forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptextern.cpp
226 lines (196 loc) · 4.9 KB
/
scriptextern.cpp
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
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2012 Warzone 2100 Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* ScriptExtern.c
*
* All game variable access functions for the scripts
*
*/
#include "lib/framework/frame.h"
#include "map.h"
#include "lib/script/script.h"
#include "lib/netplay/netplay.h"
#include "scripttabs.h"
#include "scriptextern.h"
#include "display.h"
#include "multiplay.h"
#include "main.h"
#include "hci.h"
#include "lib/gamelib/gtime.h"
// current game level
SDWORD scrGameLevel = 0;
// whether the tutorial is active
bool bInTutorial = false;
// whether any additional special case victory/failure conditions have been met
bool bExtraVictoryFlag = false;
bool bExtraFailFlag = false;
// whether or not to track the player's transporter as it comes
// into an offworld mission.
bool bTrackTransporter = false;
// reset the script externals for a new level
void scrExternReset(void)
{
scrGameLevel = 0;
bInTutorial = false;
bExtraVictoryFlag = false;
bExtraFailFlag = false;
}
// General function to get some basic game values
bool scrGenExternGet(UDWORD index)
{
INTERP_TYPE type;
INTERP_VAL scrFunctionResult; //function return value to be pushed to stack
switch (index)
{
case EXTID_TRACKTRANSPORTER:
type = VAL_BOOL;
scrFunctionResult.v.bval = bTrackTransporter;
break;
case EXTID_MAPWIDTH:
type = VAL_INT;
scrFunctionResult.v.ival = mapWidth;
break;
case EXTID_MAPHEIGHT:
type = VAL_INT;
scrFunctionResult.v.ival = mapHeight;
break;
case EXTID_GAMEINIT:
type = VAL_BOOL;
scrFunctionResult.v.bval = gameInitialised;
break;
case EXTID_SELECTEDPLAYER:
type = VAL_INT;
scrFunctionResult.v.ival = selectedPlayer;
break;
case EXTID_GAMELEVEL:
type = VAL_INT;
scrFunctionResult.v.ival = scrGameLevel;
break;
case EXTID_GAMETIME:
type = VAL_INT;
scrFunctionResult.v.ival = (SDWORD)(gameTime/SCR_TICKRATE);
break;
case EXTID_TUTORIAL:
type = VAL_BOOL;
scrFunctionResult.v.bval = bInTutorial;
break;
case EXTID_CURSOR:
type = VAL_INT;
scrFunctionResult.v.ival = 0; // FIXME Set to 0 since function returned undef value
break;
case EXTID_INTMODE:
type=VAL_INT;
scrFunctionResult.v.ival=intMode;
break;
case EXTID_TARGETTYPE:
type=VAL_INT;
scrFunctionResult.v.ival=getTargetType();
break;
case EXTID_EXTRAVICTORYFLAG:
type=VAL_BOOL;
scrFunctionResult.v.bval=bExtraVictoryFlag;
break;
case EXTID_EXTRAFAILFLAG:
type=VAL_BOOL;
scrFunctionResult.v.bval=bExtraFailFlag;
break;
case EXTID_MULTIGAMETYPE: // multiplayer variable..
type = VAL_INT;
scrFunctionResult.v.ival = game.type;
break;
case EXTID_MULTIGAMEHUMANMAX: // multiplayer variable..
type = VAL_INT;
scrFunctionResult.v.ival = game.maxPlayers;
break;
case EXTID_MULTIGAMEBASETYPE:
type = VAL_INT;
scrFunctionResult.v.ival = game.base;
break;
case EXTID_MULTIGAMEALLIANCESTYPE:
type = VAL_INT;
scrFunctionResult.v.ival = game.alliance;
break;
default:
ASSERT( false, "scrGenExternGet: unknown variable index" );
return false;
break;
}
if (!stackPushResult(type, &scrFunctionResult))
{
return false;
}
return true;
}
// General function to set some basic game values
bool scrGenExternSet(UDWORD index)
{
INTERP_VAL sVal;
INTERP_TYPE type;
SDWORD val;
// Get the value and store it in type,val
if (!stackPop(&sVal))
{
return false;
}
type = sVal.type;
val = sVal.v.ival;
switch (index)
{
case EXTID_GAMELEVEL:
if (type != VAL_INT)
{
ASSERT( false,"invalid type for gameLevel" );
return false;
}
scrGameLevel = val;
break;
case EXTID_TUTORIAL:
if (type != VAL_BOOL)
{
ASSERT( false,"invalid type for inTutorial" );
return false;
}
bInTutorial = val;
if (val)
{
// Since tutorial is skirmish
NetPlay.players[0].allocated = true;
}
break;
case EXTID_EXTRAVICTORYFLAG:
if (type != VAL_BOOL)
{
ASSERT( false,"invalid type for extraVictoryFlag" );
return false;
}
bExtraVictoryFlag = val;
break;
case EXTID_EXTRAFAILFLAG:
if (type != VAL_BOOL)
{
ASSERT( false,"invalid type for extraFailFlag" );
return false;
}
bExtraFailFlag = val;
break;
default:
ASSERT( false, "scrGenExternSet: unknown variable index" );
return false;
break;
}
return true;
}