- Joined
- Jul 10, 2007
- Messages
- 6,306
Got way too much stuff D:
reply to thread with things you want to clean up and I'll pm the code =)
IsPlayerActive(playerId) instead of IsPlaying(player)
no shorthanding allowed like pid, no weird things like displayd or enableda, and no weird spacing like 1+3*4
1+3*4 -> 1 + 3*4
u is acceptable for a method that deals with 1 and only 1 unit and would have a variable name nearly identical to the method name for that unit
example:
Command Income (this one's totally messed up, haha)
Chatroom
ChatroomAll
ChatroomAllies
ChatroomObservers
ChatroomAdmin
Gameboard (cleaned this one up quite a bit, but it still needs cleaning)
Income
Rounds
Start Income
Prevent Command
Share Bounty
Apply Income
Unit Income
Transfer On Leave
Shrine Upgrade
Shrine
SendPlayer
Summon
Path
Add Income
Unit Team
Paths
Summoning Trail
Plans
Thanks
Before
After
reply to thread with things you want to clean up and I'll pm the code =)
IsPlayerActive(playerId) instead of IsPlaying(player)
no shorthanding allowed like pid, no weird things like displayd or enableda, and no weird spacing like 1+3*4
1+3*4 -> 1 + 3*4
u is acceptable for a method that deals with 1 and only 1 unit and would have a variable name nearly identical to the method name for that unit
example:
JASS:
method onDeindex takes nothing returns nothing
local unit deindexedUnit = GetIndexedUnit() //u is acceptable here, but frowned upon : p
endmethod
Command Income (this one's totally messed up, haha)
Chatroom
ChatroomAll
ChatroomAllies
ChatroomObservers
ChatroomAdmin
Gameboard (cleaned this one up quite a bit, but it still needs cleaning)
Income
Rounds
Start Income
Prevent Command
Share Bounty
Apply Income
Unit Income
Transfer On Leave
Shrine Upgrade
Shrine
SendPlayer
Summon
Path
Add Income
Unit Team
Paths
Summoning Trail
Plans
Thanks
Before
JASS:
library Towers uses Bonus, UnitIndexer, Game
struct Towers extends array
private static integer array next
private static integer array prev
private static boolean array a
static method operator [] takes integer pid returns thistype
return next[pid/3]
endmethod
method operator n takes nothing returns thistype
return next[this]
endmethod
private static method index takes nothing returns boolean
local integer i
local integer u
if (GetUnitRace(GetIndexedUnit()) == RACE_UNDEAD and IsUnitType(GetIndexedUnit(), UNIT_TYPE_STRUCTURE) and not Race(GetUnitTypeId(GetIndexedUnit())).exists and not RaceTech(GetUnitTypeId(GetIndexedUnit())).exists and not AdvRaceTech(GetUnitTypeId(GetIndexedUnit())).exists) then
set i = GetPlayerId(GetOwningPlayer(GetIndexedUnit()))/3
set u = GetIndexedUnitId()+1
if (0 == next[i]) then
set next[i] = u
set next[u] = 0
set prev[u] = 0
else
set next[u] = next[i]
set prev[u] = 0
set prev[next[u]] = u
set next[i] = u
endif
set a[u] = true
endif
return false
endmethod
private static method deindex takes nothing returns boolean
local integer i
local integer u
local unit m
if (0 == GetIndexedUnitId()) then
set m = GetTriggerUnit()
else
set m = GetIndexedUnit()
endif
if (GetUnitRace(m) == RACE_UNDEAD and IsUnitType(m, UNIT_TYPE_STRUCTURE) and not Race(GetUnitTypeId(m)).exists and not RaceTech(GetUnitTypeId(m)).exists and not AdvRaceTech(GetUnitTypeId(m)).exists) then
if (0 == GetIndexedUnitId()) then
set i = GetPlayerId(GetTriggerPlayer())/3
set u = GetUnitUserData(m)+1
else
set i = GetPlayerId(GetOwningPlayer(GetIndexedUnit()))/3
set u = GetIndexedUnitId()+1
endif
if (a[u]) then
if (0 == prev[u]) then
set next[i] = next[u]
else
set next[prev[u]] = next[u]
endif
if (0 != next[u]) then
set prev[next[u]] = prev[u]
endif
set a[u] = false
endif
endif
set m = null
return false
endmethod
private static method init takes nothing returns boolean
call RegisterUnitIndexEvent(Condition(function thistype.index), UnitIndexer.INDEX)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, Condition(function thistype.deindex))
call RegisterUnitIndexEvent(Condition(function thistype.deindex), UnitIndexer.DEINDEX)
return false
endmethod
private static method onInit takes nothing returns nothing
call Game.onInitialize.register(Condition(function thistype.init))
call Game.onInitializeSolo.register(Condition(function thistype.init))
endmethod
endstruct
endlibrary
After
JASS:
module LinkedList
readonly thistype next
readonly thistype prev
method add takes thistype node returns nothing
set node.prev = prev
set node.next = this
set prev.next = node
set prev = node
endmethod
method remove takes nothing returns nothing
set prev.next = next
set next.prev = prev
endmethod
static method init takes thistype head returns nothing
set head.next = head
set head.prev = head
endmethod
endmodule
JASS:
library Towers uses UnitIndexer, Game
function IsTower takes unit whichUnit returns boolean
return GetUnitRace(whichUnit) == RACE_UNDEAD and IsUnitType(whichUnit, UNIT_TYPE_STRUCTURE) and not Race(GetUnitTypeId(whichUnit)).exists and not RaceTech(GetUnitTypeId(whichUnit)).exists and not AdvRaceTech(GetUnitTypeId(whichUnit)).exists
endfunction
/*
* Each player gets a list of towers
*
* Lists go from 0 to 6
*/
struct Towers extends array
implement LinkedList
private boolean added
private static method onIndex takes nothing returns boolean
local thistype playerId
local thistype node
/*
* Make sure that deindexed unit is a tower
*/
if (IsTower(GetIndexedUnit())) then
set playerId = GetPlayerId(GetOwningPlayer(GetIndexedUnit()))
set node = GetIndexedUnitId() + 5
call playerId.add(node)
set node.added = true
endif
return false
endmethod
private static method onDeindex takes nothing returns boolean
local thistype node
local unit u
if (0 == GetIndexedUnitId()) then
set u = GetTriggerUnit()
else
set u = GetIndexedUnit()
endif
if (IsTower(u)) then
set node = GetUnitUserData(u) + 5
if (node.added) then
call node.remove()
set node.added = false
endif
endif
set u = null
return false
endmethod
private static method onInit takes nothing returns nothing
local integer list = 5
loop
call init(list)
exitwhen 0 == list
set list = list - 1
endloop
call RegisterUnitIndexEvent(Condition(function thistype.onIndex), UnitIndexer.INDEX)
call RegisterUnitIndexEvent(Condition(function thistype.onDeindex), UnitIndexer.DEINDEX)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function thistype.onDeindex)
endmethod
endstruct
endlibrary
Last edited: