/
rules.js
239 lines (223 loc) · 6.9 KB
/
rules.js
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//
// Skirmish Base Script.
//
// contains the rules for starting and ending a game.
// as well as warning messages.
//
// /////////////////////////////////////////////////////////////////
var lastHitTime = 0;
function eventGameInit()
{
hackNetOff();
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
enableStructure("A0CommandCentre", playnum); // make structures available to build
enableStructure("A0LightFactory", playnum);
enableStructure("A0ResourceExtractor", playnum);
enableStructure("A0PowerGenerator", playnum);
enableStructure("A0ResearchFacility", playnum);
// We need to enable these in order for scripts to be able to generate their templates.
// Cyborg legs is a research that is never researched. The rest are not even present in
// the research system. They should be there as results, along with the bodies.
makeComponentAvailable("CyborgLegs", playnum);
makeComponentAvailable("Cyb-Wpn-Atmiss", playnum);
makeComponentAvailable("CyborgCannon", playnum);
makeComponentAvailable("CyborgChaingun", playnum);
makeComponentAvailable("CyborgFlamer01", playnum);
makeComponentAvailable("Cyb-Wpn-Grenade", playnum);
makeComponentAvailable("Cyb-Hvywpn-A-T", playnum);
makeComponentAvailable("Cyb-Hvywpn-Acannon", playnum);
makeComponentAvailable("Cyb-Hvywpn-HPV", playnum);
makeComponentAvailable("Cyb-Hvywpn-Mcannon", playnum);
makeComponentAvailable("Cyb-Hvywpn-PulseLsr", playnum);
makeComponentAvailable("Cyb-Hvywpn-RailGunner", playnum);
makeComponentAvailable("Cyb-Hvywpn-TK", playnum);
makeComponentAvailable("Cyb-Wpn-Laser", playnum);
makeComponentAvailable("Cyb-Wpn-Rail1", playnum);
makeComponentAvailable("CyborgRocket", playnum);
makeComponentAvailable("CyborgRotMG", playnum);
makeComponentAvailable("Cyb-Wpn-Thermite", playnum);
makeComponentAvailable("CyborgFlamer01", playnum);
setStructureLimits("A0LightFactory", 5, playnum); // set structure limits
setStructureLimits("A0PowerGenerator", 8, playnum);
setStructureLimits("A0ResearchFacility", 5, playnum);
setStructureLimits("A0CommandCentre", 1, playnum);
setStructureLimits("A0ComDroidControl", 1, playnum);
setStructureLimits("A0CyborgFactory", 5, playnum);
setStructureLimits("A0VTolFactory1", 5, playnum);
}
applyLimitSet(); // set limit options
const numCleanTech = 4; // do x for clean
const numBaseTech = 18; // do x for base
var techlist = new Array(
"R-Vehicle-Prop-Wheels",
"R-Sys-Spade1Mk1",
"R-Vehicle-Body01",
"R-Comp-SynapticLink",
"R-Wpn-MG1Mk1",
"R-Defense-HardcreteWall",
"R-Vehicle-Prop-Wheels",
"R-Sys-Spade1Mk1",
"R-Struc-Factory-Cyborg",
"R-Defense-Pillbox01",
"R-Defense-Tower01",
"R-Vehicle-Body01",
"R-Sys-Engineering01",
"R-Struc-CommandRelay",
"R-Vehicle-Prop-Halftracks",
"R-Comp-CommandTurret01",
"R-Sys-Sensor-Turret01",
"R-Wpn-Flamer01Mk1",
"R-Vehicle-Body05",
"R-Struc-Research-Module",
"R-Struc-PowerModuleMk1",
"R-Struc-Factory-Module",
"R-Struc-RepairFacility",
"R-Sys-MobileRepairTurret01",
"R-Vehicle-Engine01",
"R-Wpn-MG3Mk1",
"R-Wpn-Cannon1Mk1",
"R-Wpn-Mortar01Lt",
"R-Defense-Pillbox05",
"R-Defense-TankTrap01",
"R-Defense-WallTower02",
"R-Sys-Sensor-Tower01",
"R-Defense-Pillbox04",
"R-Wpn-MG2Mk1",
"R-Wpn-Rocket05-MiniPod",
"R-Wpn-MG-Damage01",
"R-Wpn-Rocket-Damage01",
"R-Defense-WallTower01");
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
enableResearch("R-Sys-Sensor-Turret01", playnum);
enableResearch("R-Wpn-MG1Mk1", playnum);
enableResearch("R-Sys-Engineering01", playnum);
// enable cyborgs components that can't be enabled with research
makeComponentAvailable("CyborgSpade", playnum);
makeComponentAvailable("CyborgRepair", playnum);
if (baseType == CAMP_CLEAN)
{
setPower(1300, playnum);
for (var count = 0; count < numCleanTech; count++)
{
completeResearch(techlist[count], playnum);
}
// Keep only some structures for insane AI
var structs = enumStruct(playnum);
for (var i = 0; i < structs.length; i++)
{
var s = structs[i];
if (playerData[playnum].difficulty != INSANE
|| (s.stattype != WALL && s.stattype != DEFENSE && s.stattype != GATE
&& s.stattype != RESOURCE_EXTRACTOR))
{
removeStruct(s);
}
}
}
else if (baseType == CAMP_BASE)
{
setPower(2500, playnum);
for (var count = 0; count < numBaseTech; count++)
{
completeResearch(techlist[count], playnum);
}
// Keep only some structures
var structs = enumStruct(playnum);
for (var i = 0; i < structs.length; i++)
{
var s = structs[i];
if ((playerData[playnum].difficulty != INSANE && (s.stattype == WALL || s.stattype == DEFENSE))
|| s.stattype == GATE || s.stattype == CYBORG_FACTORY || s.stattype == COMMAND_CONTROL)
{
removeStruct(s);
}
}
}
else // CAMP_WALLS
{
setPower(2500, playnum);
for (var count = 0; count < techlist.length; count++)
{
completeResearch(techlist[count], playnum);
}
}
}
hackNetOn();
setTimer("checkEndConditions", 100);
}
// /////////////////////////////////////////////////////////////////
// END CONDITIONS
function checkEndConditions()
{
var factories = enumStruct(me, "A0LightFactory").length + enumStruct(me, "A0CyborgFactory").length;
var droids = enumDroid(me).length;
// Losing Conditions
if (droids == 0 && factories == 0)
{
var gameLost = true;
/* If teams enabled check if all team members have lost */
if (alliancesType == ALLIANCES_TEAMS)
{
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
if (playnum != me && allianceExistsBetween(me, playnum))
{
factories = enumStruct(playnum, "A0LightFactory").length + enumStruct(playnum, "A0CyborgFactory").length;
droids = enumDroid(playnum).length;
if (droids > 0 || factories > 0)
{
gameLost = false; // someone from our team still alive
break;
}
}
}
}
if (gameLost)
{
gameOverMessage(false);
removeTimer("checkEndConditions");
return;
}
}
// Winning Conditions
var gamewon = true;
// check if all enemies defeated
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
if (playnum != me && !allianceExistsBetween(me, playnum)) // checking enemy player
{
factories = enumStruct(playnum, "A0LightFactory").length + enumStruct(playnum, "A0CyborgFactory").length; // nope
droids = enumDroid(playnum).length;
if (droids > 0 || factories > 0)
{
gamewon = false; //one of the enemies still alive
break;
}
}
}
if (gamewon)
{
gameOverMessage(true);
removeTimer("checkEndConditions");
}
}
// /////////////////////////////////////////////////////////////////
// WARNING MESSAGES
// Base Under Attack
function eventStructureAttacked(hitStruct, attackerObj)
{
if (gameTime > lastHitTime + 10)
{
lastHitTime = gameTime;
if (hitStruct)
{
playSound("pcv337.ogg", hitStruct.x, hitStruct.y, hitStruct.z); // show position if still alive
}
else
{
playSound("pcv337.ogg");
}
}
}