- Joined
- Nov 30, 2007
- Messages
- 1,202
Hello, I need some suggestions on which way would be the best way to record which resource a unit is carrying to base. Every turn the farms produce a resource which has to be delivered to the nearby town. The problem I'm facing is that there will be different resources and I need a good way to detect which and how many (perhaps) it's carrying.
Option 1: The Caravan Unit is given one or more items representing the resource. Perhaps too many calls, with adding/removing items e.t.c. ?
Pro: Can carry multiple resources.
Con: Items...?
Option 2: A temporary pool of caravan units that are collapsed once the caravan reaches it's destination (might be too system heavy, since there will be many caravans?)
Con: Might be too many loops if you have alot of units on the map?
Pro: Very flexible.
Option 3: The custom value of the unit represents the resource and you can only send the same amount of that specific resource.
Con: Not flexible at all.
Pro: Simple.
Option 4: I add add a buff to the unit representing the cargo carried.
Pro: Nice visual effect. Can have different amount in the cargo.
Con: Can only carry one resource type.
The option seem to me, is it worth cutting down the numbers of caravans running around but having to make some kind of pool system?
Option 5: ???
There is something wrong with the index I belive.
This trigger is for when the destination is reached.
This trigger is for moving stopped Caravans:
So, how would you do it?
*Edit also I'm not sure how to check if it can reach it's destination, perhaps there is such a sytem already.
Option 1: The Caravan Unit is given one or more items representing the resource. Perhaps too many calls, with adding/removing items e.t.c. ?
Pro: Can carry multiple resources.
Con: Items...?
Option 2: A temporary pool of caravan units that are collapsed once the caravan reaches it's destination (might be too system heavy, since there will be many caravans?)
Con: Might be too many loops if you have alot of units on the map?
Pro: Very flexible.
Option 3: The custom value of the unit represents the resource and you can only send the same amount of that specific resource.
Con: Not flexible at all.
Pro: Simple.
Option 4: I add add a buff to the unit representing the cargo carried.
Pro: Nice visual effect. Can have different amount in the cargo.
Con: Can only carry one resource type.
The option seem to me, is it worth cutting down the numbers of caravans running around but having to make some kind of pool system?
Option 5: ???
There is something wrong with the index I belive.
-
Setup
-
Events
- Map initialization
- Conditions
-
Actions
- Custom script: set udg_LocalPlayer = GetLocalPlayer()
- Player Group - Add Player 1 (Red) to Team_hum
- -------- Town 1 --------
- Set Town[0] = Town Hall 0000 <gen>
- -------- Town 2 --------
- Set Town[1] = Town Hall 0002 <gen>
-
For each (Integer A) from 0 to 1, do (Actions)
-
Loop - Actions
- Set Town_alive[(Integer A)] = True
- Unit - Set the custom value of Town[(Integer A)] to (Integer A)
-
Loop - Actions
- -------- Pre Placed Farms --------
- Unit Group - Add Farm 0006 <gen> to Resource_food_g
- Unit Group - Add Farm 0007 <gen> to Resource_food_g
- Unit - Set the custom value of Farm 0007 <gen> to 1
-
Events
JASS:
function Spawn_Farm_Caravan takes nothing returns nothing
local player p = GetOwningPlayer(GetEnumUnit())
local integer T_array = GetUnitUserData(GetEnumUnit())
local real x = GetLocationX(GetUnitLoc(GetEnumUnit()))
local real y = GetLocationY(GetUnitLoc(GetEnumUnit()))
local item i
local unit u
if (udg_Town_alive[T_array] == true) then
if (IsPlayerInForce(p, udg_Team_hum) == true) then
set u = CreateUnit(p, 'hrdh', x,y, 00)
else
set u = CreateUnit(p, 'oosc', x,y, 00)
endif
// Add unit to Caravan Index
call GroupAddUnitSimple( u, udg_Caravan_group)
set udg_Caravan_index_max = udg_Caravan_index_max + 1
set udg_Caravan[udg_Caravan_index_max] = u
set udg_Caravan_destination[udg_Caravan_index_max] = udg_Town[T_array]
call SetUnitUserData(u, udg_Caravan_index_max)
call IssueTargetOrderBJ(u, "cripple", udg_Town[T_array])
set i = CreateItem('ratc',x,y)
call SetItemCharges(i, 5)
call UnitAddItemSwapped(i,u)
// Debug
call SetUnitManaBJ(u, I2R(GetUnitUserData(u)) )
set i = null
set u = null
set p = null
endif
endfunction
function Trig_Turn_Actions takes nothing returns nothing
call ForGroupBJ(udg_Resource_food_g, function Spawn_Farm_Caravan)
endfunction
//===========================================================================
function InitTrig_Turn takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(t, 10.00)
call TriggerAddAction(t, function Trig_Turn_Actions)
set t = null
This trigger is for when the destination is reached.
JASS:
function CheckForCaravan takes nothing returns boolean
if (GetSpellAbilityId() == 'A000') then
return true
endif
endfunction
function Trig_Town_Pickup_Actions takes nothing returns nothing
local integer i
local unit u = GetTriggerUnit()
if (GetItemTypeId(UnitItemInSlotBJ(u, 1)) == 'ratc') then
set i = GetItemCharges(UnitItemInSlotBJ(u, 1))
call DisplayTextToForce(GetPlayersAll(), ("Food carried: " + I2S(i)))
endif
call RemoveUnit(u)
//Refresh Caravan Index
set i = GetUnitUserData(u)
loop
exitwhen i == udg_Caravan_index_max
set udg_Caravan[i] = udg_Caravan[i + 1]
set udg_Caravan_destination[i] = udg_Caravan_destination[i + 1]
call SetUnitUserData(udg_Caravan[i], GetUnitUserData(udg_Caravan[i + 1]))
call SetUnitManaBJ(udg_Caravan[i], I2R(GetUnitUserData(udg_Caravan[i])) ) //Debug
endloop
set udg_Caravan[udg_Caravan_index_max] = null
set udg_Caravan_destination[udg_Caravan_index_max] = null
set udg_Caravan_index_max = udg_Caravan_index_max - 1
call GroupRemoveUnitSimple(u, udg_Caravan_group)
// Debug
call DisplayTextToForce( GetPlayersAll(), ("Caravan Index Max =" + I2S(udg_Caravan_index_max) ) )
call DisplayTextToForce( GetPlayersAll(), ("Units In Caravan Group = " + I2S(CountUnitsInGroup(udg_Caravan_group)) ) )
call SetUnitManaBJ(u, I2R(GetUnitUserData(u)) )
set u = null
endfunction
//===========================================================================
function InitTrig_Town_Pickup takes nothing returns nothing
local trigger t = CreateTrigger()
set gg_trg_Town_Pickup = t
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_FINISH )
call TriggerAddCondition(t, Condition(function CheckForCaravan))
call TriggerAddAction(t, function Trig_Town_Pickup_Actions)
set t = null
endfunction
This trigger is for moving stopped Caravans:
-
Caravan Stopped
-
Events
- Time - Every 5.00 seconds of game time
-
Conditions
- (Number of units in Caravan_group) Greater than 0
-
Actions
-
Unit Group - Pick every unit in Caravan_group and do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Current order of (Picked unit)) Equal to (Order(hold position))
-
Then - Actions
- Unit - Order (Picked unit) to Undead Necromancer - Cripple Caravan_destination[(Custom value of (Picked unit))]
- Else - Actions
-
If - Conditions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
Loop - Actions
-
Unit Group - Pick every unit in Caravan_group and do (Actions)
-
Events
*Edit also I'm not sure how to check if it can reach it's destination, perhaps there is such a sytem already.
Last edited: