Posté le: 07/04/10 12:51 Sujet du message: Optimisation: Motherships
J'ouvre un nouveau sujet, pour conserver sur l'ancien sujet les vieux déclencheurs.
Après pas mal de temps, j'ai enfin une version qui utilise AutoIndex (plus rapide que Table) et qui se sert de hashtables/textmacros pour les variables des Motherships (plus rapide que les boucles).
A cause de l'impossibilité de coder avec des variables array dans une struct Autoindex, c'est assez volumineux, et j'avais la flemme de relier chaque Module d'un Mothership à celui-ci avec une struct/Mothership, j'ai trouvé ça plus simple de faire une struct par Mothership qui regroupe tous les modules.
Pour rappel, le but est de lier une unité principale (le corps) à des modules (d'autres unités) qui fonctionnent comme des tourelles.
Avec pas mal de sous-systèmes: upgrade du corps principal, upgrade des tourelles.
D'ailleurs on achète pas une tourelle en premier, on achète une "base" de tourelle, qui elle, peut être améliorée.
Là, en dehors de la nécessité des timers gourmands vu que 0.05 secondes de délai (et encore, un seul par joueur), je crois que j'ai fait le maximum de speedfreak dont j'étais capable.
Of course, si tu vois des énormités, fais-toi plaisir.
private struct s_MsSys
player owner = null
unit ms = null
integer msId = 0
integer ownerId = 0
timer ti = null
integer countmod = 0
unit mod1 = null
unit mod2 = null
unit mod3 = null
unit mod4 = null
unit mod5 = null
unit mod6 = null
real a1 = 0.
real a2 = 0.
real a3 = 0.
real a4 = 0.
real a5 = 0.
real a6 = 0.
real d1 = 0.
real d2 = 0.
real d3 = 0.
real d4 = 0.
real d5 = 0.
real d6 = 0.
private static method createFilter takes unit u returns boolean
return IsUnitType(u,UNIT_TYPE_HERO) and GetUnitAbilityLevel(u,ISMSMOD)<=0 and GetUnitTypeId(u)!=MST0 and GetUnitTypeId(u)!=DUMMYPICK
endmethod
private method onCreate takes nothing returns nothing
set .ms = me
set .owner = GetOwningPlayer(.ms)
set .ownerId = GetPlayerId(.owner)
set MotherShip[.ownerId] = me
set .msId = GetUnitTypeId(.ms)
set .ti = null
set .countmod = 0
set .a1 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_ANGLE1)
set .a2 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_ANGLE2)
set .a3 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_ANGLE3)
set .a4 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_ANGLE4)
set .a5 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_ANGLE5)
set .a6 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_ANGLE6)
set .d1 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_DISTANCE1)
set .d2 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_DISTANCE2)
set .d3 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_DISTANCE3)
set .d4 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_DISTANCE4)
set .d5 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_DISTANCE5)
set .d6 = LoadInteger(HashT,GetUnitTypeId(.ms),INDEX_DISTANCE6)
set .mod1 = null
set .mod2 = null
set .mod3 = null
set .mod4 = null
set .mod5 = null
set .mod6 = null
endmethod
implement AutoCreate
private method onDestroy takes nothing returns nothing
set .ms = null
set .owner = null
set .msId = 0
call ReleaseTimer(.ti)
set .ti = null
set .countmod = 0
set .mod1 = null
set .mod2 = null
set .mod3 = null
set .mod4 = null
set .mod5 = null
set .mod6 = null
endmethod
implement AutoDestroy
endstruct
private function CancelMod takes unit mod returns nothing
local s_MsSys dat = s_MsSys[MotherShip[GetPlayerId(GetOwningPlayer(mod))]]
call UnitRemoveAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(mod),INDEX_SKILL))
call RemoveUnit(mod)
set dat.countmod = dat.countmod - 1
endfunction
private function UpdateModulePosition takes nothing returns nothing
local timer t = GetExpiredTimer()
local s_MsSys dat = GetTimerData(t)
local real x1 = GetUnitX(dat.ms)
local real y1 = GetUnitY(dat.ms)
local real facing = GetUnitFacing(dat.ms)
if not (IsUnitType(dat.mod1,UNIT_TYPE_DEAD)) then
call SetUnitX(dat.mod1,x1+dat.d1*Cos((facing + dat.a1)*bj_DEGTORAD) )
call SetUnitY(dat.mod1,y1+dat.d1*Sin((facing + dat.a1)*bj_DEGTORAD) )
if IsUnitType(dat.mod1,UNIT_TYPE_TAUREN) then
call SetUnitFacing(dat.mod1,facing)
endif
else
if dat.mod1 != null then
call CancelMod(dat.mod1)
set dat.mod1 = null
endif
endif
if not (IsUnitType(dat.mod2,UNIT_TYPE_DEAD)) then
call SetUnitX(dat.mod2,x1+dat.d2*Cos((facing + dat.a2)*bj_DEGTORAD) )
call SetUnitY(dat.mod2,y1+dat.d2*Sin((facing + dat.a2)*bj_DEGTORAD) )
if IsUnitType(dat.mod2,UNIT_TYPE_TAUREN) then
call SetUnitFacing(dat.mod2,facing)
endif
else
if dat.mod2 != null then
call CancelMod(dat.mod2)
set dat.mod2 = null
endif
endif
if not (IsUnitType(dat.mod3,UNIT_TYPE_DEAD)) then
call SetUnitX(dat.mod3,x1+dat.d3*Cos((facing + dat.a3)*bj_DEGTORAD) )
call SetUnitY(dat.mod3,y1+dat.d3*Sin((facing + dat.a3)*bj_DEGTORAD) )
if IsUnitType(dat.mod3,UNIT_TYPE_TAUREN) then
call SetUnitFacing(dat.mod3,facing)
endif
else
if dat.mod3 != null then
call CancelMod(dat.mod3)
set dat.mod3 = null
endif
endif
if not (IsUnitType(dat.mod5,UNIT_TYPE_DEAD)) then
call SetUnitX(dat.mod4,x1+dat.d4*Cos((facing + dat.a4)*bj_DEGTORAD) )
call SetUnitY(dat.mod4,y1+dat.d4*Sin((facing + dat.a4)*bj_DEGTORAD) )
if IsUnitType(dat.mod4,UNIT_TYPE_TAUREN) then
call SetUnitFacing(dat.mod4,facing)
endif
else
if dat.mod4 != null then
call CancelMod(dat.mod4)
set dat.mod4 = null
endif
endif
if not (IsUnitType(dat.mod5,UNIT_TYPE_DEAD)) then
call SetUnitX(dat.mod5,x1+dat.d5*Cos((facing + dat.a5)*bj_DEGTORAD) )
call SetUnitY(dat.mod5,y1+dat.d5*Sin((facing + dat.a5)*bj_DEGTORAD) )
if IsUnitType(dat.mod5,UNIT_TYPE_TAUREN) then
call SetUnitFacing(dat.mod5,facing)
endif
else
if dat.mod5 != null then
call CancelMod(dat.mod5)
set dat.mod5 = null
endif
endif
if not (IsUnitType(dat.mod6,UNIT_TYPE_DEAD)) then
call SetUnitX(dat.mod6,x1+dat.d6*Cos((facing + dat.a6)*bj_DEGTORAD) )
call SetUnitY(dat.mod6,y1+dat.d6*Sin((facing + dat.a6)*bj_DEGTORAD) )
if IsUnitType(dat.mod6,UNIT_TYPE_TAUREN) then
call SetUnitFacing(dat.mod6,facing)
endif
else
if dat.mod6 != null then
call CancelMod(dat.mod6)
set dat.mod6 = null
endif
endif
endfunction
private function LinkMod takes unit mod returns nothing
local s_MsSys dat = s_MsSys[MotherShip[GetPlayerId(GetOwningPlayer(mod))]]
if dat.mod1 == null then
set dat.mod1 = mod
set dat.countmod = dat.countmod + 1
return
elseif dat.mod2 == null then
set dat.mod2 = mod
set dat.countmod = dat.countmod + 1
return
elseif dat.mod3 == null then
set dat.mod3 = mod
set dat.countmod = dat.countmod + 1
return
elseif dat.mod4 == null then
set dat.mod4 = mod
set dat.countmod = dat.countmod + 1
return
elseif dat.mod5 == null then
set dat.mod5 = mod
set dat.countmod = dat.countmod + 1
return
elseif dat.mod6 == null then
set dat.mod6 = mod
set dat.countmod = dat.countmod + 1
return
endif
endfunction
private function CountCargoMod takes unit ms returns integer
local integer value = 0
local s_MsSys dat = s_MsSys[ms]
if not (IsUnitType(dat.mod1, UNIT_TYPE_DEAD)) then
if GetUnitTypeId(dat.mod1) == CARGO1 then
set value = value + 1
elseif GetUnitTypeId(dat.mod1) == CARGO2 then
set value = value + 2
elseif GetUnitTypeId(dat.mod1) == CARGO3 then
set value = value + 3
endif
endif
if not (IsUnitType(dat.mod2, UNIT_TYPE_DEAD)) then
if GetUnitTypeId(dat.mod2) == CARGO1 then
set value = value + 1
elseif GetUnitTypeId(dat.mod2) == CARGO2 then
set value = value + 2
elseif GetUnitTypeId(dat.mod2) == CARGO3 then
set value = value + 3
endif
endif
if not (IsUnitType(dat.mod3, UNIT_TYPE_DEAD)) then
if GetUnitTypeId(dat.mod3) == CARGO1 then
set value = value + 1
elseif GetUnitTypeId(dat.mod3) == CARGO2 then
set value = value + 2
elseif GetUnitTypeId(dat.mod3) == CARGO3 then
set value = value + 3
endif
endif
if not (IsUnitType(dat.mod4, UNIT_TYPE_DEAD)) then
if GetUnitTypeId(dat.mod4) == CARGO1 then
set value = value + 1
elseif GetUnitTypeId(dat.mod4) == CARGO2 then
set value = value + 2
elseif GetUnitTypeId(dat.mod4) == CARGO3 then
set value = value + 3
endif
endif
if not (IsUnitType(dat.mod5, UNIT_TYPE_DEAD)) then
if GetUnitTypeId(dat.mod5) == CARGO1 then
set value = value + 1
elseif GetUnitTypeId(dat.mod5) == CARGO2 then
set value = value + 2
elseif GetUnitTypeId(dat.mod5) == CARGO3 then
set value = value + 3
endif
endif
if not (IsUnitType(dat.mod6, UNIT_TYPE_DEAD)) then
if GetUnitTypeId(dat.mod6) == CARGO1 then
set value = value + 1
elseif GetUnitTypeId(dat.mod6) == CARGO2 then
set value = value + 2
elseif GetUnitTypeId(dat.mod6) == CARGO3 then
set value = value + 3
endif
endif
return value
endfunction
private function ChangeMod takes unit modbase, unit modnew returns nothing
local s_MsSys dat = s_MsSys[MotherShip[GetPlayerId(GetOwningPlayer(modnew))]]
if dat.mod1 == modbase then
set dat.mod1 = modnew
elseif dat.mod2 == modbase then
set dat.mod2 = modnew
elseif dat.mod3 == modbase then
set dat.mod3 = modnew
elseif dat.mod4 == modbase then
set dat.mod4 = modnew
elseif dat.mod5 == modbase then
set dat.mod5 = modnew
elseif dat.mod6 == modbase then
set dat.mod6 = modnew
endif
call RemoveUnit(modbase)
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(modnew),INDEX_SKILL))
call SetUnitFlyHeight(modnew,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
call SetUnitPathing(modnew,false)
endfunction
private function InitializeTimer takes unit ms returns nothing
local s_MsSys dat = s_MsSys[ms]
if dat.ti == null then
set dat.ti = NewTimer()
call SetTimerData( dat.ti, dat )
call TimerStart( dat.ti, TIMEOUT, true, function UpdateModulePosition )
endif
endfunction
private function TransferMods takes unit ms returns nothing
local s_MsSys dat = s_MsSys[ms]
local unit tmpMod = null
if TmpMod1[dat.ownerId]!= 0 then
set tmpMod = CreateUnit(dat.owner,TmpMod1[dat.ownerId],GetUnitX(dat.ms),GetUnitY(dat.ms),0.)
set dat.mod1 = tmpMod
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(tmpMod),INDEX_SKILL))
call SetUnitFlyHeight(tmpMod,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
call SetUnitPathing(tmpMod,false)
set dat.countmod = dat.countmod + 1
endif
if TmpMod2[dat.ownerId]!= 0 then
set tmpMod = CreateUnit(dat.owner,TmpMod2[dat.ownerId],GetUnitX(dat.ms),GetUnitY(dat.ms),0.)
set dat.mod2 = tmpMod
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(tmpMod),INDEX_SKILL))
call SetUnitFlyHeight(tmpMod,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
call SetUnitPathing(tmpMod,false)
set dat.countmod = dat.countmod + 1
endif
if TmpMod3[dat.ownerId]!= 0 then
set tmpMod = CreateUnit(dat.owner,TmpMod3[dat.ownerId],GetUnitX(dat.ms),GetUnitY(dat.ms),0.)
set dat.mod3 = tmpMod
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(tmpMod),INDEX_SKILL))
call SetUnitFlyHeight(tmpMod,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
call SetUnitPathing(tmpMod,false)
set dat.countmod = dat.countmod + 1
endif
if TmpMod4[dat.ownerId]!= 0 then
set tmpMod = CreateUnit(dat.owner,TmpMod4[dat.ownerId],GetUnitX(dat.ms),GetUnitY(dat.ms),0.)
set dat.mod4 = tmpMod
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(tmpMod),INDEX_SKILL))
call SetUnitFlyHeight(tmpMod,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
call SetUnitPathing(tmpMod,false)
set dat.countmod = dat.countmod + 1
endif
if TmpMod5[dat.ownerId]!= 0 then
set tmpMod = CreateUnit(dat.owner,TmpMod5[dat.ownerId],GetUnitX(dat.ms),GetUnitY(dat.ms),0.)
set dat.mod5 = tmpMod
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(tmpMod),INDEX_SKILL))
call SetUnitFlyHeight(tmpMod,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
call SetUnitPathing(tmpMod,false)
set dat.countmod = dat.countmod + 1
endif
if TmpMod6[dat.ownerId]!= 0 then
set tmpMod = CreateUnit(dat.owner,TmpMod6[dat.ownerId],GetUnitX(dat.ms),GetUnitY(dat.ms),0.)
set dat.mod6 = tmpMod
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(tmpMod),INDEX_SKILL))
call SetUnitFlyHeight(tmpMod,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
call SetUnitPathing(tmpMod,false)
set dat.countmod = dat.countmod + 1
endif
endfunction
private function Upgrade takes unit ms returns nothing
local s_MsSys dat = s_MsSys[ms]
local real x = GetUnitX(dat.ms)
local real y = GetUnitY(dat.ms)
local real a = GetUnitFacing(dat.ms)
local integer j = 0
local unit tmpMs = null
if not (IsUnitType(dat.mod1,UNIT_TYPE_DEAD)) then
set TmpMod1[dat.ownerId] = GetUnitTypeId(dat.mod1)
else
set TmpMod1[dat.ownerId] = 0
endif
if not (IsUnitType(dat.mod2,UNIT_TYPE_DEAD)) then
set TmpMod2[dat.ownerId] = GetUnitTypeId(dat.mod2)
else
set TmpMod2[dat.ownerId] = 0
endif
if not (IsUnitType(dat.mod3,UNIT_TYPE_DEAD)) then
set TmpMod3[dat.ownerId] = GetUnitTypeId(dat.mod3)
else
set TmpMod3[dat.ownerId] = 0
endif
if not (IsUnitType(dat.mod4,UNIT_TYPE_DEAD)) then
set TmpMod4[dat.ownerId] = GetUnitTypeId(dat.mod4)
else
set TmpMod4[dat.ownerId] = 0
endif
if not (IsUnitType(dat.mod5,UNIT_TYPE_DEAD)) then
set TmpMod5[dat.ownerId] = GetUnitTypeId(dat.mod5)
else
set TmpMod5[dat.ownerId] = 0
endif
if not (IsUnitType(dat.mod6,UNIT_TYPE_DEAD)) then
set TmpMod6[dat.ownerId] = GetUnitTypeId(dat.mod6)
else
set TmpMod6[dat.ownerId] = 0
endif
call RemoveUnit(dat.mod1)
call RemoveUnit(dat.mod2)
call RemoveUnit(dat.mod3)
call RemoveUnit(dat.mod4)
call RemoveUnit(dat.mod5)
call RemoveUnit(dat.mod6)
set dat.mod1 = null
set dat.mod2 = null
set dat.mod3 = null
set dat.mod4 = null
set dat.mod5 = null
set dat.mod6 = null
set tmpMs = CreateUnit(dat.owner,LoadInteger(HashT,dat.msId,INDEX_UPGRADE),x,y,a)
call RemoveUnit(dat.ms)
call TransferMods(tmpMs)
call InitializeTimer(tmpMs)
set tmpMs = null
endfunction
private function AddModule takes nothing returns boolean
local unit dockOrBaseMod = GetTriggerUnit()
local unit mod = GetTrainedUnit()
local s_MsSys dat = s_MsSys[MotherShip[GetPlayerId(GetOwningPlayer(mod))]]
local real x1 = GetUnitX(dat.ms)
local real y1 = GetUnitY(dat.ms)
local real x2 = GetUnitX(dockOrBaseMod)
local real y2 = GetUnitY(dockOrBaseMod)
local real distance = SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
if GetUnitTypeId(mod)==MST0 then
if LoadInteger(HashT,dat.msId,INDEX_CLASS) == 1 then //Shuttle
if dat.countmod < MAXMODSHUT and distance<= RANGE then
private function DisablePirMods takes player whichPlayer returns nothing
//Afterburner mk2
call SetPlayerTechMaxAllowed(whichPlayer,'E005',0)
//boarder
call SetPlayerTechMaxAllowed(whichPlayer,'E007',0)
//hyperforcer
call SetPlayerTechMaxAllowed(whichPlayer,'E013',0)
//Secondary motor Mark 3
call SetPlayerTechMaxAllowed(whichPlayer,'E030',0)
endfunction
private function DisablePolMods takes player whichPlayer returns nothing
//Builder
call SetPlayerTechMaxAllowed(whichPlayer,'E009',0)
//Reparator
call SetPlayerTechMaxAllowed(whichPlayer,'E027',0)
endfunction
private function IniMs takes player whichPlayer,unit mothership returns nothing
local integer whichPlayerId = GetPlayerId(whichPlayer)
local real x = GetUnitX(mothership)
local real y = GetUnitY(mothership)
local unit dummy = null
call SetPlayerTechResearched(whichPlayer, HasShut, 1 )
//Give it the instant colo ability
call UnitAddAbility(mothership,'A007')
//Create the dummy with start buffs
set dummy= CreateUnit(whichPlayer,'o00L',x,y,0.)
call UnitApplyTimedLife(dummy,'BTLF',5.)
call IssueTargetOrder(dummy,"innerfire", mothership)
call IssueTargetOrder(dummy,"bloodlust", mothership)
call IssueImmediateOrder(mothership,"divineshield")
//Selet the MS
if whichPlayer == GetLocalPlayer() then
call ClearSelection()
call SelectUnit(mothership,true)
endif
//Initialize the Ms system
call InitializeTimer(mothership)
call RemoveUnit(FirstShip[whichPlayerId])
set dummy = null
endfunction
private function MsMer takes nothing returns nothing
//This trigger should work only for shuttle motherships
local unit mothership = SpellEvent.CastingUnit
local player owner = GetOwningPlayer(mothership) //The first ship
local real x = GetUnitX(mothership)
local real y = GetUnitY(mothership)
set mothership = CreateUnit(owner,'H02E',x,y,0.)
call DisableMilMods(owner)
call DisablePirMods(owner)
call DisablePolMods(owner)
call IniMs(owner,mothership)
set mothership = null
set owner = null
endfunction
private function MsMil takes nothing returns nothing
//This trigger should work only for shuttle motherships
local unit mothership = SpellEvent.CastingUnit
local player owner = GetOwningPlayer(mothership) //The first ship
local real x = GetUnitX(mothership)
local real y = GetUnitY(mothership)
set mothership = CreateUnit(owner,'H02D',x,y,0.)
call DisableMerMods(owner)
call DisablePirMods(owner)
call DisablePolMods(owner)
call IniMs(owner,mothership)
set mothership = null
set owner = null
endfunction
private function MsPir takes nothing returns nothing
//This trigger should work only for shuttle motherships
local unit mothership = SpellEvent.CastingUnit
local player owner = GetOwningPlayer(mothership) //The first ship
local real x = GetUnitX(mothership)
local real y = GetUnitY(mothership)
set mothership = CreateUnit(owner,'H02F',x,y,0.)
call DisableMerMods(owner)
call DisableMilMods(owner)
call DisablePolMods(owner)
call IniMs(owner,mothership)
set mothership = null
set owner = null
endfunction
private function MsPol takes nothing returns nothing
//This trigger should work only for shuttle motherships
local unit mothership = SpellEvent.CastingUnit
local player owner = GetOwningPlayer(mothership) //The first ship
local real x = GetUnitX(mothership)
local real y = GetUnitY(mothership)
set mothership = CreateUnit(owner,'H02C',x,y,0.)
call DisableMerMods(owner)
call DisableMilMods(owner)
call DisablePirMods(owner)
call IniMs(owner,mothership)
set mothership = null
set owner = null
endfunction
private function UpgradeMainBody takes nothing returns boolean
local player owner = GetOwningPlayer(GetTriggerUnit())
Inscrit le: 23 Aoû 2007 Messages: 7143 Sujets: 147 Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance Médailles: 2 (En savoir plus...)
Posté le: 22/04/10 18:15 Sujet du message:
Y'a des trucs qui me choquent.
1)
Jass:
if not (IsUnitType(dat.mod1,UNIT_TYPE_DEAD)) then
Te rends tu compte que cela sera égal à true quand dat.mod1 est une unité invalide ou égal à null ?
Jamais testé mais la fonction IsUnit devrait détecter si l'unité existe (encore).
Si cela ne fonctionne pas tu peux utiliser GetUnitTypeId(<unit>) != 0
2)
Remove une unité non existante n'est pas vraiment une pratique à conseiller, même si ca devrait être safe, tu pourrais inclure le remove dans le if.
3)
Encore une fois il n'est pas nécessaire de nullifier une variable player, tu ne créés pas, ni détruit de joueur en cours de jeu (même si tu peux l'own).
Tu tentes d'ajouter un entier à l'unité et non une compétence valide.
Ce qui me laisse à penser que tu utilises cette compétence comme un moyen de lier un booléen/entier à une unité, si c'est le cas honte sur toi !
Mais je peux être dans le faux je n'ai pas parcouru entièrement le code.
5)
La flemme de continuer, recheck ton code plus attentivement d'abord _________________
Inscrit le: 23 Aoû 2007 Messages: 7143 Sujets: 147 Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance Médailles: 2 (En savoir plus...)
Posté le: 22/04/10 18:42 Sujet du message:
Mais c'est impossible que cela fonctionne INDEX_SKILL est un entier assez bas, impossible qu'il soit un id de compétence valide, tu as du rajouter la compétence dans l'éditeur d'objet.
Ou alors tu as déclaré 2 fois INDEX_SKILL, et pour une obscure raison JassHelper ne t'a pas vomit d'erreur.
"player" est certes un handle mais cela ne veut pas dire pour autant que l'on puisse créer/détruire ce type.
Tout comme les type race,alliancetype, etc ...
Or il est nécessaire de nullifier une variable handle uniquement si cet handle est susceptible d'être détruit ultérieurement, pour que son id puisse être recyclé (GetHandleId).
Car tant qu'une variable pointe sur un handle, son id n'est pas recyclé même si cet handle est détruit.
Après il y a aussi un leak très mineur quand on ne nullifie pas immédiatement une variable qui pointe sur un handle après destruction de celui ci, mais c'est vraiment négligeable.
http://www.thehelper.net/forums/showthread.php?t=136608
Même pour le type unit, si par ex une unité n'est jamais remove, nullifier une variable locale pointant sur elle est superflu. (je dis cela juste pour clarifier) _________________
1-Je ne vois pas en quoi c'est gênant: je n'ai pas de raison d'avoir une unité invalide. Si la variable renvoie sur une valeur nulle, ça ne créé pas de problème non plus. Mais je peux effectivement rajouter un and dat.mod1 != null comme condition.
2-C'est safe, sauf pour Autoindex qui apprécie rarement (tests empiriques à l'appui sur d'autres systèmes, j'ai des messages d'erreur type "autoindex error: unit truc muche is a filtered unit" parfois).
Mais comme les modules sont des unités de type "héros", je suis obligé de le supprimer à la main du jeu.
3-Donc set maVariablePlayer = null est complètement inutile. Dingue ça!
4-Je peux t'envoyer la map pour les tests, je t'assure que ça fonctionne au poil. Et non, tout est ici, pas d'autre Index Skill ailleurs.
5-En fait, tout fonctionne. Je crois que la map commence à être vraiment "normale". (Cad pas de surconsommation du moteur du jeu).
Mais tant qu'à faire, autant la rendre parfaite :p. _________________
Inscrit le: 23 Aoû 2007 Messages: 7143 Sujets: 147 Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance Médailles: 2 (En savoir plus...)
Posté le: 23/04/10 17:24 Sujet du message:
Apocalypse a écrit:
1-Je ne vois pas en quoi c'est gênant: je n'ai pas de raison d'avoir une unité invalide. Si la variable renvoie sur une valeur nulle, ça ne créé pas de problème non plus. Mais je peux effectivement rajouter un and dat.mod1 != null comme condition.
Tu n'as en effet pas de raison d'avoir une unité invalide car tu utilises AutoDestroy, par contre tu peux avoir une unité null, et faire des opérations sur une unité null c'est conceptuellement crade (même si ca doit être safe).
Citation:
2-C'est safe, sauf pour Autoindex qui apprécie rarement (tests empiriques à l'appui sur d'autres systèmes, j'ai des messages d'erreur type "autoindex error: unit truc muche is a filtered unit" parfois).
Mais comme les modules sont des unités de type "héros", je suis obligé de le supprimer à la main du jeu.
La flemme de regarder mais ca doit venir du hook de RemoveUnit d'AutoIndex, car si je me rappelle bien il se contente de vérifier si l'unité est différente de "null", ce qui ne suffit pas pour les ghost units (unité remove du jeu mais variable pointant sur elle non nullifiée)
Citation:
3-Donc set maVariablePlayer = null est complètement inutile. Dingue ça!
Ouai, dingue !
Citation:
4-Je peux t'envoyer la map pour les tests, je t'assure que ça fonctionne au poil. Et non, tout est ici, pas d'autre Index Skill ailleurs.
C'est impossible, tu ne sembles pas comprendre ce qu'est une KEY, c'est une constant integer dont tu ne définis pas la valeur, JassHelper attribue pour chaque key une valeur entière unique, mais en aucun cas tu ne la choisis.
Peut être que tu ne triggerises pas cette compétence, ou qu'elle n'est pas visible, ou quoi que ce soit d'autre.
Mais ce qui est sûr c'est que tu ne comprends pas l'utilisation d'une KEY. _________________
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