Worldedit
  Worldedit
Le site sur l'éditeur de warcraft 3 !
 
  FAQFAQ   RechercherRechercher   Liste des MembresListe des Membres    Groupes d'utilisateursGroupes d'utilisateurs   medals.php?sid=63359adeed5b8f68a0fbe076ea67bf62Médailles   S'enregistrerS'enregistrer 
 ProfilProfil   Se connecter pour vérifier ses messages privésSe connecter pour vérifier ses messages privés   ConnexionConnexion 
  FAQFAQ World Editor   UploadUploader une map ou une image    UploadAjouter sa map à l'annuaire   UploadConsulter l'annuaire

Optimisation: Motherships

 
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
 jk2pach
Invité








MessagePosté le: 07/04/10 12:51    Sujet du message: Optimisation: Motherships Citer

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.

Nécessite:

AbilityPreload
TextDisplay
SpellEvent
TimerUtils
AutoIndex
Secret:

Jass:
library MsSys initializer init requires TimerUtils,AutoIndex, BoundSentinel, AbilityPreload,SpellEvent,TextDisplay

globals
    private constant real TIMEOUT = 0.05
    private constant integer CARGO1 = 'E010'
    private constant integer CARGO2 = 'E011'
    private constant integer CARGO3 = 'E012'
    private constant integer MST0 = 'H02G'
    private constant string C1 = "You already have the maximum number of modules allowed with this ship."
    private constant string C2 = "Distance between the dock and the Mothership must be less than "     
    private constant string C3 = " to get the new module. Current Range: "
    private constant string C4 = "Modules slot left for your Mothership: "
    private constant real RANGE = 300.00
    private constant integer MAXMODSHUT = 2
    private constant integer MAXMODFRIG = 4
    private constant integer MAXMODCRUIZ = 6
    unit array MotherShip [12]
    integer array TmpMod1 [12]
    integer array TmpMod2 [12]
    integer array TmpMod3 [12]
    integer array TmpMod4 [12]
    integer array TmpMod5 [12]
    integer array TmpMod6 [12]
    private constant integer UpToFrig ='R00Z'
    private constant integer UpToCruiz ='R010'
    private constant integer HasShut = 'R00W'
    private constant integer HasFrig = 'R00X'
    private constant integer HasCruiz ='R00Y'
    private constant integer ISMSMOD = 'A03X'
    private key INDEX_ANGLE1
    private key INDEX_ANGLE2
    private key INDEX_ANGLE3
    private key INDEX_ANGLE4
    private key INDEX_ANGLE5
    private key INDEX_ANGLE6
    private key INDEX_HEIGH
    private key INDEX_UPGRADE
    private key INDEX_DISTANCE1
    private key INDEX_DISTANCE2
    private key INDEX_DISTANCE3
    private key INDEX_DISTANCE4
    private key INDEX_DISTANCE5
    private key INDEX_DISTANCE6
    private key INDEX_SKILL
    private key INDEX_CLASS //1=shut, 2=frig, 3==Cruis
    private hashtable HashT
