-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgametype_conquest.lua
180 lines (159 loc) · 3.92 KB
/
gametype_conquest.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
ConquestTeam =
{
team = 0,
points = 0,
count = 0,
bleed = {},
--
-- Create a new conquest team
--
New = function(self, o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end,
--
-- Initialize the conquest team
--
Init = function(self)
-- ai goals
AddAIGoal(self.team,"Conquest",100)
-- create the bleed timer
self.bleedtimer = CreateTimer("bleed" .. self.team)
SetTimerValue(self.bleedtimer, 4)
OnTimerElapse(
function (timer)
if GetReinforcementCount(self.team) > 0 then
AddReinforcements(self.team, -1)
end
SetTimerValue(timer, GetTimerValue(timer) + 4)
StartTimer(timer)
end,
self.bleedtimer)
-- create the lose timer
self.losetimer = CreateTimer("instant" .. self.team)
OnTimerElapse(
function(timer)
MissionDefeat(self.team)
end,
self.losetimer)
-- command post spawn
OnCommandPostRespawn(
function (post)
local team = GetCommandPostTeam(post)
if team == self.team then
self:UpdatePost(GetCommandPostBleedValue(post, team), 1)
elseif team == 0 then
self:UpdatePost(1, 0)
end
end
)
-- command post kill
OnCommandPostKill(
function (post)
local team = GetCommandPostTeam(post)
if team == self.team then
self:UpdatePost(-GetCommandPostBleedValue(post, team), -1)
elseif team == 0 then
self:UpdatePost(-1, 0)
end
end
)
-- command post neutralize
OnFinishNeutralize(
function (post)
local team = GetCommandPostTeam(post)
if team == self.team then
self:UpdatePost(1 - GetCommandPostBleedValue(post, team), -1)
elseif team ~= 0 then
self:UpdatePost(1, 0)
end
end
)
-- command post capture
OnFinishCapture(
function (post)
local team = GetCommandPostTeam(post)
if team == self.team then
self:UpdatePost(GetCommandPostBleedValue(post, team) - 1, 1)
elseif team ~= 0 then
self:UpdatePost(-1, 0)
end
end
)
-- teammate death
OnCharacterDeathTeam(
function (character, killer)
if GetReinforcementCount(self.team) > 0 then
AddReinforcements(self.team, -1)
end
end,
self.team
)
-- ticket count change
OnTicketCountChangeTeam(
function (team, count)
if count <= 0 then
MissionDefeat(team)
end
end,
self.team
)
end,
--
-- add a bleed threshold
--
AddBleedThreshold = function(self, threshold, rate)
self.bleed[threshold] = rate
end,
--
-- update command post points and count
--
UpdatePost = function(self, points, count)
-- update the total points and count
self.points = self.points + points;
self.count = self.count + count;
-- calculate the bleed rate
local bleedrate = 0
local minthresh = 2147483647
for threshold, rate in pairs(self.bleed) do
if self.points <= threshold and threshold <= minthresh then
bleedrate = rate
minthresh = threshold
end
end
-- update the bleed rate
SetBleedRate(self.team, bleedrate)
SetTimerRate(self.bleedtimer, bleedrate)
-- start or stop the bleed timer as necessary
if bleedrate == 0 then
StopTimer(self.bleedtimer)
else
StartTimer(self.bleedtimer)
end
-- if the enemy holds all command points...
if self.points <= 0 then
-- show the lose timer
SetDefeatTimer(self.losetimer, self.team)
-- start the lose timer
StartTimer(self.losetimer)
else
-- stop the lose timer
StopTimer(self.losetimer)
-- if holding at least one commmand post ...
if self.count > 0 then
-- if adding the first one...
if self.count == count then
-- hide the lose timer
SetDefeatTimer(nil, self.team)
end
-- reset the lose timer
SetTimerValue(self.losetimer, 20)
end
end
end
}