Independant Summon: je ne voulais pas pomper celui de Vexorian qui est très lourd.
Ca te parait bon le mien?
Secret:
Jass:
library IndSum initializer init requires Table, TimerUtils, BoundSentinel,GroupUtils
//=================================================
globals
private constant real TIMEOUT = 5.00
private constant real COMETOMIN = 50.
private constant real COMETOMAX = 200.
private constant real DISMAX = 500.
private constant real DISMAXTP = 2500.
private constant string FX = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
endglobals
//=================================================
private keyword s_IndSum
globals
private HandleTable TABLE
endglobals
//=================================================
private function init takes nothing returns nothing
set TABLE = HandleTable.create()
endfunction
//=================================================
private function runtimerorder takes nothing returns nothing
local s_IndSum g = GetTimerData( GetExpiredTimer() )
call g.UpdateOrder()
endfunction
//=================================================
private struct s_IndSum
private unit master
private unit summon
private timer ti = null
//=================================================
method UpdateOrder takes nothing returns nothing
local integer o=GetUnitCurrentOrder(.summon)
local real tx=GetUnitX(.master)
local real ty=GetUnitY(.master)
local real angle = 0.
local real dist = 0.
if GetUnitState(.summon,UNIT_STATE_LIFE) > 0 then
set dist=Pow(tx-GetUnitX(.summon),2) + Pow(ty-GetUnitY(.summon),2)
if dist > DISMAX and dist<DISMAXTP and (o == 0 or o == OrderId("attack") or o == OrderId("move") or o == OrderId("stop") or o==851971) then
call IssuePointOrder(.summon, "move", tx,ty)
else
if dist >= COMETOMIN and (o == 0 or o == 851971) then
set angle = GetRandomReal( GetUnitFacing(.master)-80, GetUnitFacing(.master)+80)
if (ModuloInteger(GetUnitPointValue(.summon),2)==0) then
set angle=angle * bj_DEGTORAD
else
set angle=- angle * bj_DEGTORAD
endif
set dist = GetRandomReal(COMETOMIN, COMETOMAX )
set tx=tx+dist*Cos(angle)
set ty=ty+dist*Sin(angle)
if not IssuePointOrder(.summon, "attack", tx, ty ) then
call IssuePointOrder(.summon, "move", tx, ty )
endif
endif
endif
if dist>DISMAXTP then
call DestroyEffect(AddSpecialEffect(FX,GetUnitX(.summon),GetUnitY(.summon)))
call DestroyEffect(AddSpecialEffect(FX,tx,ty))
call SetUnitPosition(.summon,tx,ty)
endif
else
call .Release()
endif
endmethod
//=================================================
method Link takes unit master returns nothing
set .master = master
set .ti = NewTimer()
call SetTimerData( .ti, this )
call TimerStart( .ti, TIMEOUT, true, function runtimerorder )
endmethod
//=================================================
method Release takes nothing returns nothing
call ReleaseTimer(.ti)
set .ti = null
set .master = null
call .destroy()
endmethod
//=================================================
//Constructor
static method create takes unit summon returns s_IndSum
local s_IndSum this = s_IndSum.allocate()
set this.summon = summon
return this
endmethod
//=================================================
endstruct
//=================================================
private function i2struct takes integer i returns s_IndSum
return i
endfunction
//=================================================
function IndSum takes unit summon returns s_IndSum
if( summon==null )then
return 0
endif
if( not TABLE.exists(summon) )then
set TABLE[summon] = s_IndSum.create(summon)
else
call TABLE.destroy(i2struct(TABLE[summon]))
set TABLE[summon] = s_IndSum.create(summon)
endif
return i2struct(TABLE[summon])
endfunction
endlibrary
Système d'orbites des planètes: affecte une position au bâtiments construits, et empêche d'en construire trop.
Ca te parait bien?
Cela détruit les bâtiments si la planète meurt.
Secret:
Jass:
library OrbSys initializer init requires Table,BoundSentinel,TextDisplay,Resource
//=================================================
globals
private constant integer SLOT = 14
private constant string C = "The planet has to much buildings orbiting arround it."
endglobals
//=================================================
private keyword s_OrbSys
globals
private HandleTable TABLE
endglobals
//=================================================
private function init takes nothing returns nothing
set TABLE = HandleTable.create()
endfunction
//=================================================
private struct s_OrbSys
private unit planet
private unit array sat [SLOT]
private real array a [SLOT]
private real array d [SLOT]
private real angle = 0.00
//=================================================
method LinkSat takes unit sat returns nothing
local integer i = 0
local real x = 0.
local real y = 0.
//Refresh: dead sat are cancelled
loop
exitwhen i > SLOT-1
if GetUnitState(.sat[i], UNIT_STATE_LIFE) <= 0 then
set .sat[i] = null
endif
set i = i + 1
endloop
//Seting the new satellite
set i = 0
loop
exitwhen i > SLOT-1
if .sat[i] == null and i <= 13 then
set .sat[i] = sat
call SetUnitPathing(sat,false)
set x = GetUnitX(.planet)+.d[i]*Cos(.a[i]*bj_DEGTORAD)
set y = GetUnitY(.planet)+.d[i]*Sin(.a[i]*bj_DEGTORAD)
call SetUnitPosition(sat,x,y)
return
endif
set i = i + 1
endloop
call .PreventBuilding(sat)
endmethod
//=================================================
method PreventBuilding takes unit sat returns nothing
local integer i = 0
local player owner = GetOwningPlayer(sat)
call RemoveUnit(sat)
loop
set i = i + 1
exitwhen i > CostMax
if GetUnitTypeId(sat)== CostUnitId[i] then
call DisplayTextToPlayer(owner, 0, 0, C)
call ErrorSound(owner)
call SetResource(owner,CostGold[i],CostLumber[i])
set owner = null
return
endif
endloop
set owner = null
endmethod
//=================================================
method SetPlanetProperties takes nothing returns nothing
local integer i = 0
loop
exitwhen i > SLOT
if i <=5 then
set .a[i]= 60.00*i
set .d[i] = 100.
endif
if i >5 and i <= 13 then
set .a[i]= 45.00*i
set .d[i] = 162.5
endif
set i = i + 1
endloop
endmethod
//=================================================
method Release takes nothing returns nothing
local integer i = 0
loop
exitwhen i > SLOT - 1
call KillUnit(.sat[i])
set .sat[i] = null
set i = i + 1
endloop
set .planet = null
call .destroy()
endmethod
//=================================================
//Constructor
static method create takes unit planet returns s_OrbSys
local s_OrbSys this = s_OrbSys.allocate()
set this.planet = planet
return this
endmethod
//=================================================
endstruct
//=================================================
private function i2struct takes integer i returns s_OrbSys
return i
endfunction
//=================================================
function OrbSys takes unit planet returns s_OrbSys
if( planet==null )then
return 0
endif
if( not TABLE.exists(planet) )then
set TABLE[planet] = s_OrbSys.create(planet)
endif
return i2struct(TABLE[planet])
endfunction
endlibrary
Exemple:
Secret:
Jass:
scope orbitesbtpunits initializer init
//=================================================
private function Conditions takes nothing returns boolean
local unit planet = GetTriggerUnit()
local unit sat = GetTrainedUnit()
if IsUnitType(sat, UNIT_TYPE_MECHANICAL) == true and IsUnitType(planet, UNIT_TYPE_ANCIENT) == true then
call OrbSys(planet).LinkSat(sat)
endif
set planet = null
set sat = null
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
endscope
Le principe: tu sélectionne une unité (cargo etc) et tu utilise sa compétence appelée "Select A Buyer" en cliquant sur une autre unité appelée Freeport.
Le système envoie l'unité périodiquement faire l'aller retour entre le Freeport du joueur et le Freeport Allié ciblé par la compétence.
Le Freeport allié achète les objets du cargo. Le Freeport du propriétaire du cargo lui donne des objets, etc.
Le trajet automatique est désactivé en utilisant une compétence sans cible, Abort Trade.
Les marchands ont des bonus (comme pouvoir remplacer le Freeport Allié par des planètes)
Suppléments:
Les Freeports ont une capacité (Create A Trade Road). En sélectionnant un Freeport allié via cette compétence, on créé une série d'unité dummy en forme de portails.
Le système GateSys détecte alors pour tous les cargos en trajet entre les deux freeports si il y a une Trade Road existante.
Si oui, il envoie les cargos en vitesse rapide (dérivé de l'hyperespace).
En théorie tout fonctionne, mais ça consomme pas mal de ressources. Tu auras peut-être de meilleures idées.
Sachant que la manière dont les objets sont gérés doit rester (avec des vrais objets qui sont ajoutés sur une unité dès qu'elle rentre sur la carte) pour plus de visibilité, et permettre d'autres actions (comme le piratage).
Library principale
Secret:
Jass:
library TradeSys initializer init requires Table, TimerUtils, BoundSentinel, GateSys, AbilityPreload, RoadMove,SoundUtils, TextDisplay,Resource,GroupUtils,BoardSystem
//=================================================
globals
private constant real TIMEOUT = 10.00 //Interval to check the status of a cargo
private constant integer WILLSELL = 'A03I' //dummmy ability to know if the cargo will sell its products
private constant integer WILLBACK = 'A03J' //dummmy ability to know if the cargo will re buy its products
private constant string FXLOAD = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
private constant string FXUNLOAD = "UI\\Feedback\\GoldCredit\\GoldCredit.mdl"
private constant string C1 = "|cff008040"
private constant string C2 = "|cff80FFFF"
private constant string C = " |r"
private constant integer ABORT = 'A00C' //ability which stops all trade operation for a cargo
private constant real RANGEMAX = 125.00 //radius maximum to check the nearest freeport
constant integer CARGOSHUTTLE = 'h00N'
constant integer CARGOCRUISER = 'h01C'
constant integer CARGOMOTHERSHIP3 = 'H02M'
constant integer CARGOMOTHERSHIP2 = 'H02H'
constant integer CARGOMOTHERSHIP1 = 'H02E'
constant integer FREEPORT = 'h00O'
constant integer CARGOSPEED = 'A020'
constant integer PRODUCT = 'I000'
constant integer CARGOSLOT = 'R00K'
unit array Freeport [16]
integer SOUND_GOLD
endglobals
//=================================================
private keyword s_TradeSys
globals
private HandleTable TABLE
endglobals
//=================================================
private function init takes nothing returns nothing
call AbilityPreload(WILLSELL)
call AbilityPreload(CARGOSPEED)
call AbilityPreload(WILLBACK)
call AbilityPreload(CARGOSLOT)
call AbilityPreload(ABORT)
set SOUND_GOLD = DefineSound("Abilities\\Spells\\Other\\Transmute\\AlchemistTransmuteDeath1.wav",1601 , false, true)
set TABLE = HandleTable.create()
endfunction
//=================================================
private function BoucleUpdate takes nothing returns nothing
local s_TradeSys g = GetTimerData( GetExpiredTimer() )
call g.Update()
endfunction
//=================================================
private struct s_TradeSys
private unit buyer = null
private unit seller = null
private timer ti = null
private player owner = null
private unit cargo
//=================================================
method Update takes nothing returns nothing
local real x1 = GetUnitX(.cargo)
local real y1 = GetUnitY(.cargo)
local real x2 = GetUnitX(.seller)
local real y2 = GetUnitY(.seller)
local real x3 = GetUnitX(.buyer)
local real y3 = GetUnitY(.buyer)
local real distanteBetweenPorts = SquareRoot((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2))
local real distanceBetweenShipAndSeller = SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
local real distanceBetweenShipAndBuyer = SquareRoot((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1))
local integer i = 0
if .cargo != null and GetUnitState(.cargo ,UNIT_STATE_LIFE)>0 and .buyer != null and GetUnitState(.buyer ,UNIT_STATE_LIFE)>0 and .seller != null and GetUnitState(.seller ,UNIT_STATE_LIFE)>0 then
if GetUnitAbilityLevel(.cargo,WILLBACK)>=1 and GetUnitAbilityLevel(.cargo,WILLSELL)<=0 then
if distanceBetweenShipAndSeller <= RANGEMAX then
call .Buy()
call UnitRemoveAbility(.cargo,WILLBACK)
call UnitAddAbility(.cargo,WILLSELL)
if GateSys(.buyer).IsRoadOk(.seller)==true or GateSys(.seller).IsRoadOk(.buyer)==true then
if GetUnitAbilityLevel(.cargo,HYPMOVING)<=0 then
call RoadMove(.cargo).Link(x3,y3)
endif
else
call IssuePointOrder(.cargo,"move",x3,y3)
endif
call DestroyEffect(AddSpecialEffect(FXLOAD,x1,y1))
else
if GateSys(.buyer).IsRoadOk(.seller)==true or GateSys(.seller).IsRoadOk(.buyer)==true then
if GetUnitAbilityLevel(.cargo,HYPMOVING)<=0 then
call RoadMove(.cargo).Link(x2,y2)
endif
else
call IssuePointOrder(.cargo,"move",x2,y2)
endif
endif
elseif GetUnitAbilityLevel(.cargo,WILLBACK)<=0 and GetUnitAbilityLevel(.cargo,WILLSELL)>=1 then
if distanceBetweenShipAndBuyer <= RANGEMAX then
call .Sell(distanteBetweenPorts)
call UnitRemoveAbility(.cargo,WILLSELL)
call UnitAddAbility(.cargo,WILLBACK)
if GateSys(.buyer).IsRoadOk(.seller)==true or GateSys(.seller).IsRoadOk(.buyer)==true then
if GetUnitAbilityLevel(.cargo,HYPMOVING)<=0 then
call RoadMove(.cargo).Link(x2,y2)
else
call RoadMove(.cargo).Release()
endif
else
call IssuePointOrder(.cargo,"move",x2,y2)
endif
call DestroyEffect(AddSpecialEffect(FXLOAD,x1,y1))
else
if GateSys(.buyer).IsRoadOk(.seller)==true or GateSys(.seller).IsRoadOk(.buyer)==true then
if GetUnitAbilityLevel(.cargo,HYPMOVING)<=0 then
call RoadMove(.cargo).Link(x3,y3)
else
call RoadMove(.cargo).Release()
endif
else
call IssuePointOrder(.cargo,"move",x3,y3)
endif
endif
endif
else
call .Release()
endif
endmethod
//=================================================
method GetProductAmount takes nothing returns integer
local integer i = 0
local item carriedItem = null
local integer carriedItemCharges = 0
loop
exitwhen i > 5
set carriedItem = UnitItemInSlot(.cargo, i)
if GetItemTypeId(carriedItem) == PRODUCT then
set carriedItemCharges = GetItemCharges(carriedItem)
set carriedItem = null
return carriedItemCharges
endif
set i = i + 1
endloop
set carriedItem = null
return 0
endmethod
//=================================================
method Buy takes nothing returns nothing
local integer i = 0
local integer slotAmount = GetPlayerTechCount(.owner,CARGOSLOT,true)
local item carriedItem = null
loop
exitwhen i > 5
set carriedItem = UnitItemInSlot(.cargo, i)
if GetItemTypeId(carriedItem) == PRODUCT and GetItemCharges(carriedItem)<=slotAmount then
call SetItemCharges(carriedItem,slotAmount)
endif
set i = i + 1
endloop
set carriedItem = null
endmethod
//=================================================
method Sell takes real distanteBetweenPorts returns nothing
local integer productAmount = .GetProductAmount()
local integer gold = R2I(distanteBetweenPorts*0.05*0.05)*productAmount*2
local integer lumber = R2I(distanteBetweenPorts*0.02*0.05)*productAmount*2
local item carriedItem = null
local integer i = 0
local integer ownerId = GetPlayerId(.owner)
loop
exitwhen i > 5
set carriedItem = UnitItemInSlot(.cargo, i)
if GetItemTypeId(carriedItem) == PRODUCT then
call SetItemCharges(carriedItem,0)
endif
set i = i + 1
endloop
if Merchant[GetPlayerId(.owner)]== true then
set gold = R2I(gold*1.15)
set lumber = R2I(lumber*1.15)
endif
if GetUnitTypeId(.cargo)==CARGOCRUISER then
set gold = R2I(gold*10.00)
set lumber = R2I(lumber*10.00)
elseif GetUnitTypeId(.cargo)==CARGOMOTHERSHIP1 then
set gold = R2I(gold*(5.00+MsSys(.owner).CountCargoMod()))
set lumber = R2I(lumber*(5.00+MsSys(.owner).CountCargoMod()))
elseif GetUnitTypeId(.cargo)==CARGOMOTHERSHIP2 then
set gold = R2I(gold*(8.00+MsSys(.owner).CountCargoMod()))
set lumber = R2I(lumber*(8.00+MsSys(.owner).CountCargoMod()))
elseif GetUnitTypeId(.cargo)==CARGOMOTHERSHIP3 then
set gold = R2I(gold*(13.00+MsSys(.owner).CountCargoMod()))
set lumber = R2I(lumber*(13.00+MsSys(.owner).CountCargoMod()))
endif
call SetResource(.owner,gold,lumber)
call RunSoundOnUnit(SOUND_GOLD,.cargo)
call Text(.cargo,false,C1+I2S(gold)+C+" p, "+C2+I2S(lumber)+C+" i")
if Merchant[ownerId]==true then
call UpdateRank(.owner,XP_TRADE)
endif
set carriedItem = null
endmethod
//=================================================
method LinkBuyer takes unit buyer returns nothing
set .buyer = buyer
set .owner = GetOwningPlayer(.cargo)
if GetUnitAbilityLevel(.cargo,ABORT)<=0 then
call UnitAddAbility(.cargo,ABORT)
endif
if GetUnitAbilityLevel(.cargo,WILLBACK)<=0 then
call UnitAddAbility(.cargo,WILLBACK)
endif
call UnitRemoveAbility(.cargo,SELECTBUYER)
set .seller = Freeport[GetPlayerId(.owner)]
if .seller != null and GetUnitState(.seller,UNIT_STATE_LIFE)>0 then
set .ti = NewTimer()
call SetTimerData( .ti, this )
call TimerStart( .ti, TIMEOUT, true, function BoucleUpdate )
else
call DisplayTextToPlayer(GetOwningPlayer(.cargo),0.,0.,"No freeport detected")
endif
endmethod
//=================================================
method Release takes nothing returns nothing
call ReleaseTimer(.ti)
set .ti = null
call UnitAddAbility(.cargo,SELECTBUYER)
call IssueImmediateOrder(.cargo,"stop")
if GetUnitAbilityLevel(.cargo,WILLSELL)>=1 then
call UnitRemoveAbility(.cargo,WILLSELL)
endif
if GetUnitAbilityLevel(.cargo,WILLBACK)>=1 then
call UnitRemoveAbility(.cargo,WILLBACK)
endif
set .buyer = null
set .seller = null
set .owner = null
call .destroy()
endmethod
//=================================================
//Constructor
static method create takes unit cargo returns s_TradeSys
local s_TradeSys this = s_TradeSys.allocate()
set this.cargo = cargo
return this
endmethod
//=================================================
endstruct
//=================================================
private function i2struct takes integer i returns s_TradeSys
return i
endfunction
//=================================================
function TradeSys takes unit cargo returns s_TradeSys
if( cargo==null )then
return 0
endif
if( not TABLE.exists(cargo) )then
set TABLE[cargo] = s_TradeSys.create(cargo)
endif
return i2struct(TABLE[cargo])
endfunction
endlibrary
scope products initializer init
//=================================================
private function Conditions takes nothing returns boolean
local unit entering = GetTriggerUnit()
local integer enteringId = GetUnitTypeId(entering)
if enteringId == CARGOSHUTTLE or enteringId == CARGOCRUISER or enteringId == CARGOMOTHERSHIP1 or enteringId == CARGOMOTHERSHIP2 or enteringId == CARGOMOTHERSHIP3 then
call UnitAddItem(entering,CreateItem(PRODUCT,0.,0.))
endif
set entering = null
return false
endfunction
///=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call RemoveItem(CreateItem(PRODUCT,0.,0.))
call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea)
call TriggerAddCondition( t, Condition( function Conditions ) )
endfunction
///=================================================
endscope
Arrêt du trajet auto
Secret:
Jass:
scope abortrade initializer init
//=================================================
globals
private constant integer SPELL = 'A00C'
endglobals
//=================================================
private function Actions takes nothing returns nothing
local unit caster = SpellEvent.CastingUnit
call UnitRemoveAbility(caster,SPELL)
call TradeSys(caster).Release()
set caster = null
endfunction
//=================================================
public function init takes nothing returns nothing
call RegisterSpellCastResponse(SPELL,Actions)
endfunction
//=================================================
endscope
Sélectionner un Freeport Cible pour lancer le trajet automatique
Secret:
Jass:
scope linkbuyernunit initializer init
//=================================================
globals
constant integer SELECTBUYER = 'A03H'
private constant string C1 = "Please select an allied FreePort"
private constant string C2 = "Only Merchants can trade with planets"
private constant string C3 = "You can not select your own freeport"
endglobals
//=================================================
private function Actions takes nothing returns nothing
local unit cargo = SpellEvent.CastingUnit
local unit buyer = SpellEvent.TargetUnit
local player owner = GetOwningPlayer(cargo)
local integer ownerId = GetPlayerId(owner)
if IsPlayerEnemy(owner,GetOwningPlayer(buyer))==false then
if IsUnitType(buyer,UNIT_TYPE_ANCIENT)==true then
if Merchant[GetPlayerId(owner)]== true then
call TradeSys(cargo).LinkBuyer(buyer)
set cargo = null
set buyer = null
set owner = null
return
else
call ErrorSound(owner)
call DisplayTextToPlayer(owner,0,0,C2)
endif
endif
if GetUnitTypeId(buyer)==FREEPORT then
if buyer != Freeport[ownerId] then
call TradeSys(cargo).LinkBuyer(buyer)
else
call ErrorSound(owner)
call DisplayTextToPlayer(owner,0,0,C3)
endif
set cargo = null
set buyer = null
set owner = null
return
else
call ErrorSound(owner)
call DisplayTextToPlayer(owner,0,0,C1)
endif
else
call ErrorSound(owner)
call DisplayTextToPlayer(owner,0,0,C1)
endif
set cargo = null
set buyer = null
set owner = null
endfunction
//=================================================
public function init takes nothing returns nothing
call AbilityPreload(SELECTBUYER)
call RegisterSpellCastResponse(SELECTBUYER,Actions)
endfunction
//=================================================
endscope
library RoadMove initializer init requires Table, TimerUtils, BoundSentinel,AbilityPreload,SoundUtils,OrbSysTerrorist
//=================================================
globals
private constant integer SPEED = 25 //Base move speed
private constant string FX = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl" //effect linked on a unit
constant integer TRADEROADISMOVING = 'A04O' //Kind of boolean allowing to detect if the unit is channeling the RoadMoveerespace
private constant real TIMEOUTMOVE =0.05 //interval for the movement
endglobals
//=================================================
private keyword s_RoadMove
globals
private HandleTable TABLE
endglobals
//=================================================
private function init takes nothing returns nothing
call AbilityPreload(TRADEROADISMOVING) //Antileak
set TABLE = HandleTable.create()
endfunction
//=================================================
private function RunTimerMove takes nothing returns nothing
local s_RoadMove g = GetTimerData( GetExpiredTimer() )
call g.UpdateMove()
endfunction
//=================================================
private struct s_RoadMove
private unit ship
private timer ti = null
private integer countmove = 0
private effect fx = null
private real angle = 0.
private integer distance = 0
private real x1 = 0.
private real y1 = 0.
private real x2 = 0.
private real y2 = 0.
//=================================================
method UpdateMove takes nothing returns nothing
local real newX = GetUnitX(.ship) + SPEED*Cos(.angle)
local real newY = GetUnitY(.ship) + SPEED*Sin(.angle)
if .countmove < .distance and GetUnitState(.ship,UNIT_STATE_LIFE)>0 and GetUnitAbilityLevel(.ship,TRADEROADISMOVING)>=1 then
set .countmove = .countmove + 1
call SetUnitPosition(.ship,newX,newY)
else
call .Release()
endif
endmethod
//=================================================
method Link takes real destX, real destY returns nothing
set .x1 = GetUnitX(.ship)
set .y1 = GetUnitY(.ship)
set .angle = Atan2((destY-.y1), (destX-.x1))
set .distance =R2I(SquareRoot((destX-.x1)*(destX-.x1)+(destY-.y1)*(destY-.y1))/SPEED)
set .x1 = GetUnitX(.ship) +200.*Cos(.angle)
set .y1 = GetUnitY(.ship) +200.*Sin(.angle)
set .x2 = destX -100.*Cos(.angle)
set .y2 = destY -100.*Sin(.angle)
call SetUnitFacing(.ship, .angle*bj_RADTODEG)
set .fx = AddSpecialEffectTarget(FX,.ship,"origin")
set .countmove = 0
call RunSoundOnUnit(SOUND_HYPERSTART,.ship)
call UnitAddAbility(.ship,TRADEROADISMOVING)
set .ti = NewTimer()
call SetTimerData( .ti, this )
call TimerStart( .ti, TIMEOUTMOVE, true, function RunTimerMove )
endmethod
//=================================================
method Release takes nothing returns nothing
call SetUnitPathing( .ship, true)
call RunSoundOnUnit(SOUND_HYPEREND,.ship)
if GetUnitAbilityLevel(.ship,TRADEROADISMOVING)>=1 then
call UnitRemoveAbility(.ship,TRADEROADISMOVING)
endif
call DestroyEffect(.fx)
set .fx = null
call ReleaseTimer(.ti)
set .ti = null
call .destroy()
endmethod
//=================================================
static method create takes unit ship returns s_RoadMove
local s_RoadMove this = s_RoadMove.allocate()
set this.ship = ship
return this
endmethod
//=================================================
endstruct
//=================================================
private function i2struct takes integer i returns s_RoadMove
return i
endfunction
//=================================================
function RoadMove takes unit ship returns s_RoadMove
if( ship==null )then
return 0
endif
if( not TABLE.exists(ship) )then
set TABLE[ship] = s_RoadMove.create(ship)
endif
return i2struct(TABLE[ship])
endfunction
endlibrary
Si un cargo utilise une compétence, annule la vitesse lumière
Secret:
Jass:
scope hpstoproad initializer init
//=================================================
private function Conditions takes nothing returns boolean
local unit caster = GetTriggerUnit()
if GetUnitAbilityLevel(caster,TRADEROADISMOVING)>=1 then
call UnitRemoveAbility(caster,TRADEROADISMOVING)
endif
set caster = null
return false
endfunction
//===========================================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
endscope
Système de répérage des Trade Roads entre les freeports
Secret:
Jass:
library GateSys initializer init requires Table
//=================================================
private keyword s_GateSys
globals
private HandleTable TABLE
endglobals
//=================================================
private function init takes nothing returns nothing
set TABLE = HandleTable.create()
endfunction
//=================================================
private struct s_GateSys
private unit port2 = null
private unit port1
//=================================================
method IsRoadOk takes unit port2 returns boolean
if .port1 != null and .port2 != null and GetUnitState(.port1 ,UNIT_STATE_LIFE)>0 and GetUnitState(.port2 ,UNIT_STATE_LIFE)>0 then
return true
else
call .Release()
return false
endif
endmethod
//=================================================
method LinkGate takes unit port2 returns nothing
set .port2 = port2
endmethod
//=================================================
method Release takes nothing returns nothing
set .port2 = null
call .destroy()
endmethod
//=================================================
//Constructor
static method create takes unit port1 returns s_GateSys
local s_GateSys this = s_GateSys.allocate()
set this.port1 = port1
return this
endmethod
//=================================================
endstruct
//=================================================
private function i2struct takes integer i returns s_GateSys
return i
endfunction
//=================================================
function GateSys takes unit port1 returns s_GateSys
if( port1==null )then
return 0
endif
if( not TABLE.exists(port1) )then
set TABLE[port1] = s_GateSys.create(port1)
endif
return i2struct(TABLE[port1])
endfunction
endlibrary
Création Trade Road
Secret:
Jass:
scope createroad initializer init
//=================================================
globals
private constant integer SPELL = 'A03K'
constant integer GATE = 'o00T'
private constant string C1 = "Please select an allied FreePort."
private constant string C2 = "Only Merchants can trade with planets."
private constant string C3 = "You need 500 iron to open a trade road."
private constant real INTERVAL = 250.
private constant real DUR = 240.
endglobals
//=================================================
private struct str
unit target
integer i
endstruct
//=================================================
private function Wait takes nothing returns nothing
local timer t = GetExpiredTimer()
local str dat = GetTimerData(t)
if dat.target!=null and GetUnitState(dat.target ,UNIT_STATE_LIFE)>0 and dat.i<R2I(DUR) then
set dat.i = dat.i + 1
else
call GateSys(dat.target).Release()
call ReleaseTimer(t)
call dat.destroy()
endif
endfunction
//=================================================
private function Ini takes unit target returns nothing
local timer t = NewTimer()
local str dat = str.create()
set dat.target = target
set dat.i = 0
call SetTimerData(t, dat)
call TimerStart (t, 1., true, function Wait )
endfunction
//=================================================
private function Actions takes nothing returns nothing
local integer i = 0
local unit roadCreator = SpellEvent.CastingUnit
local unit roadTarget = SpellEvent.TargetUnit
local player owner = GetOwningPlayer(roadCreator)
local real x1 = GetUnitX(roadCreator)
local real y1 = GetUnitY(roadCreator)
local real x2 = GetUnitX(roadTarget)
local real y2 = GetUnitY(roadTarget)
local real angle = Atan2((y2 -y1), (x2 - x1))
local real distance = SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
if IsPlayerEnemy(owner,GetOwningPlayer(roadTarget))==false then
if GetUnitTypeId(roadTarget)==FREEPORT then
if GetPlayerState(owner,PLAYER_STATE_RESOURCE_LUMBER)>= 500 then
call SetPlayerState(owner, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(owner,PLAYER_STATE_RESOURCE_LUMBER)-500)
loop
set i = i + 1
exitwhen i > distance/INTERVAL
set x2 = x1 + i*INTERVAL*Cos(angle)
set y2 = y1 + i*INTERVAL*Sin(angle)
call UnitApplyTimedLife(CreateUnit(owner,GATE,x2,y2,angle*bj_RADTODEG),'BTLF',DUR)
endloop
call Ini(roadCreator)
call GateSys(roadCreator).LinkGate(roadTarget)
set roadCreator = null
set roadTarget = null
set owner = null
return
else
call ErrorSound(owner)
call DisplayTextToPlayer(owner,0,0,C3)
endif
else
call ErrorSound(owner)
call DisplayTextToPlayer(owner,0,0,C1)
endif
else
call ErrorSound(owner)
call DisplayTextToPlayer(owner,0,0,C1)
endif
set roadCreator = null
set roadTarget = null
set owner = null
endfunction
//=================================================
public function init takes nothing returns nothing
call RegisterSpellCastResponse(SPELL,Actions)
endfunction
//=================================================
endscope
Repérage et suppression du Freeport (unique) d'un joueur
Secret:
Jass:
scope addfreeport initializer init
//=================================================
private function Conditions takes nothing returns boolean
local unit constructed = GetConstructedStructure()
if GetUnitTypeId(constructed)==FREEPORT then
set Freeport[GetPlayerId(GetOwningPlayer(constructed))] = constructed
endif
set constructed = null
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
endscope
Secret:
Jass:
scope removefreeport initializer init
//=================================================
private function Conditions takes nothing returns boolean
local unit killedUnit = GetTriggerUnit()
if GetUnitTypeId(killedUnit)==FREEPORT then
set Freeport[GetPlayerId(GetOwningPlayer(killedUnit))] = null
endif
set killedUnit = null
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
endscope
L'autre gros système: Motherships
L'idée est d'offrir à chaque joueur (sauf pour les Aliens et Terrorists) un vaisseau en début de partie.
Ce vaisseau va pouvoir recevoir des "modules".
Les modules sont des unités dummys construites à partir d'un bâtiment (le dock).
La première opération crééra donc une unité invisible, que l'on peut upgrader en une série de modules eux-mêmes uprgradables.
A chaque fois , le module ainsi créer va suivre le corps principal du Mothership grâce aux timers, selon la position enregistrée dans les variables initiales (premier déclencheur ci-dessous).
La plupart de ces modules tirent ou lancent des sorts. Ils doivent donc être déplacés sans interruption d'animation (donc avec SetUnitX et SetUnitY). Les autres sont bidons, et ajoutent des compétences au Mothership (par détection de leur création).
Les motherships sont eux-même upgradables en tonnage supérieur (navetter=>frégate=>croiseur).
Variables
Secret:
Jass:
scope msvar initializer init
//=================================================
globals
integer MsMainMax
integer array MsMainId [12]
integer MsModWithSpellMax
integer array MsModWithSpellId [15]
integer array MsModSpellId [15]
real array ModAngle [12][8]
real array ModDistance [12][8]
real array ModHeight [12][8]
boolean array MsCanTrade[12]
constant integer UpToFrig ='R00Z'
constant integer UpToCruiz ='R010'
constant integer HasShut = 'R00W'
constant integer HasFrig = 'R00X'
constant integer HasCruiz ='R00Y'
constant integer ISMSMOD = 'A03X'
endglobals
//=================================================
public function init takes nothing returns nothing
local integer i = 0
//Motherships
// Pour le système d'upgrade, conserver le même ordre entre chaque classe
set i = 0
// 0
set MsMainId[i] = 'H02E'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 0.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = -10.
set ModHeight[i][0] = 5.
set ModHeight[i][1] = 5.
set MsCanTrade[i]=true
// 1
set i = i + 1
set MsMainId[i] = 'H02D'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 0.
set ModDistance[i][0] = 10.
set ModDistance[i][1] = -10.
set ModHeight[i][0] = 5.
set ModHeight[i][1] = 5.
set MsCanTrade[i]=false
// 2
set i = i + 1
set MsMainId[i] = 'H02F'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 0.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = 15.
set ModHeight[i][0] = 6.
set ModHeight[i][1] = 6.
set MsCanTrade[i]=false
// 3
set i = i + 1
set MsMainId[i] = 'H02C'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 90.
set ModDistance[i][0] = 10.
set ModDistance[i][1] = 10.
set ModHeight[i][0] = 5.
set ModHeight[i][1] = 5.
set MsCanTrade[i]=false
// 4
set i = i + 1
set MsMainId[i] = 'H02H'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = -180.
set ModAngle[i][2] = -180.
set ModAngle[i][3] = -180.
set ModDistance[i][0] = 10.
set ModDistance[i][1] = 0.
set ModDistance[i][2] = 20.
set ModDistance[i][3] = 10.
set ModHeight[i][0] = 10.
set ModHeight[i][1] = 10.
set ModHeight[i][2] = 10.
set ModHeight[i][3] = 10.
set MsCanTrade[i]=true
// 5
set i = i + 1
set MsMainId[i] = 'H02N'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = -180.
set ModAngle[i][2] = -180.
set ModAngle[i][3] = 0.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = 12.5
set ModDistance[i][2] = 25.
set ModDistance[i][3] = 12.5
set ModHeight[i][0] = 20.
set ModHeight[i][1] = 20.
set ModHeight[i][2] = 20.
set ModHeight[i][3] = 20.
set MsCanTrade[i]=false
// 6
set i = i + 1
set MsMainId[i] = 'H02O'
set ModAngle[i][0] = -180.
set ModAngle[i][1] = -180.
set ModAngle[i][2] = -180.
set ModAngle[i][3] = -180.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = 12.5
set ModDistance[i][2] = 25.
set ModDistance[i][3] = 37.5
set ModHeight[i][0] = 5.
set ModHeight[i][1] = 5.
set ModHeight[i][2] = 5.
set ModHeight[i][3] = 5.
set MsCanTrade[i]=false
// 7
set i = i + 1
set MsMainId[i] = 'H02K'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 45.
set ModAngle[i][2] = -45.
set ModAngle[i][3] = -315.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = 12.5
set ModDistance[i][2] = 12.5
set ModDistance[i][3] = 12.5
set ModHeight[i][0] = 10.
set ModHeight[i][1] = 10.
set ModHeight[i][2] = 10.
set ModHeight[i][3] = 10.
set MsCanTrade[i]=false
// 8
set i = i + 1
set MsMainId[i] = 'H02M'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 0.
set ModAngle[i][2] = 0.
set ModAngle[i][3] = 0.
set ModAngle[i][4] = 0.
set ModAngle[i][5] = 0.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = 10.
set ModDistance[i][2] = 15.
set ModDistance[i][3] = 20.
set ModDistance[i][4] = 25.
set ModDistance[i][5] = 30.
set ModHeight[i][0] = 15.
set ModHeight[i][1] = 15.
set ModHeight[i][2] = 15.
set ModHeight[i][3] = 15.
set ModHeight[i][4] = 15.
set ModHeight[i][5] = 15.
set MsCanTrade[i]=true
// 9
set i = i + 1
set MsMainId[i] = 'H02L'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 180.
set ModAngle[i][2] = 45.
set ModAngle[i][3] = -45.
set ModAngle[i][4] = 225.
set ModAngle[i][5] = -225.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = 10.
set ModDistance[i][2] = 25.
set ModDistance[i][3] = 25.
set ModDistance[i][4] = 25.
set ModDistance[i][5] = 25.
set ModHeight[i][0] = 30.
set ModHeight[i][1] = 30.
set ModHeight[i][2] = 30.
set ModHeight[i][3] = 30.
set ModHeight[i][4] = 30.
set ModHeight[i][5] = 30.
set MsCanTrade[i]=false
// 10
set i = i + 1
set MsMainId[i] = 'H02I'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 180.
set ModAngle[i][2] = 45.
set ModAngle[i][3] = -45.
set ModAngle[i][4] = 315.
set ModAngle[i][5] = -315.
set ModDistance[i][0] = 25.
set ModDistance[i][1] = 25.
set ModDistance[i][2] = 25.
set ModDistance[i][3] = 25.
set ModDistance[i][4] = 25.
set ModDistance[i][5] = 25.
set ModHeight[i][0] = 20.
set ModHeight[i][1] = 20.
set ModHeight[i][2] = 20.
set ModHeight[i][3] = 20.
set ModHeight[i][4] = 20.
set ModHeight[i][5] = 20.
set MsCanTrade[i]=false
// 11
set i = i + 1
set MsMainId[i] = 'H02J'
set ModAngle[i][0] = 0.
set ModAngle[i][1] = 0.
set ModAngle[i][2] = 45.
set ModAngle[i][3] = -45.
set ModAngle[i][4] = 90.
set ModAngle[i][5] = -90.
set ModDistance[i][0] = 0.
set ModDistance[i][1] = 12.5
set ModDistance[i][2] = 17.5
set ModDistance[i][3] = 12.5
set ModDistance[i][4] = 12.5
set ModDistance[i][5] = 12.5
set ModHeight[i][0] = 25.
set ModHeight[i][1] = 25.
set ModHeight[i][2] = 25.
set ModHeight[i][3] = 25.
set ModHeight[i][4] = 25.
set ModHeight[i][5] = 25.
set MsCanTrade[i]=false
//SetMax
set MsMainMax = i
//Tourelles avec une capacité
set i = 0
set MsModWithSpellId[i] = 'E004'
set MsModSpellId[i] = 'A00O'
set i = i + 1
set MsModWithSpellId[i] = 'E005'
set MsModSpellId[i] = 'A00P'
set i = i + 1
set MsModWithSpellId[i] = 'E013'
set MsModSpellId[i] = 'A01W'
set i = i + 1
set MsModWithSpellId[i] = 'E014'
set MsModSpellId[i] = 'A000'
set i = i + 1
set MsModWithSpellId[i] = 'E024'
set MsModSpellId[i] = 'A033'
set i = i + 1
set MsModWithSpellId[i] = 'E028'
set MsModSpellId[i] = 'A00L'
set i = i + 1
set MsModWithSpellId[i] = 'E029'
set MsModSpellId[i] = 'A00N'
set i = i + 1
set MsModWithSpellId[i] = 'E030'
set MsModSpellId[i] = 'A00M'
set i = i + 1
set MsModWithSpellId[i] = 'E032'
set MsModSpellId[i] = 'A034'
set i = i + 1
set MsModWithSpellId[i] = 'E035'
set MsModSpellId[i] = 'A035'
//SetMax
set MsModWithSpellMax = i
set i = 0
loop
exitwhen i > MsModWithSpellMax
call AbilityPreload(MsModSpellId[i])
set i = i + 1
endloop
endfunction
//=================================================
endscope
library MsSys initializer init requires Table, TimerUtils, BoundSentinel,GateSys, AbilityPreload
//=================================================
globals
private constant real TIMEOUT = 0.05
private constant integer MODALLOWED = 6
private constant integer CARGO1 = 'E010'
private constant integer CARGO2 = 'E011'
private constant integer CARGO3 = 'E012'
endglobals
//=================================================
private keyword s_MsSys
globals
private HandleTable TABLE
endglobals
//=================================================
private function init takes nothing returns nothing
call AbilityPreload(ISMSMOD)
set TABLE = HandleTable.create()
endfunction
//=================================================
private function BoucleUpdate takes nothing returns nothing
local s_MsSys g = GetTimerData( GetExpiredTimer() )
call g.Update()
endfunction
//=================================================
private struct s_MsSys
private player pl = null
private unit ms = null
private timer ti = null
private unit array m [MODALLOWED]
private real array a [MODALLOWED]
private real array d [MODALLOWED]
private real array f [MODALLOWED]
private integer countmod = 0
private integer array spell [15]
//=================================================
method Update takes nothing returns nothing
local real x1 = GetUnitX(.ms)
local real y1 = GetUnitY(.ms)
local real facing = GetUnitFacing(.ms)
local integer i = 0
loop
exitwhen i > MODALLOWED
if GetUnitState(.m[i], UNIT_STATE_LIFE) > 0 then
call SetUnitX(.m[i],x1+.d[i]*Cos((facing + .a[i])*bj_DEGTORAD) )
call SetUnitY(.m[i],y1+.d[i]*Sin((facing + .a[i])*bj_DEGTORAD) )
call SetUnitFlyHeight(.m[i],GetUnitFlyHeight(.ms)+.f[i],0.00)
else
set .m[i]= null
endif
set i = i + 1
endloop
endmethod
//=================================================
method LinkMod takes unit m returns nothing
local integer i = 0
loop
exitwhen i > MODALLOWED
if .m[i] == null then
set .m[i] = m
set .countmod = .countmod + 1
call SetUnitPathing(m,false)
return
endif
set i = i + 1
endloop
endmethod
//=================================================
method AddXp takes integer n returns nothing
call AddHeroXP(.ms,n,true)
endmethod
//=================================================
method CancelMod takes unit mod returns nothing
local integer i = 0
loop
exitwhen i > MsModWithSpellMax
if GetUnitTypeId(mod)==MsModWithSpellId[i] then
call UnitRemoveAbility(.ms, MsModSpellId[i])
endif
set i = i + 1
endloop
call RemoveUnit(mod)
set .countmod = .countmod - 1
endmethod
//=================================================
method CountCargoMod takes nothing returns integer
local integer i = 0
local integer n = 0
loop
exitwhen i > MODALLOWED
if GetUnitState(.m[i], UNIT_STATE_LIFE) > 0 then
if GetUnitTypeId(.m[i])==CARGO1 then
set n = n + 1
elseif GetUnitTypeId(.m[i])==CARGO2 then
set n = n + 2
elseif GetUnitTypeId(.m[i])==CARGO3 then
set n = n + 3
endif
endif
set i = i + 1
endloop
return n
endmethod
//=================================================
method IsMod takes unit mod returns boolean
local integer i = 0
loop
exitwhen i > MODALLOWED
return mod == .m[i]
set i = i + 1
endloop
return false
endmethod
//=================================================
method SetMs takes unit ms returns nothing
set .ms = ms
call .SetMods()
endmethod
//=================================================
method GetMs takes nothing returns unit
return .ms
endmethod
//=================================================
method CountLivingMod takes nothing returns integer
return .countmod
endmethod
//=================================================
method ChangeMod takes unit modbase, unit modnew returns nothing
local integer i = 0
local integer j = 0
local integer id = GetUnitTypeId(modnew)
set i = 0
loop
exitwhen i > MODALLOWED
if modbase == .m[i] then
set .m[i]=modnew
endif
set i = i + 1
endloop
call RemoveUnit(modbase)
set i = 0
loop
exitwhen i > MsModWithSpellMax
if id==MsModWithSpellId[i] then
call UnitAddAbility(.ms, MsModSpellId[i])
endif
set i = i + 1
endloop
call SetUnitPathing(modnew,false)
endmethod
//=================================================
method Upgrade takes nothing returns nothing
local real x = GetUnitX(.ms)
local real y = GetUnitY(.ms)
local real a = GetUnitFacing(.ms)
local integer i = 0
local integer j = 0
loop
exitwhen i > MsMainMax
if GetUnitTypeId(.ms)== MsMainId[i] then
set j = 0
loop
exitwhen j > 15
if GetUnitAbilityLevel(.ms,MsModSpellId[j])>=1 then
set .spell[j]=MsModSpellId[j]
else
set .spell[j]=0
endif
set j = j + 1
endloop
call RemoveUnit(.ms)
set .ms = CreateUnit(.pl,MsMainId[i+4],x,y,a)
set j = 0
loop
exitwhen j > 15
if .spell[j]!= 0 then
call UnitAddAbility(.ms,.spell[j])
endif
set j = j + 1
endloop
call .SetMods()
return
endif
set i = i + 1
endloop
endmethod
//=================================================
method SetMods takes nothing returns nothing
local integer i = 0
local integer j = 0
loop
exitwhen i > MsMainMax
if GetUnitTypeId40;.ms) == MsMainId[i] then
set j = 0
loop
exitwhen j > 8
set .a[j] = ModAngle[i][j]
set j = j + 1
endloop
set j = 0
loop
exitwhen j > 8
set .d[j] = ModDistance[i][j]
set j = j + 1
endloop
set j = 0
loop
exitwhen j > 8
set .f[j] = ModHeight[i][j]
set j = j + 1
endloop
endif
set i = i + 1
endloop
if .ti == null then
set .ti = NewTimer40;)
call SetTimerData40; .ti, this )
call TimerStart40; .ti, TIMEOUT, true, function BoucleUpdate )
endif
endmethod
//=================================================
method Release takes nothing returns nothing
local integer i = 0
call ReleaseTimer40;.ti)
loop
exitwhen i > MODALLOWED - 1
call KillUnit40;.m[i])
if GetUnitTypeId40;.m[i])=='H02G' then //Base module
call RemoveUnit40;.m[i])
endif
set .m[i] = null
set i = i + 1
endloop
set .ti = null
set .ms = null
set .pl = null
call .destroy40;)
endmethod
//=================================================
//Constructor
static method create takes player pl returns s_MsSys
local s_MsSys this = s_MsSys.allocate40;)
set this.pl = pl
return this
endmethod
//=================================================
endstruct
//=================================================
private function i2struct takes integer i returns s_MsSys
return i
endfunction
//=================================================
function MsSys takes player pl returns s_MsSys
if( pl==null )then
return 0
endif
if( not TABLE.exists(pl) )then
set TABLE[pl] = s_MsSys.create(pl)
endif
return i2struct(TABLE[pl])
endfunction
endlibrary
Choix du Mothership en début de partie: règle les unités autorisées (selon la voie de développement choisie, on ne peut pas accéder à tout)
Secret:
Jass:
scope mscrea initializer init
//=================================================
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 whichUnit returns nothing
local integer whichPlayerId = GetPlayerId(whichPlayer)
local real x = GetUnitX(whichUnit)
local real y = GetUnitY(whichUnit)
local unit dummy = null
call RemoveUnit(FirstShip[whichPlayerId])
call SetPlayerTechResearched(whichPlayer, HasShut, 1 )
//Give it the instant colo ability
call UnitAddAbility(whichUnit,'A007')
//Create the dummy with start buffs
set dummy= CreateUnit(whichPlayer,'o00L',x,y,0.)
call UnitApplyTimedLife(dummy,'BTLF',5.)
call IssueTargetOrder(dummy,"innerfire", whichUnit)
call IssueTargetOrder(dummy,"bloodlust", whichUnit)
call IssueImmediateOrder(whichUnit,"divineshield")
//Selet the MS
if whichPlayer == GetLocalPlayer() then
call ClearSelection()
call SelectUnit(whichUnit,true)
endif
//Initialize the Ms system
call MsSys(whichPlayer).SetMs(whichUnit)
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,MsMainId[0],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,MsMainId[1],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,MsMainId[2],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,MsMainId[3],x,y,0.)
call DisableMerMods(owner)
call DisableMilMods(owner)
call DisablePirMods(owner)
call IniMs(owner,mothership)
set mothership = null
set owner = null
endfunction
//=================================================
public function init takes nothing returns nothing
call RegisterSpellFinishResponse(PICKMSMER,MsMer)
call RegisterSpellFinishResponse(PICKMSMIL,MsMil)
call RegisterSpellFinishResponse(PICKMSPIR,MsPir)
call RegisterSpellFinishResponse(PICKMSPOL,MsPol)
endfunction
//=================================================
endscope
Upgrade du Mothership: fonctionne quand le joueur termine une recherche sur le dock
Secret:
Jass:
scope msupgrade initializer init
//=================================================
private function Conditions 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 MsSys(owner).Upgrade()
return false
elseif GetResearched() == UpToCruiz then
call SetPlayerTechResearched(owner, HasCruiz, 1)
call DisplayTextToPlayer(owner,0.,0.,"Mothership upgraded to cruiser")
call MsSys(owner).Upgrade()
return false
endif
set owner = null
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_RESEARCH_FINISH )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
//=================================================
endscope
Ajout du module Dummy qui ne sert qu'à être upgradé en une série de modules.
Secret:
Jass:
scope msaddmodbase initializer init
//=================================================
globals
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
endglobals
//=================================================
private function IsUnitMsShut takes unit u returns boolean
return GetUnitTypeId(u) == MsMainId[1] or GetUnitTypeId(u) == MsMainId[2] or GetUnitTypeId(u) == MsMainId[3] or GetUnitTypeId(u) == MsMainId[4]
endfunction
//=================================================
private function IsUnitMsFrig takes unit u returns boolean
return GetUnitTypeId(u) == MsMainId[5] or GetUnitTypeId(u) == MsMainId[6] or GetUnitTypeId(u) == MsMainId[7] or GetUnitTypeId(u) == MsMainId[8]
endfunction
//=================================================
private function IsUnitMsCruiz takes unit u returns boolean
return GetUnitTypeId(u) == MsMainId[9] or GetUnitTypeId(u) == MsMainId[10] or GetUnitTypeId(u) == MsMainId[11] or GetUnitTypeId(u) == MsMainId[12]
endfunction
//=================================================
private function Conditions takes nothing returns boolean
local unit dock = GetTriggerUnit()
local unit mod = GetTrainedUnit()
local player owner = GetOwningPlayer(mod)
local unit ms = MsSys(owner).GetMs()
local real x1 = GetUnitX(ms)
local real y1 = GetUnitY(ms)
local real x2 = GetUnitX(dock)
local real y2 = GetUnitY(dock)
local real distance = SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
if GetUnitTypeId(mod)==MST0 then
if IsUnitMsShut(ms) == true then
if MsSys(owner).CountLivingMod() <= MAXMODSHUT and distance<= RANGE then
call MsSys(owner).LinkMod(mod)
call DisplayTextToPlayer( owner, 0, 0, C4+I2S(MAXMODSHUT-MsSys(owner).CountLivingMod()) )
elseif MsSys(owner).CountLivingMod() > MAXMODSHUT then
call ErrorSound(owner)
call DisplayTextToPlayer( owner, 0, 0, C1 )
call RemoveUnit(mod)
elseif distance > RANGE then
call ErrorSound(owner)
call DisplayTextToPlayer( owner, 0, 0, C2+I2S(R2I(RANGE))+C3+I2S(R2I(distance)) )
call RemoveUnit(mod)
endif
elseif IsUnitMsFrig(ms) == true then
if MsSys(owner).CountLivingMod() <= MAXMODFRIG and distance<= RANGE then
call MsSys(owner).LinkMod(mod)
call DisplayTextToPlayer( owner, 0, 0, C4+I2S(MAXMODFRIG-MsSys(owner).CountLivingMod()) )
elseif MsSys(owner).CountLivingMod() > MAXMODFRIG then
call ErrorSound(owner)
call DisplayTextToPlayer( owner, 0, 0, C1 )
call RemoveUnit(mod)
elseif distance > RANGE then
call ErrorSound(owner)
call DisplayTextToPlayer( owner, 0, 0, C2+I2S(R2I(RANGE))+C3+I2S(R2I(distance)) )
call RemoveUnit(mod)
endif
elseif IsUnitMsCruiz(ms) == true then
if MsSys(owner).CountLivingMod() <= MAXMODCRUIZ and distance<= RANGE then
call MsSys(owner).LinkMod(mod)
call DisplayTextToPlayer( owner, 0, 0, C4+I2S(MAXMODCRUIZ-MsSys(owner).CountLivingMod()) )
elseif MsSys(owner).CountLivingMod() > MAXMODCRUIZ then
call ErrorSound(owner)
call DisplayTextToPlayer( owner, 0, 0, C1 )
call RemoveUnit(mod)
elseif distance > RANGE then
call ErrorSound(owner)
call DisplayTextToPlayer( owner, 0, 0, C2+I2S(R2I(RANGE))+C3+I2S(R2I(distance)) )
call RemoveUnit(mod)
endif
endif
endif
set dock = null
set ms = null
set owner = null
set mod = null
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
//=================================================
endscope
Upgrade d'un module dummy en module
Secret:
Jass:
scope msaddmod initializer init
//=================================================
private function Conditions takes nothing returns boolean
if GetUnitAbilityLevel(GetTriggerUnit(),ISMSMOD)>=1 then
call MsSys(GetOwningPlayer(GetTriggerUnit())).ChangeMod(GetTriggerUnit(),GetTrainedUnit())
endif
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
//=================================================
endscope
Mort d'un module
Secret:
Jass:
scope moddeath initializer init
//=================================================
private function Conditions takes nothing returns boolean
if GetUnitAbilityLevel(GetTriggerUnit(),ISMSMOD)>=1 then
call MsSys(GetOwningPlayer(GetTriggerUnit()) ).CancelMod(GetTriggerUnit() )
endif
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
endscope
Comme les Motherships peuvent être ressucités, je n'ai pas prévu d'annulation des timers etc (ce sont des héros) _________________
Après, si tu es toujours d'accord, on parlera des "détails".
Mais si tu teste la carte en solo, tu devrais mieux comprendre, je pense.
En général mon problème c'est qu'alors que j'utilise des sytèmes MUI, il y a parfois des bugs en multijoueur que je ne détecte pas en solo. _________________
Inscrit le: 23 Aoû 2007 Messages: 7146 Sujets: 147 Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance Médailles: 2 (En savoir plus...)
Posté le: 20/01/10 23:06 Sujet du message:
En fait mon objectif est t'apprendre le plus de choses possible, le but ultime est que tu puisses faire tout ce que je fait.
Et donc normalement tu n'aurais plus besoin de moi. _________________
Comme tu l'as peut-être constaté, je suis capable de créer pas mal de trucs (enfin je crois, sans fausse modestie/vantardise, que l'idée des Motherships et du Trade, c'est pas mal non?)
Effectivement ensuite, mes manières pour y arriver sont bizarres car mes connaissances très lacunaires.
J'ai créé un sujet par système, vu que là, sinon , c'est ingérable.
Je ne demande pas de faire du debug (non pas que je le refuserais, mais après tout, c'est la partie la plus chiante, et le rôle du créateur de la carte), bien sûr, ni même de faire des tests etc (tu as sûrement autre chose à faire) mais de regarder à quoi les déclencheurs ressemblent et de les critiquer, ou mieux, si tu vois, pour parvenir aux mêmes résultats, des méthodes plus simples. _________________
Inscrit le: 23 Aoû 2007 Messages: 7146 Sujets: 147 Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance Médailles: 2 (En savoir plus...)
Posté le: 22/01/10 21:52 Sujet du message:
Je te l'ai déjà dit, mais pas assez clairement je crois.
C'est très bien de fragmenter ton code, mais tu le fais beaucoup trop, 1 système = 1 library, et surtout pas de scopes wtf ...
Ça ouvre la porte aux bugs, et rend ton code difficilement lisible et donc débuggable.
L'utilité des scopes est discutable, mais bon en gros ne les utilise surtout pas pour des systèmes mais pour des choses n'ayant pas d'autres utilités qu'eux mêmes, ne doivent pas être réutilisés, du jor un spell.
J'apprécie les scopes juste parce que ca m'évite de gérer les requires quand ce n'est pas nécessaire, mais du point de vue programmation ce n'est pas sain.
N'hésite pas à commenter tes codes aussi, ca ne rendra que plus facile la maintenance ultérieure de ton code quand tu ne te rappèleras plus du pourquoi du comment t'as pondu la ligne 1337. _________________
Je trouvais cela plus lisible que d'avoir des énormes libraries (genre pour les motherships: ça rend la page de code énorme, hors le JNPG ne gère pas bien les grosses pages de codes, l'affichage est tout petit :' _________________
J'apprécie les scopes juste parce que ca m'évite de gérer les requires quand ce n'est pas nécessaire, mais du point de vue programmation ce n'est pas sain.
Mouai, ça c'est Vex qui le dit :p
Dans plein de langages il y a des équivalents qui sont très utiles voir indispensables (namespace en C++ par exemple)
M'enfin quoi qu'il en soit (c'est marrant parce qu'on a dû le dire en même temps dans des posts différents), 1 système = 1 lib _________________
Bêta Systems:70% Bêta Spells:13% Bêta Arts & graphics:70%
Toutes les heures sont au format GMT + 1 Heure Aller à la page 1, 2Suivante
Page 1 sur 2 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