endglobals
   
    //! textmacro t__ModulePosition_Init takes MS ,CLASS, UPGRADE ,HEIGHT , A1, A2, A3, A4, A5, A6, D1, D2, D3, D4, D5, D6
        call SaveInteger(HashT,$MS$,INDEX_CLASS,$CLASS$)
        call SaveInteger(HashT,$MS$,INDEX_UPGRADE,$UPGRADE$)
        call SaveInteger(HashT,$MS$,INDEX_HEIGH,$HEIGHT$)
        call SaveInteger(HashT,$MS$,INDEX_ANGLE1,$A1$)
        call SaveInteger(HashT,$MS$,INDEX_ANGLE2,$A2$)
        call SaveInteger(HashT,$MS$,INDEX_ANGLE3,$A3$)
        call SaveInteger(HashT,$MS$,INDEX_ANGLE4,$A4$)
        call SaveInteger(HashT,$MS$,INDEX_ANGLE5,$A5$)
        call SaveInteger(HashT,$MS$,INDEX_ANGLE6,$A6$)
        call SaveInteger(HashT,$MS$,INDEX_DISTANCE1,$D1$)
        call SaveInteger(HashT,$MS$,INDEX_DISTANCE2,$D2$)
        call SaveInteger(HashT,$MS$,INDEX_DISTANCE3,$D3$)
        call SaveInteger(HashT,$MS$,INDEX_DISTANCE4,$D4$)
        call SaveInteger(HashT,$MS$,INDEX_DISTANCE5,$D5$)
        call SaveInteger(HashT,$MS$,INDEX_DISTANCE6,$D6$)
    //! endtextmacro
   
    //! textmacro t__ModuleSkill_Init takes MOD ,SKILL
        call SaveInteger(HashT,$MOD$,INDEX_SKILL,$SKILL$)
        call AbilityPreload($SKILL$)
    //! endtextmacro
   

    private function SetVariables takes nothing returns nothing
        local integer i = 0
            //! runtextmacro t__ModulePosition_Init("'H02E'","1","'H02H'","5","0","0","0","0","0","0","-10","0","0","0","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02D'","1","'H02N'","5","0","0","0","0","0","0","-10","10","0","0","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02F'","1","'H02O'","6","0","0","0","0","0","0","15","0","0","0","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02C'","1","'H02K'","5","90","0","0","0","0","0","10","10","0","0","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02H'","2","'H02M'","10","180","180","180","0","0","0","10","0","20","10","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02N'","2","'H02L'","20","0","180","180","0","0","0","0","13","25","13","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02O'","2","'H02I'","5","180","180","180","180","0","0","0","13","25","38","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02K'","2","'H02J'","10","0","45","-45","-315","0","0","0","13","13","13","0","0")
            //! runtextmacro t__ModulePosition_Init("'H02M'","3","'XXXX'","15","0","0","0","0","0","0","0","10","15","20","25","30")
            //! runtextmacro t__ModulePosition_Init("'H02L'","3","'XXXX'","30","0","180","45","-45","225","-225","0","10","25","25","25","25")
            //! runtextmacro t__ModulePosition_Init("'H02I'","3","'XXXX'","20","0","180","45","-45","315","-315","25","25","25","25","25","25")
            //! runtextmacro t__ModulePosition_Init("'H02J'","3","'XXXX'","25","0","0","45","-45","90","-90","0","13","18","13","13","13")

            //! runtextmacro t__ModuleSkill_Init("'E004'","'A00O'")
            //! runtextmacro t__ModuleSkill_Init("'E005'","'A00P'")
            //! runtextmacro t__ModuleSkill_Init("'E013'","'A01W'")
            //! runtextmacro t__ModuleSkill_Init("'E014'","'A000'")
            //! runtextmacro t__ModuleSkill_Init("'E024'","'A033'")
            //! runtextmacro t__ModuleSkill_Init("'E028'","'A00L'")
            //! runtextmacro t__ModuleSkill_Init("'E029'","'A00N'")
            //! runtextmacro t__ModuleSkill_Init("'E030'","'A00M'")
            //! runtextmacro t__ModuleSkill_Init("'E032'","'A034'")
            //! runtextmacro t__ModuleSkill_Init("'E035'","'A035'")
    endfunction
 
    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))]]
           
            call SetUnitPathing(mod,false)
            call SetUnitFlyHeight(mod,GetUnitFlyHeight(dat.ms)+LoadInteger(HashT,GetUnitTypeId(dat.ms),INDEX_HEIGH),0.)
           
            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
                   
                        call LinkMod(mod)
                        call DisplayTextToPlayer(dat.owner,0,0,C4+I2S(MAXMODSHUT-dat.countmod))
                       
                    elseif dat.countmod >= MAXMODSHUT then
                   
                        call ErrorSound(dat.owner)
                        call DisplayTextToPlayer(dat.owner,0,0,C1)
                        call RemoveUnit(mod)
                       
                    elseif  distance > RANGE then
                   
                        call ErrorSound(dat.owner)
                        call DisplayTextToPlayer(dat.owner,0,0,C2+I2S(R2I(RANGE))+C3+I2S(R2I(distance)))
                        call RemoveUnit(mod)
                       
                    endif
                   
                elseif LoadInteger(HashT,dat.msId,INDEX_CLASS) == 2 then //Frigate
               
                    if dat.countmod < MAXMODFRIG and distance<= RANGE then
                   
                        call LinkMod(mod)
                        call DisplayTextToPlayer(dat.owner,0,0,C4+I2S(MAXMODFRIG-dat.countmod))
                       
                    elseif dat.countmod >= MAXMODFRIG then
                   
                        call ErrorSound(dat.owner)
                        call DisplayTextToPlayer(dat.owner,0,0,C1)
                        call RemoveUnit(mod)
                       
                    elseif  distance > RANGE then
                   
                        call ErrorSound(dat.owner)
                        call DisplayTextToPlayer(dat.owner,0,0,C2+I2S(R2I(RANGE))+C3+I2S(R2I(distance)))
                        call RemoveUnit(mod)
                       
                    endif
                   
                elseif LoadInteger(HashT,dat.msId,INDEX_CLASS) == 3 then //Cruiser
               
                    if dat.countmod < MAXMODCRUIZ and distance<= RANGE then
                   
                        call LinkMod(mod)
                        call DisplayTextToPlayer(dat.owner,0,0,C4+I2S(MAXMODCRUIZ-dat.countmod))
                       
                    elseif dat.countmod >= MAXMODCRUIZ then
                   
                        call ErrorSound(dat.owner)
                        call DisplayTextToPlayer(dat.owner,0,0,C1)
                        call RemoveUnit(mod)
                       
                    elseif distance > RANGE then
                   
                        call ErrorSound(dat.owner)
                        call DisplayTextToPlayer(dat.owner,0,0,C2+I2S(R2I(RANGE))+C3+I2S(R2I(distance)))
                        call RemoveUnit(mod)
                       
                    endif
                   
                elseif LoadInteger(HashT,dat.msId,INDEX_CLASS) <1 or LoadInteger(HashT,dat.msId,INDEX_CLASS) >3 then
               
                    call BJDebugMsg("Mothership bug for player "+I2S(dat.ownerId)+ " The mothership class is unknown")
                   
                endif
               
            elseif GetUnitAbilityLevel(mod,ISMSMOD)>=1 and GetUnitTypeId(mod)!=MST0 then
           
                call ChangeMod(dockOrBaseMod,mod)
               
            endif
            set dockOrBaseMod = null
            set mod = null
            return false
    endfunction

    private function DisableMerMods takes player whichPlayer returns nothing
        //Cargo Modules Mk1, 2 and 3
        call SetPlayerTechMaxAllowed(whichPlayer,'E010',0)
        call SetPlayerTechMaxAllowed(whichPlayer,'E011',0)
        call SetPlayerTechMaxAllowed(whichPlayer,'E012',0)
        //Microcities Mk1 and 2
        call SetPlayerTechMaxAllowed(whichPlayer,'E019',0)
        call SetPlayerTechMaxAllowed(whichPlayer,'E020',0)
    endfunction

    private function DisableMilMods takes player whichPlayer returns nothing
        //MicroBH
        call SetPlayerTechMaxAllowed(whichPlayer,'E006',0)
        //MicroMis Thrower Mk2
        call SetPlayerTechMaxAllowed(whichPlayer,'E022',0)
        //Tank Module
        call SetPlayerTechMaxAllowed(whichPlayer,'E033',0)
        //Torpedo Launcher
        call SetPlayerTechMaxAllowed(whichPlayer,'E034',0)
    endfunction

    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())
       
            if GetResearched() == UpToFrig then
           
                call SetPlayerTechResearched(owner, HasFrig, 1)
                call DisplayTextToPlayer(owner,0.,0.,"Mothership upgraded to frigate")
                call Upgrade(MotherShip[GetPlayerId(owner)])
                return false
               
            elseif GetResearched() == UpToCruiz then
           
                call SetPlayerTechResearched(owner, HasCruiz, 1)
                call DisplayTextToPlayer(owner,0.,0.,"Mothership upgraded to cruiser")
                call Upgrade(MotherShip[GetPlayerId(owner)])
                return false
               
            endif
           
            set owner = null
            return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t1 = CreateTrigger()
        local trigger t2 = CreateTrigger()
        local integer i = 0
            set HashT = InitHashtable()
            call SetVariables()
            call AbilityPreload(ISMSMOD)
            call RegisterSpellCastResponse(PICKMSMER,MsMer)
            call RegisterSpellCastResponse(PICKMSMIL,MsMil)
            call RegisterSpellCastResponse(PICKMSPIR,MsPir)
            call RegisterSpellCastResponse(PICKMSPOL,MsPol)
            call TriggerRegisterAnyUnitEventBJ(t1, EVENT_PLAYER_UNIT_RESEARCH_FINISH )
            call TriggerAddCondition(t1, Condition(function UpgradeMainBody))
            call TriggerRegisterAnyUnitEventBJ(t2, EVENT_PLAYER_UNIT_TRAIN_FINISH )
            call TriggerAddCondition(t2, Condition(function AddModule))
    endfunction

