// ----- BLACKMASK AND CINEMATIC CODE -----
function MaskTimer takes nothing returns nothing
if bj_cineFadeContinueTimer!=null then
call DestroyTimer(bj_cineFadeContinueTimer)
endif
if bj_cineFadeFinishTimer!=null then
call DestroyTimer(bj_cineFadeFinishTimer)
endif
endfunction
function MaskStart takes nothing returns nothing
call ShowInterface(false,.25)
call EnableUserUI(false)
call SetCineFilterTexture("ReplaceableTextures\\CameraMasks\\Black_mask.blp")
call SetCineFilterBlendMode(BLEND_MODE_BLEND)
call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
call SetCineFilterStartUV(0,0,1,1)
call SetCineFilterEndUV(0,0,1,1)
call SetCineFilterStartColor(0,0,0,0)
call SetCineFilterEndColor(0,0,0,255)
call SetCineFilterDuration(.25)
call DisplayCineFilter(true)
endfunction
function MaskFade takes nothing returns nothing
local timer T=GetExpiredTimer()
call DestroyTimer(T)
set T=null
call DisplayCineFilter(false)
call EnableUserUI(true)
endfunction
function MaskEnd takes nothing returns nothing
local timer T=CreateTimer()
call ShowInterface(true,2)
call SetCineFilterStartColor(0,0,0,255)
call SetCineFilterEndColor(0,0,0,0)
call SetCineFilterDuration(2)
call TimerStart(T,2,false,function MaskFade)
set T=null
endfunction
// ----- MINIMAP CODE -----
function ResetMap takes nothing returns nothing
local fogmodifier Fog=CreateFogModifierRect(GetLocalPlayer(),FOG_OF_WAR_VISIBLE,gg_rct_World,false,false)
call FogModifierStart(Fog)
call TriggerSleepAction(.25)
call FogModifierStop(Fog)
call DestroyFogModifier(Fog)
set Fog=null
set Fog=CreateFogModifierRect(GetLocalPlayer(),FOG_OF_WAR_MASKED,gg_rct_World,false,false)
call FogModifierStart(Fog)
call TriggerSleepAction(.25)
call FogModifierStop(Fog)
call DestroyFogModifier(Fog)
set Fog=null
endfunction
function ResetMapForPlayer takes player P returns nothing
local fogmodifier Fog=CreateFogModifierRect(P,FOG_OF_WAR_VISIBLE,gg_rct_World,false,false)
call FogModifierStart(Fog)
call TriggerSleepAction(.25)
call FogModifierStop(Fog)
call DestroyFogModifier(Fog)
set Fog=null
set Fog=CreateFogModifierRect(P,FOG_OF_WAR_MASKED,gg_rct_World,false,false)
call FogModifierStart(Fog)
call TriggerSleepAction(.25)
call FogModifierStop(Fog)
call DestroyFogModifier(Fog)
set Fog=null
endfunction
function LastMinute takes nothing returns nothing
call FogEnable(false)
call FogMaskEnable(false)
endfunction
// ----- ENUMERATION UTILITY FUNCTIONS -----
function RemoveUnitEnum takes nothing returns nothing
local unit U=GetEnumUnit()
call RemoveUnit(U)
set U=null
endfunction
function ClearTreesEnum takes nothing returns nothing
local destructable D=GetEnumDestructable()
call RemoveDestructable(D)
set D=null
endfunction
function ClearTrees takes rect R returns nothing
call EnumDestructablesInRect(R,null,function ClearTreesEnum)
set R=null
endfunction
// ----- PATHING CODE -----
function IsPathableEnum takes nothing returns boolean
local unit u=GetFilterUnit()
local boolean b=not(IsUnitType(u,UNIT_TYPE_STRUCTURE))
set u=null
if b then
set bj_groupCountUnits=bj_groupCountUnits+1
endif
return b
endfunction
function IsPathable takes real x,real y,integer id returns boolean
local item I=CreateItem(id,x,y)
local boolean B=false
local group g=CreateGroup()
local boolexpr filter=Condition(function IsPathableEnum)
set bj_groupCountUnits=0
call GroupEnumUnitsInRange(g,x,y,24,filter)
call DestroyBoolExpr(filter)
set filter=null
if (((GetItemX(I)-x)*(GetItemX(I)-x)+(GetItemY(I)-y)*(GetItemY(I)-y))<=256)and bj_groupCountUnits==0then
set B=true
endif
call DestroyGroup(g)
set g=null
call RemoveItem(I)
set I=null
return B
endfunction
// ----- TREE CODE -----
function CreateTree takes real X,real Y returns nothing
local real xx
local real yy
local real angle
local boolean End=false
local integer loops=100
loop
exitwhen loops<=0
set angle=GetRandomReal(0,360)
set xx=X+256*Cos(bj_DEGTORAD*angle)
set yy=Y+256*Sin(bj_DEGTORAD*angle)
set End=IsPathable(xx,yy,'I000')
if End then
call CreateDestructable('B00B',xx,yy,270,GetRandomReal(.8,1.2),0)
call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\NightElf\\EntBirthTarget\\EntBirthTarget.mdl",xx,yy))
set loops=0
else
set loops=loops-1
endif
endloop
endfunction
Name | Type | is_array | initial_value |
BlightHuman | terraintype | No | |
BlightZombie | terraintype | No | |
Graves | group | No | |
Houses | group | No | |
Humans | force | No | |
IncomeHash | hashtable | No | |
LastMinuteTimer | timer | No | |
Mills | group | No | |
NumHumans | integer | No | |
NumPlayers | integer | No | |
NumZombies | integer | No | |
Players | force | No | |
ResetMap | fogmodifier | No | |
T_Board | leaderboard | No | |
T_Build | boolean | No | |
T_Cells | integer | No | |
T_CellSize | real | No | |
T_HeightMap | hashtable | No | |
T_SampleHeightMap | hashtable | No | |
T_TileTypes | terraintype | Yes | |
T_TreeChances | integer | Yes | |
T_TreeTypes | destructablecode | Yes | |
T_WorldH | real | No | |
T_WorldW | real | No | |
T_x | real | No | |
T_y | real | No | |
TimeLeft | timer | No | |
TimeLeftWindow | timerdialog | No | |
Zombies | force | No |
function InitTrig_TerrainGen takes nothing returns nothing
endfunction
// ----- HEIGHT CODE -----
function GetLineHeight takes real A,real B,real C,real D,real m returns real
return m*(m*(m*(B-A-C+D)+2*(A-B)+C-D)-A+C)+B
endfunction
function Smooth_Linear takes real A,real B,real m returns real
return A*(1-m)+B*(m)
endfunction
function Smooth_Flat takes real A,real B,real m returns real
if m>0.5then
return B
else
return A
endif
endfunction
function GetZ takes real Z returns real
set Z=Z*Z*Z*576.
if Z<0 then
return -SquareRoot(-Z)
endif
return SquareRoot(Z)
endfunction
// ----- TERRAIN GENERATION CODE -----
function SetHeight takes real x,real y,real z returns nothing
local real curz
local integer X
local integer Y
set x=x/128+0.5
set y=y/128+0.5
if x<0.0 then
set x=x-1.0
endif
if y<0.0 then
set y=y-1.0
endif
set X=R2I(x)
set Y=R2I(y)
set curz=LoadReal(udg_T_HeightMap,X,Y)
call TerrainDeformCrater(X*128,Y*128,64,z-curz,1,true)
call SaveReal(udg_T_HeightMap,X,Y,z)
endfunction
function GetHeight takes real x,real y returns real
set x=x/128+0.5
set y=y/128+0.5
if x<0then
set x=x-1
endif
if y<0then
set y=y-1
endif
return LoadReal(udg_T_HeightMap,R2I(x),R2I(y))
endfunction
function GetCell takes real X,real Y returns real
// X and Y are not in map coordinates!
if X>udg_T_WorldW then
set X=udg_T_WorldW
elseif X<0then
set X=0
endif
if Y>udg_T_WorldH then
set Y=udg_T_WorldH
elseif Y<0then
set Y=0
endif
return LoadReal(udg_T_SampleHeightMap,R2I(X/udg_T_CellSize),R2I(Y/udg_T_CellSize))
endfunction
function GetPtHeight takes real x,real y returns real
// x and y are in map coordinates!
//0 to 32
//0 to 32
// x+y*33
//[-1,-1] ...
// ...
// [2,2]
local integer X
local integer Y
local integer I=0
local integer J
local real array Heights
// x and y are now translated!
set x=x-GetRectMinX(gg_rct_World)
set y=y-GetRectMinY(gg_rct_World)
set X=R2I(x/udg_T_CellSize)
set Y=R2I(y/udg_T_CellSize)
loop
set J=0
loop
set Heights[J]=GetCell(I2R(X+J-1)*udg_T_CellSize,I2R(Y+I-1)*udg_T_CellSize)
set J=J+1
exitwhen J==4
endloop
set Heights[I+4]=GetLineHeight(Heights[0],Heights[1],Heights[2],Heights[3],x/udg_T_CellSize-R2I(X))//Smooth_Flat(Heights[1],Heights[2],x-I2R(X))
set I=I+1
exitwhen I==4
endloop
return GetLineHeight(Heights[4],Heights[5],Heights[6],Heights[7],y/udg_T_CellSize-R2I(Y))//Smooth_Flat(Heights[5],Heights[6],y-I2R(Y))
endfunction
function UpdateProgress takes nothing returns nothing
local real G=I2R(udg_T_Cells)/1024.
local real R=1.-G
call LeaderboardSetItemValue(udg_T_Board,0,R2I(G*100.))
call LeaderboardSetItemValueColor(udg_T_Board,0,R2I(R*255.),R2I(G*255.),0,255)
endfunction
function BuildCell takes nothing returns nothing
local timer T=GetExpiredTimer()
local real X=udg_T_x
local real Y=udg_T_y
local real x=0
local real y=0
local integer Cx=0
local integer Cy=0
local real Z=0
local integer Tid=-1
local real tx
local real ty
local real OX=GetRectMinX(gg_rct_World)
local real OY=GetRectMinY(gg_rct_World)
set udg_T_Cells=udg_T_Cells+1
call UpdateProgress()
loop
set Cy=0
set x=X+Cx*128
loop
set y=Y+Cy*128
set Z=GetPtHeight(x+OX,y+OY)-0.5
set Tid=R2I(Z)
set Z=GetZ(Z)
if Tid>10then
set Tid=10
elseif Tid<0then
set Tid=0
endif
// Terrain Tile
call SetTerrainType(x+OX,y+OY,udg_T_TileTypes[Tid],-1,1,0)
if Tid==0then
call CreateDestructable('YTpc',x+OX,y+OY,0,1,0)
endif
// Terrain Height
call SetHeight(x+OX,y+OY,GetRandomReal(0,32)-Z)
// Trees
if GetRandomInt(1,100)<=udg_T_TreeChances[Tid]then
set tx=x+OX+GetRandomReal(-128,128)
set ty=y+OY+GetRandomReal(-128,128)
call CreateDestructableZ(udg_T_TreeTypes[Tid],tx,ty,GetZ(GetPtHeight(tx,ty))-48,GetRandomReal(0,360),GetRandomReal(.8,1.2),-1)
endif
// Gold Mines
if Tid>1 and GetRandomInt(0,100)<1then
call SetResourceAmount(CreateUnit(Player(15),'n000',x+OX,y+OY,0),GetRandomInt(20,100))
endif
set Cy=Cy+1
exitwhen Cy==4
endloop
set Cx=Cx+1
exitwhen Cx==4
endloop
set X=X+512
if X>=udg_T_WorldW then
set X=0
set Y=Y+512
endif
if Y<udg_T_WorldH then
set udg_T_x=X
set udg_T_y=Y
call TimerStart(T,.02,false,function BuildCell)
else
call DestroyTimer(T)
set udg_T_Build=false
endif
set T=null
endfunction
function FixGold takes nothing returns nothing
local group G=CreateGroup()
local unit U=null
local integer I
local real X
local real Y
call GroupEnumUnitsOfPlayer(G,Player(15),null)
loop
set U=FirstOfGroup(G)
exitwhen U==null
call GroupRemoveUnit(G,U)
set I=GetResourceAmount(U)
set X=GetWidgetX(U)
set Y=GetWidgetY(U)
call RemoveUnit(U)
set U=null
call SetResourceAmount(CreateUnit(Player(15),'n000',X,Y,0),I)
endloop
call DestroyGroup(G)
set G=null
set U=null
endfunction
function BuildTerrain takes nothing returns nothing
local timer T
local real Z
local integer x
local integer y=0
local integer w
local integer h
set udg_T_WorldW=GetRectMaxX(gg_rct_World)-GetRectMinX(gg_rct_World)
set udg_T_WorldH=GetRectMaxY(gg_rct_World)-GetRectMinY(gg_rct_World)
set w=R2I(udg_T_WorldW/udg_T_CellSize)
set h=R2I(udg_T_WorldH/udg_T_CellSize)
if not udg_T_Build then
set T=CreateTimer()
call LeaderboardDisplay(udg_T_Board,true)
set udg_T_x=0
set udg_T_y=0
set udg_T_Cells=0
// Create samples...
loop
set x=0
loop
if x>=w or y>=h or x<2or y<2then
set Z=-1
elseif x==w/2+1and y==h/2+1then
set Z=11.
else
set Z=GetRandomReal(.5,8.)
endif
call SaveReal(udg_T_SampleHeightMap,x,y,Z)
exitwhen x>=w
set x=x+1
endloop
exitwhen y>=h
set y=y+1
endloop
set udg_T_Build=true
call TimerStart(T,0,false,function BuildCell)
set T=null
endif
loop
exitwhen not udg_T_Build
call TriggerSleepAction(1)
endloop
call FixGold()
call LeaderboardDisplay(udg_T_Board,false)
endfunction
function InitTrig_Map_Script takes nothing returns nothing
endfunction
// ----- OTHER CODE -----
function CreatePlayer takes player Who,boolean zom returns nothing
local real X
local real Y
local real xx
local real yy
local integer A=100
local integer B=GetRandomInt(0,5)
local real z=bj_DEGTORAD*51.42857
local integer ID=udg_T_TileTypes[2]
local string s="human"
local integer workers='h002'
local integer house='h001'
local integer terrain=udg_BlightHuman
local rect R=null
if zom then
set ID=udg_T_TileTypes[10]
set s="zombie"
set workers='u002'
set house='h00G'
set terrain=udg_BlightZombie
endif
loop
set X=GetRandomReal(1024+GetRectMinX(gg_rct_World),GetRectMaxX(gg_rct_World)-1024)
set Y=GetRandomReal(1024+GetRectMinY(gg_rct_World),GetRectMaxY(gg_rct_World)-1024)
if GetTerrainType(X,Y)==ID then
set A=0
else
set A=A-1
endif
exitwhen A==0
endloop
set R=Rect(X-256,Y-256,X+256,Y+256)
call ClearTrees(R)
call RemoveRect(R)
set R=null
call CreateUnit(Who,house,X,Y,0)
loop
set xx=X+196*Cos(z*A)
set yy=Y+196*Sin(z*A)
if A==B then
if zom then
call CreateUnit(Who,'h008',xx,yy,0)
else
call TriggerRegisterUnitEvent(gg_trg_HumanDies,CreateUnit(Who,'h000',xx,yy,0),EVENT_UNIT_DEATH)
endif
elseif A==B+1then
call SetResourceAmount(CreateUnit(Player(15),'n000',xx,yy,0),200)
else
call CreateUnit(Who,workers,xx,yy,0)
endif
set A=A+1
exitwhen A==7
endloop
call SetPlayerState(Who,PLAYER_STATE_RESOURCE_GOLD,1)
call SetPlayerState(Who,PLAYER_STATE_RESOURCE_LUMBER,50)
if Who==GetLocalPlayer()then
call SetCameraPosition(X,Y)
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"|cffffff00You're a "+s+"!|r")
endif
call SetTerrainType(X,Y,terrain,0,4,0)
endfunction
function StartRound takes nothing returns nothing
local integer array Ps
local integer NP=0
local integer I=0
local player P
local player Z
local string S="|cffff8000Build a base and try to defend yourself for 20 mintes!|r"
call ResetMap()
call BuildTerrain()
loop
set P=Player(I)
if IsPlayerInForce(P,udg_Players)then
set Ps[NP]=I
set NP=NP+1
call ForceAddPlayer(udg_Humans,P)
endif
set P=null
set I=I+1
exitwhen I==12
endloop
set Z=Player(Ps[GetRandomInt(0,NP-1)])
if Z==GetLocalPlayer()then
set S="|cffff8000Seek out and kill all humans!|r"
endif
call ForceAddPlayer(udg_Zombies,Z)
call ForceRemovePlayer(udg_Humans,Z)
call TriggerExecute(gg_trg_Enforce_Allies)
set I=0
loop
set P=Player(Ps[I])
call CreatePlayer(P,P==Z)
set P=null
set I=I+1
exitwhen I==NP
endloop
set Z=null
set udg_NumZombies=1
set udg_NumHumans=NP-1
call MaskEnd()
call DisplayTextToPlayer(GetLocalPlayer(),0,0,S)
call TimerStart(udg_TimeLeft,1200,false,null)
call TimerStart(udg_LastMinuteTimer,1110,false,function LastMinute)
call TimerDialogDisplay(udg_TimeLeftWindow,true)
endfunction
function Init takes nothing returns nothing
local timer T=GetExpiredTimer()
local quest Quest=CreateQuest()
local questitem Item=null
call DestroyTimer(T)
set T=null
call MaskStart()
call SetWaterBaseColor(128,255,255,255)
call PlayMusic(gg_snd_Music)
set udg_T_CellSize=2048
call SetFloatGameState(GAME_STATE_TIME_OF_DAY,0)
call SetTimeOfDayScale(0)
set udg_T_Board=CreateLeaderboard()
call LeaderboardSetLabel(udg_T_Board,"")
call LeaderboardAddItem(udg_T_Board,"Terrain Progress:",0,Player(0))
call LeaderboardSetSizeByItemCount(udg_T_Board,0)
call LeaderboardSetItemLabelColor(udg_T_Board,0,128,0,128,255)
call LeaderboardSetItemValueColor(udg_T_Board,0,255,0,0,255)
set udg_TimeLeftWindow=CreateTimerDialog(udg_TimeLeft)
call TimerDialogSetTitle(udg_TimeLeftWindow,"Humans Win:")
set udg_T_TileTypes[0]='Oaby'
set udg_T_TileTypes[1]='Zdrt'
set udg_T_TileTypes[2]='Zsan'
set udg_T_TileTypes[3]='Lgrd'
set udg_T_TileTypes[4]='Lgrs'
set udg_T_TileTypes[5]='Wgrs'
set udg_T_TileTypes[6]='Wsng'
set udg_T_TileTypes[7]='Nsnw'
set udg_T_TileTypes[8]='Nsnr'
set udg_T_TileTypes[9]='Nice'
set udg_T_TileTypes[10]='Nrck'
//set udg_T_TreeTypes[0]='B007'
set udg_T_TreeTypes[1]='B006'
set udg_T_TreeTypes[2]='B001'
set udg_T_TreeTypes[3]='B000'
set udg_T_TreeTypes[4]='B009'
set udg_T_TreeTypes[5]='B00A'
set udg_T_TreeTypes[6]='B008'
set udg_T_TreeTypes[7]='B002'
set udg_T_TreeTypes[8]='B003'
set udg_T_TreeTypes[9]='B004'
set udg_T_TreeTypes[10]='B005'
set udg_T_TreeChances[0]=0
set udg_T_TreeChances[1]=10
set udg_T_TreeChances[2]=20
set udg_T_TreeChances[3]=50
set udg_T_TreeChances[4]=50
set udg_T_TreeChances[5]=50
set udg_T_TreeChances[6]=35
set udg_T_TreeChances[7]=15
set udg_T_TreeChances[8]=10
set udg_T_TreeChances[9]=5
set udg_T_TreeChances[10]=1
set udg_BlightHuman='Ybtl'
set udg_BlightZombie='Jbtl'
set udg_IncomeHash=InitHashtable()
set udg_T_HeightMap=InitHashtable()
set udg_T_SampleHeightMap=InitHashtable()
call SaveInteger(udg_IncomeHash,'h00C',0,1)
call SaveInteger(udg_IncomeHash,'h00E',0,2)
call SaveInteger(udg_IncomeHash,'h00M',0,1)
call SaveInteger(udg_IncomeHash,'h00N',0,2)
//Credits
set Item=QuestCreateItem(Quest)
call QuestItemSetDescription(Item,"Credits for various art-work.")
call QuestItemSetCompleted(Item,false)
set Item=QuestCreateItem(Quest)
call QuestItemSetDescription(Item,"If you see custom art-work without credits, I made it.")
call QuestItemSetCompleted(Item,false)
set Item=QuestCreateItem(Quest)
call QuestItemSetDescription(Item,"If you see your work without credits, let me know!.")
call QuestItemSetCompleted(Item,false)
call QuestSetTitle(Quest,"Credits")
call QuestSetDescription(Quest,"MasterHaosis - Grave Icon\nBlizzard - Gold Coin Icon")
call QuestSetIconPath(Quest,"ReplaceableTextures\\CommandButtons\\BTNINV_Misc_Coin_01.blp")
call QuestSetRequired(Quest,true)
call QuestSetDiscovered(Quest,true)
call QuestSetCompleted(Quest,false)
//Testers
set Quest=CreateQuest()
set Item=QuestCreateItem(Quest)
call QuestItemSetDescription(Item,"This is a list of all testers.")
call QuestItemSetCompleted(Item,false)
call QuestSetTitle(Quest,"Testers")
call QuestSetDescription(Quest,"Sheep100, Zikkeryzak, Alucardist, Trunks34")
call QuestSetIconPath(Quest,"ReplaceableTextures\\CommandButtons\\BTNEngineeringUpgrade.blp")
call QuestSetRequired(Quest,true)
call QuestSetDiscovered(Quest,true)
call QuestSetCompleted(Quest,false)
call SetCameraField(CAMERA_FIELD_FARZ,8192,0)
set Quest=null
set Item=null
endfunction
function Escape takes nothing returns nothing
local trigger T=GetTriggeringTrigger()
local integer I=5
call DisableTrigger(T)
call ShowInterface(false,0)
call TriggerSleepAction(1)
call SetCinematicScene('hfoo',PLAYER_COLOR_GREEN,"Random Footman","Derp Derp Derp!",5,1)
loop
call TriggerSleepAction(1)
set I=I-1
exitwhen I==0
endloop
call ShowInterface(true,1)
call EnableTrigger(T)
set T=null
endfunction
function InitTrig_Escape takes nothing returns nothing
set gg_trg_Escape=CreateTrigger()
call TriggerAddAction(gg_trg_Escape,function Escape)
call TriggerRegisterPlayerEvent(gg_trg_Escape,Player(0),EVENT_PLAYER_END_CINEMATIC)
endfunction
function GameStart takes nothing returns nothing
local integer I=0
local player P
// Make a better intro string.
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Ahh! It's a Zombie! Run away if you're human, and kill the humans if you're a zombie, killing humans converts them to zombies.")
loop
set P=Player(I)
if GetPlayerSlotState(P)==PLAYER_SLOT_STATE_PLAYING then
call ForceAddPlayer(udg_Players,P)// Add player to list of players.
set udg_NumPlayers=udg_NumPlayers+1// Increase number of players.
call PlayerSetLeaderboard(P,udg_T_Board)// Set leaderboard to display the terrain progress.
call SetPlayerTechMaxAllowed(P,'h008',1)
call TriggerRegisterPlayerEvent(gg_trg_PlayerQuit,P,EVENT_PLAYER_LEAVE)// Add player to Quit trigger.
call TriggerRegisterPlayerUnitEvent(gg_trg_UnitDies,P,EVENT_PLAYER_UNIT_DEATH,null)// Add player to UnitDies trigger.
call TriggerRegisterPlayerUnitEvent(gg_trg_StructureBuilt,P,EVENT_PLAYER_UNIT_CONSTRUCT_FINISH,null)// Add player to Constructed trigger.
call TriggerRegisterPlayerUnitEvent(gg_trg_DestroyBuilding,P,EVENT_PLAYER_UNIT_RESEARCH_START,null)// Add player to Destroy Building trigger.
endif
set P=null
set I=I+1
exitwhen I==12
endloop
if udg_NumPlayers==1then
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"|cffffff00Single Player Mode|r")
endif
call StartRound()
endfunction
function InitTrig_GameStart takes nothing returns nothing
local timer T=CreateTimer()
call TimerStart(T,0,false,function Init)
set T=null
set gg_trg_GameStart=CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_GameStart,0,false)
call TriggerAddAction(gg_trg_GameStart,function GameStart)
endfunction
function RoundEnd takes nothing returns nothing
local group G=null
local string S="|cff00ff00The Humans have outlasted the Zombies!|r"
call TimerDialogDisplay(udg_TimeLeftWindow,false)
if udg_NumHumans==0then
set S="|cff00ff00The Zombies have killed all the Humans!|r"
endif
call DisplayTextToPlayer(GetLocalPlayer(),0,0,S)
if udg_NumPlayers==1then
call DisplayTextToForce(GetPlayersAll(),"|cffffff00Single Player Mode|r")
else
call FogEnable(true)
call FogMaskEnable(true)
call MaskStart()
set G=CreateGroup()
call GroupEnumUnitsInRect(G,gg_rct_World,null)
call ForGroup(G,function RemoveUnitEnum)
call DestroyGroup(G)
set G=null
call ClearTrees(gg_rct_World)
call EndThematicMusic()
call StopMusic(true)
call PlayMusic(gg_snd_Music)
call ForceClear(udg_Zombies)
call ForceClear(udg_Humans)
call StartRound()
endif
endfunction
function InitTrig_RoundEnd takes nothing returns nothing
set gg_trg_RoundEnd=CreateTrigger()
call TriggerRegisterTimerExpireEvent(gg_trg_RoundEnd,udg_TimeLeft)
call TriggerAddAction( gg_trg_RoundEnd,function RoundEnd)
endfunction
function Trig_Environment_Actions takes nothing returns nothing
local real mX=udg_TilesMinX
local real mY=udg_TilesMinY
local real MX=udg_TilesMaxX
local real MY=udg_TilesMaxY
local real X=mX
local real Y=mY
local integer W=0
local integer T
local integer I
local integer L
local integer C=0
if mY==MY or mX==MX then
return
endif
set udg_TerrainCount=udg_TerrainCount+1
set udg_TilesMinX=0
set udg_TilesMinY=0
set udg_TilesMaxX=0
set udg_TilesMaxY=0
loop
exitwhen Y>MY
set X=mX
loop
exitwhen X>MX
set T=GetTerrainType(X,Y)
//Set Terrain Index
set L=0
loop
exitwhen L>10
if T==udg_T_TileTypes[L]then
set I=L
set L=11
endif
set L=L+1
endloop
//GoldMines
if I==10then
if GetRandomInt(0,10)>9then
call SetResourceAmount(CreateUnit(Player(15),'n000',X,Y,0),25)
endif
endif
//Trees
set C=GetRandomInt(1,100)
if C<=udg_T_TreeChances[I]then
call CreateDestructable(udg_T_TreeTypes[I],X+GetRandomReal(-128,128),Y+GetRandomReal(-128,128),GetRandomReal(0,360),GetRandomReal(.4,1),-1)
endif
//Shrubs
//Animals
set W=W+1
if W==100then
set W=0
call TriggerSleepAction(0.1)
endif
set X=X+128
endloop
set Y=Y+128
endloop
set udg_TerrainCount=udg_TerrainCount-1
endfunction
function InitTrig_Environment takes nothing returns nothing
set gg_trg_Environment=CreateTrigger()
call TriggerAddAction(gg_trg_Environment,function Trig_Environment_Actions)
endfunction
function PlayerQuit takes nothing returns nothing
local player P=GetTriggerPlayer()
local group G=CreateGroup()
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"|cffff0000"+GetPlayerName(P)+" has quit the game!|r")
call ForceRemovePlayer(udg_Players,P)
set udg_NumPlayers=udg_NumPlayers-1
if IsPlayerInForce(P,udg_Humans)then
call ForceRemovePlayer(udg_Humans,P)
set udg_NumHumans=udg_NumHumans-1
else
call ForceRemovePlayer(udg_Zombies,P)
set udg_NumZombies=udg_NumZombies-1
endif
call GroupEnumUnitsOfPlayer(G,P,null)
call ForGroup(G,function RemoveUnitEnum)
call DestroyGroup(G)
set G=null
set P=null
if udg_NumHumans==0or udg_NumZombies==0then
call TimerStart(udg_TimeLeft,0,false,null)
endif
endfunction
function InitTrig_PlayerQuit takes nothing returns nothing
set gg_trg_PlayerQuit=CreateTrigger()
call TriggerAddCondition(gg_trg_PlayerQuit,Condition(function PlayerQuit))
endfunction
function DestroyBuilding takes nothing returns boolean
local unit U=GetTriggerUnit()
if GetResearched()=='R000'then
call KillUnit(U)
endif
set U=null
return false
endfunction
function InitTrig_DestroyBuilding takes nothing returns nothing
set gg_trg_DestroyBuilding=CreateTrigger()
call TriggerAddCondition(gg_trg_DestroyBuilding,Condition(function DestroyBuilding))
endfunction
function UnitDies takes nothing returns nothing
local unit U=GetTriggerUnit()
call GroupRemoveUnit(udg_Houses,U)
call GroupRemoveUnit(udg_Graves,U)
call GroupRemoveUnit(udg_Mills,U)
set U=null
endfunction
function InitTrig_UnitDies takes nothing returns nothing
set gg_trg_UnitDies=CreateTrigger()
call TriggerAddAction(gg_trg_UnitDies,function UnitDies)
endfunction
function HumanDies takes nothing returns nothing
local unit U=GetDyingUnit()// Woodsman that died.
local player P=GetOwningPlayer(U)// Player who's Woodman just died.
local unit K=GetKillingUnit()// Unit that killed the Woodsman.
local player KP=GetOwningPlayer(K)// Player who's unit killed the Woodsman.
local real X=GetWidgetX(U)// X of Woodman's coord.
local real Y=GetWidgetY(U)// Y of Woodman's coord.
local string MA=""
local string MK=""
local string MP=""
local group G=null
if udg_NumPlayers==1then// Check for singleplayer.
call CreateUnit(P,'h000',X,Y,0)
set U=null
set P=null
set K=null
set KP=null
return
endif
// Otherwise... display a message!
if P==KP then
set MA="|cffff8000"+GetPlayerName(P)+" commited suicide!|r"
set MP="|cffff8000You commited suicide!|r"
else
set MA="|cffff8000"+GetPlayerName(KP)+" killed "+GetPlayerName(P)+"!|r"
set MK="|cffff8000You killed "+GetPlayerName(P)+"!|r"
set MP="|cffff8000"+GetPlayerName(KP)+" killed you!|r"
endif
if P==GetLocalPlayer()then
call DisplayTextToPlayer(P,0,0,MP)
elseif KP==GetLocalPlayer()then
call DisplayTextToPlayer(KP,0,0,MK)
else
call DisplayTextToPlayer(GetLocalPlayer(),0,0,MA)
endif
// Check remaining humans.
set udg_NumHumans=udg_NumHumans-1
if udg_NumHumans==0then
call TimerStart(udg_TimeLeft,0,false,null)
else
set G=CreateGroup()
set udg_NumZombies=udg_NumZombies+1
call GroupEnumUnitsOfPlayer(G,P,null)
call ForGroup(G,function RemoveUnitEnum)
call DestroyGroup(G)
set G=null
call ForceRemovePlayer(udg_Humans,P)
call ForceAddPlayer(udg_Zombies,P)
call TriggerExecute(gg_trg_Enforce_Allies)
call ResetMapForPlayer(P)
call CreatePlayer(P,true)
endif
set U=null
set P=null
set K=null
set KP=null
endfunction
function InitTrig_HumanDies takes nothing returns nothing
set gg_trg_HumanDies=CreateTrigger()
call TriggerAddAction(gg_trg_HumanDies,function HumanDies)
endfunction
function Blight takes unit U returns nothing
local real X=GetWidgetX(U)
local real Y=GetWidgetY(U)
local integer ID=GetTerrainType(X,Y)
local boolean Hum=GetUnitAbilityLevel(U,'A006')>0
local boolean Zom=GetUnitAbilityLevel(U,'A007')>0
local real Rad=0
local real CRd=0
if GetUnitAbilityLevel(U,'A002')==0then
if(Hum and ID!=udg_BlightHuman)or(Zom and ID!=udg_BlightZombie)then
call KillUnit(U)
set U=null
return
endif
else
if Hum then
set ID=udg_BlightHuman
elseif Zom then
set ID=udg_BlightZombie
endif
endif
if GetUnitAbilityLevel(U,'A008')>0then
set Rad=512
elseif GetUnitAbilityLevel(U,'A00B')>0then
set Rad=384
elseif GetUnitAbilityLevel(U,'A009')>0then
set Rad=256
else
set U=null
return
endif
loop
call SetTerrainType(X,Y,ID,0,R2I(CRd)/128,0)
set CRd=CRd+128
exitwhen CRd>Rad
call TriggerSleepAction(0.5)
endloop
set U=null
endfunction
function StructureBuilt takes nothing returns nothing
local unit U=GetTriggerUnit()
local integer Id=GetUnitTypeId(U)
local player P=GetOwningPlayer(U)
local group G=null
if Id=='n000'then
call SetResourceAmount(U,25)
endif
if GetUnitAbilityLevel(U,'A001')>0then
call GroupAddUnit(udg_Houses,U)
endif
if GetUnitAbilityLevel(U,'A005')>0then
call GroupAddUnit(udg_Mills,U)
endif
if GetUnitAbilityLevel(U,'A00A')>0then
call GroupAddUnit(udg_Graves,U)
endif
call Blight(U)
set U=null
set P=null
endfunction
function InitTrig_StructureBuilt takes nothing returns nothing
set gg_trg_StructureBuilt=CreateTrigger()
call TriggerAddAction(gg_trg_StructureBuilt,function StructureBuilt)
endfunction
function Income takes nothing returns nothing
local unit U=GetEnumUnit()
local player P=GetOwningPlayer(U)
local integer Uid=GetUnitTypeId(U)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Other\\Transmute\\PileofGold.mdl",GetWidgetX(U),GetWidgetX(U)))
call SetPlayerState(P,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(P,PLAYER_STATE_RESOURCE_GOLD)+LoadInteger(udg_IncomeHash,Uid,0))
set U=null
set P=null
endfunction
function Trees takes nothing returns nothing
local unit U=GetEnumUnit()
call CreateTree(GetWidgetX(U),GetWidgetY(U))
set U=null
endfunction
function Resources takes nothing returns nothing
call ForGroup(udg_Houses,function Income)
call ForGroup(udg_Mills,function Trees)
endfunction
function InitTrig_Every_Minute takes nothing returns nothing
set gg_trg_Every_Minute=CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_Every_Minute,20,true)
call TriggerAddCondition(gg_trg_Every_Minute,Condition(function Resources))
endfunction
function GraveEnum takes nothing returns boolean
local unit U=GetFilterUnit()
if GetWidgetLife(U)<0.405and not(IsUnitType(U,UNIT_TYPE_STRUCTURE)or GetUnitTypeId(U)=='hpea')then
call RemoveUnit(U)
call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl",GetWidgetX(U),GetWidgetY(U)))
endif
set U=null
return false
endfunction
function Grave takes nothing returns nothing
local unit U=GetEnumUnit()
local group G=CreateGroup()
call GroupEnumUnitsInRange(G,GetWidgetX(U),GetWidgetY(U),768,Condition(function GraveEnum))
call DestroyGroup(G)
set G=null
set U=null
endfunction
function Graves takes nothing returns nothing
call ForGroup(udg_Graves,function Grave)
endfunction
function InitTrig_Graves takes nothing returns nothing
set gg_trg_Graves=CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_Graves,1,true)
call TriggerAddCondition(gg_trg_Graves,Condition(function Graves))
endfunction
function PlayerCam takes nothing returns nothing
local real X=GetCameraEyePositionX()
local real Y=GetCameraEyePositionY()
local real Z=GetPtHeight(X,Y)
local real Z2=0
set X=GetCameraTargetPositionX()
set Y=GetCameraTargetPositionY()
set Z2=GetPtHeight(X,Y)
if Z2>Z then
set Z=Z2
endif
call SetCameraField(CAMERA_FIELD_ZOFFSET,GetZ(Z),.02)
endfunction
function InitTrig_Every_Step takes nothing returns nothing
set gg_trg_Every_Step=CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_Every_Step,.02,true)
call TriggerAddCondition(gg_trg_Every_Step,Condition(function PlayerCam))
endfunction