- Joined
- Jul 10, 2007
- Messages
- 6,306
This prevents players from controlling units by switching unit control when that player selects that unit. The problem with switching unit control is that the unit is automatically deselected, which can cause some issues.
Whether the unit is selected or not is stored locally for each player
From here, the unit ownership changes and the unit is selected again.
My question is does anyone know if this code will desync or not? It's very iffy because of select events. My thoughts are that it would only desync if a trigger was run that had desyncing code in it ; ). Considering that the only triggers in this specific map that have select/deselect events in them are disabled during this, I'm not sure. The events might still go through some sort of call stack (although it would be empty), thus causing a weird memory issue.
Anyways, yaar ^)^.
This is part of an advanced queue for massing units. When a player has a large number of units sent in a game like Tower Wars or Hero Wars, they can't build their own buildings. To counter this, the sends are spread throughout the team and a computer player. When a player selects a unit that they control that they shouldn't be able to control, the unit is then changed over to the computer player so that the player can't control the unit. When the player deselects the unit, that player gets control of the unit.
Giving/Taking away control isn't a very elegant solution to preventing players from having control over certain units, but it's the only one I could come up with. If the players had no control over any units (plain observers), they could have their move/attack abilities disabled, but they'd still be able to stop the unit, which is no good.
Whether the unit is selected or not is stored locally for each player
set selected = IsUnitSelected(u, GetLocalPlayer())
From here, the unit ownership changes and the unit is selected again.
JASS:
if (selected) then
call SelectUnit(u, true)
endif
My question is does anyone know if this code will desync or not? It's very iffy because of select events. My thoughts are that it would only desync if a trigger was run that had desyncing code in it ; ). Considering that the only triggers in this specific map that have select/deselect events in them are disabled during this, I'm not sure. The events might still go through some sort of call stack (although it would be empty), thus causing a weird memory issue.
Anyways, yaar ^)^.
This is part of an advanced queue for massing units. When a player has a large number of units sent in a game like Tower Wars or Hero Wars, they can't build their own buildings. To counter this, the sends are spread throughout the team and a computer player. When a player selects a unit that they control that they shouldn't be able to control, the unit is then changed over to the computer player so that the player can't control the unit. When the player deselects the unit, that player gets control of the unit.
Giving/Taking away control isn't a very elegant solution to preventing players from having control over certain units, but it's the only one I could come up with. If the players had no control over any units (plain observers), they could have their move/attack abilities disabled, but they'd still be able to stop the unit, which is no good.
JASS:
struct PreventSelect extends array
private static trigger selectt
private static trigger deselectt
private static method select takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer i = GetUnitUserData(u)
local boolean selected
if (isSend[i] and GetTriggerPlayer() == GetOwningPlayer(u)) then
call DisableTrigger(deselectt)
call DisableTrigger(selectt)
set selected = IsUnitSelected(u, GetLocalPlayer())
call SetUnitOwner(u, deferPlayer[GetPlayerId(GetTriggerPlayer())], false)
call IssuePointOrder(u, "move", unitMoveX[i], unitMoveY[i])
if (selected) then
call SelectUnit(u, true)
endif
call EnableTrigger(selectt)
call EnableTrigger(deselectt)
endif
set u = null
return false
endmethod
private static method deselect takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer i = GetUnitUserData(u)
local boolean selected
if (isSend[i] and GetTriggerPlayer() == unitOwner[i]) then
call DisableTrigger(deselectt)
call DisableTrigger(selectt)
set selected = IsUnitSelected(u, GetLocalPlayer()) and GetLocalPlayer() != GetTriggerPlayer()
call SetUnitOwner(u, GetTriggerPlayer(), false)
call IssuePointOrder(u, "move", unitMoveX[i], unitMoveY[i])
if (selected) then
call SelectUnit(u, true)
endif
call EnableTrigger(selectt)
call EnableTrigger(deselectt)
endif
set u = null
return false
endmethod
private static method onInit takes nothing returns nothing
local integer i = 9
set selectt = CreateTrigger()
set deselectt = CreateTrigger()
call TriggerAddCondition(selectt, Condition(function thistype.select))
call TriggerAddCondition(deselectt, Condition(function thistype.deselect))
loop
call TriggerRegisterPlayerUnitEvent(selectt, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(deselectt, Player(i), EVENT_PLAYER_UNIT_DESELECTED, null)
exitwhen 0 == i
set i = i - 1
endloop
endmethod
endstruct