endlibrary


_________________


Dernière édition par jk2pach le 10/08/10 09:04; édité 1 fois
Revenir en haut
 Troll-Brain
Ri1kamoua


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...)
Rédacteur de tuto #3 (Quantité : 1) Grand mage créateur de sort (Quantité : 1)

MessagePosté le: 22/04/10 18:15    Sujet du message: Citer

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).

4)

Jass:

    private key INDEX_SKILL
call UnitAddAbility(dat.ms,LoadInteger(HashT,GetUnitTypeId(tmpMod),INDEX_SKILL))


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 Razz
_________________
Le violet, c'est moche.
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 jk2pach
Invité








MessagePosté le: 22/04/10 18:34    Sujet du message: Citer

Juste pour le 4, pas du tout: certains modules construits => une capacité ajoutée au corps principal.

Et ça fonctionne très bien.

Je regarderai le reste la semaine prochaine.

(Pour les joueurs, je ne comprends pas trop, le handle pointe si on ne le nullifie pas -_-)
_________________
Revenir en haut
 Troll-Brain
Ri1kamoua


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...)
Rédacteur de tuto #3 (Quantité : 1) Grand mage créateur de sort (Quantité : 1)

MessagePosté le: 22/04/10 18:42    Sujet du message: Citer

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)
_________________
Le violet, c'est moche.
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 jk2pach
Invité








MessagePosté le: 23/04/10 08:25    Sujet du message: Citer

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.
_________________
Revenir en haut
 Troll-Brain
Ri1kamoua


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...)
Rédacteur de tuto #3 (Quantité : 1) Grand mage créateur de sort (Quantité : 1)

MessagePosté le: 23/04/10 17:24    Sujet du message: Citer

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.
_________________
Le violet, c'est moche.
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs Toutes les heures sont au format GMT + 1 Heure
Page 1 sur 1
La question posée dans ce topic a été résolue !

 
Sauter vers:  
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


Powered by phpBB © 2001, 2005 phpBB Group
Traduction par : phpBB-fr.com