Posté le: 22/01/10 12:14 Sujet du message: Optimisation: Income
Un système qui offre des ressources aux joueurs autres qu'Alien toutes les 60 secondes.
Parmi les bonus, certaines planètes apportent des gains d'or et de bois. Avant, je fais un GroupEnum pour repérer toutes les planètes de ce type à chaque calcul d'income, et pour chaque joueur, ce qui était assez mauvais niveau performances.
Cette version là se fonde sur une boucle qui checke l'appartenance de toutes les planètes apportées par bonus avec une boucle: en effet, au début de jeu, j'attribue ces planètes à une variable de déploiement.
y'a-t-il une meilleur façon de procéder pour éviter de recompter les planètes à chaque fois?
Ancienne version supprimée pour alléger la page
La détection de ces planètes a lieu dans un trigger appelé System Creator. C'est tout simple, au moment de la création des planètes, je les stocke ou non dans une variable:
Secret:
Jass:
set planet = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),SsPlaneteId[GetRandomInt(0,7)],x2,y2,0.)
//Implement the planet if it has a bonus for the income trigger
if GetUnitAbilityLevel(planet,PLANETINCOMEBONUS_PULSAR)>= 1 then
set PlanetWithBonusPulsar[PlanetWithBonusPulsarMax]=planet
set PlanetWithBonusPulsarMax = PlanetWithBonusPulsarMax +1
elseif GetUnitAbilityLevel(planet,PLANETINCOMEBONUS_IRON)>= 1 then
set PlanetWithBonusIron[PlanetWithBonusIronMax]=planet
set PlanetWithBonusIronMax = PlanetWithBonusIronMax +1
endif
_________________
Dernière édition par jk2pach le 10/08/10 09:04; édité 2 fois
Rappel: la détection des planètes possédant un éventuel bonus provient d'une library, SystemCreator, avec une simple détection des capacités.
Secret:
Jass:
set planet = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),SsPlaneteId[GetRandomInt(0,7)],x2,y2,0.)
//Implement the planet if it has a bonus for the income trigger
if GetUnitAbilityLevel(planet,PLANETINCOMEBONUS_PULSAR)>= 1 then
set PlanetWithBonusPulsar[PlanetWithBonusPulsarMax]=planet
set PlanetWithBonusPulsarMax = PlanetWithBonusPulsarMax +1
elseif GetUnitAbilityLevel(planet,PLANETINCOMEBONUS_IRON)>= 1 then
set PlanetWithBonusIron[PlanetWithBonusIronMax]=planet
set PlanetWithBonusIronMax = PlanetWithBonusIronMax +1
endif
Voici le système d'income périodique à proprement parler.
private function UpdateIncome takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer i = 0
local integer j = 0
call RunSound(SOUND_HINT)
loop
exitwhen i > MAXPLAYER
//Only check playing players
if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and Alien[i]==false then
//Initialize variables
set Gold = 0
set Lumber = 0
set Bonus1 = 0
set Bonus2 = 0
set Bonus3 = 0
set Bonus4 = 0
//Check Planet with Pulsar bonus
set j = 0
loop
exitwhen j > PlanetWithBonusPulsarMax
if GetOwningPlayer(PlanetWithBonusPulsar[j])==Player(i) and GetUnitState(PlanetWithBonusPulsar[j],UNIT_STATE_LIFE)>0 and PlanetWithBonusPulsar[j]!= null then
set Bonus1 = Bonus1 + 100*GetUnitAbilityLevel(PlanetWithBonusPulsar[j],PLANETINCOMEBONUS_PULSAR)
endif
set j = j + 1
endloop
//Check Planet with Iron bonus
set j = 0
loop
exitwhen j > PlanetWithBonusIronMax
if GetOwningPlayer(PlanetWithBonusIron[j])==Player(i) and GetUnitState(PlanetWithBonusIron[j],UNIT_STATE_LIFE)>0 and PlanetWithBonusIron[j]!= null then
set Bonus2 = Bonus2 + 100*GetUnitAbilityLevel(PlanetWithBonusIron[j],PLANETINCOMEBONUS_IRON)
endif
set j = j + 1
endloop
//Check Freeport bonus
//Check only if the player freeport is alive AND if he has the alliance income bonus
if GetUnitAbilityLevel(Freeport[i],'A01Y')>= 1 and Freeport[i]!= null and GetUnitState(Freeport[i],UNIT_STATE_LIFE)>0 then
set j = 0
loop
exitwhen j > MAXPLAYER
//Then check for all players if the player is allied to other and if they have a freeport
if IsPlayerAlly(Player(i),Player(j))==true and Freeport[j]!= null and GetUnitState(Freeport[j],UNIT_STATE_LIFE)>0 then
set Bonus3 = Bonus3+100
set Bonus4 = Bonus4+50
endif
set j = j + 1
endloop
endif
set Gold = 50 + GetPlayerTechCount(Player(i),'R00H',true)*25+GetPlayerState(Player(i), PLAYER_STATE_FOOD_CAP_CEILING)+Bonus1+Bonus3
set Lumber = 10 + GetPlayerTechCount(Player(i),'R00I',true)*10+R2I(0.25*GetPlayerState(Player(i), PLAYER_STATE_FOOD_CAP_CEILING)) +Bonus2+Bonus4
if Merchant[GetPlayerId(Player(i))]== true then
set Gold = R2I(1.25*Gold)
set Lumber = R2I(1.25*Lumber)
endif
if Terrorist[GetPlayerId(Player(i))]== true then
set Gold = R2I(4.00*Gold)
set Lumber = R2I(10.00*Lumber)
endif
Page 1 sur 1 La question posée dans ce topic a été résolue !
Vous ne pouvez pas poster de nouveaux sujets dans ce forum Vous ne pouvez pas répondre aux sujets dans ce forum Vous ne pouvez pas éditer vos messages dans ce forum Vous ne pouvez pas supprimer vos messages dans ce forum Vous ne pouvez pas voter dans les sondages de ce forum