File: trigger.cpp

package info (click to toggle)
postal1 2015.git20250526%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 14,024 kB
  • sloc: cpp: 130,877; ansic: 38,942; python: 874; makefile: 351; sh: 61
file content (329 lines) | stat: -rw-r--r-- 9,836 bytes parent folder | download | duplicates (2)
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program 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 this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// trigger.cpp
// Project: Nostril (aka Postal)
//
// This module impliments the CTrigger class -> holds trigger attributes
//
// History:
//		12/25/96 MJR	Started.
//
//		05/12/97	JRD	Turned this into a CTrigger to load the trigger attributes
//
////////////////////////////////////////////////////////////////////////////////

#include "RSPiX.h"
#include "trigger.h"
#include "game.h"
#include "realm.h" 


////////////////////////////////////////////////////////////////////////////////
// Macros/types/etc.
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Variables/data
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Function prototypes
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Constructor
// (protected).
////////////////////////////////////////////////////////////////////////////////
CTrigger::CTrigger(CRealm* pRealm)
	: CThing(pRealm, CTriggerID)
	{
	// Insert a default instance into the realm:
	m_pmgi = NULL;
	m_pRealm->m_pTriggerMapHolder = this;
	m_pRealm->m_pTriggerMap = m_pmgi;

	// Assume we don't know the UID's fdor the pylons yet, so clear them all out:
	for (int16_t i=0;i < 256;i++)
		{
		m_ausPylonUIDs[i] = pRealm->m_asPylonUIDs[i] = 0;
		}
	}

////////////////////////////////////////////////////////////////////////////////
// Destructor
// (public).
////////////////////////////////////////////////////////////////////////////////
CTrigger::~CTrigger()
	{
	if (m_pmgi) delete m_pmgi;
	m_pmgi = NULL;

	// Clear it from the realm:
	m_pRealm->m_pTriggerMap = NULL;
	m_pRealm->m_pTriggerMapHolder = NULL;
	}

////////////////////////////////////////////////////////////////////////////////
// Load object (should call base class version!)
////////////////////////////////////////////////////////////////////////////////
int16_t CTrigger::Load(								// Returns 0 if successfull, non-zero otherwise
	RFile* pFile,									// In:  File to load from
	bool bEditMode,								// In:  True for edit mode, false otherwise
	int16_t sFileCount,								// In:  File count (unique per file, never 0)
	uint32_t	ulFileVersion)							// In:  Version of file format to load.
	{
	int16_t sResult = 0;

	// In most cases, the base class Load() should be called.
	sResult	= CThing::Load(pFile, bEditMode, sFileCount, ulFileVersion);
	if (sResult == 0)
		{
		// Load object data
		m_pRealm->m_pTriggerMap = NULL; // clear the shadow
		// ASSUME THERE WILL ALREADY BE AN EMPTY TRIGGER MAP HOLDER!
		if (m_pRealm->m_pTriggerMapHolder == NULL) m_pRealm->m_pTriggerMapHolder = new CTrigger(m_pRealm);

		if (m_pmgi) delete m_pmgi;
		m_pmgi = NULL;

		int16_t sData = 0;
		pFile->Read(&sData);

		// Was there something here?
		if (sData)
			{
			m_pmgi = new RMultiGridIndirect;
			if (m_pmgi) 
				{
				if (m_pmgi->Load(pFile) != SUCCESS)
					{
					TRACE("CTrigger::Load(): Warning - couldn't load trigger attributes!\n");
					sResult = -1;
					}
				else
					{
					// Load the ID list:
					if (pFile->Read(m_ausPylonUIDs,256) != 256) // Grab the ID's
						{
						TRACE("CTrigger::Load(): Warning - I lost my pylon IDs!\n");
						sResult = -1;
						}
					else
						{
						// Install into the Realm
						m_pRealm->m_pTriggerMapHolder = this;
						m_pRealm->m_pTriggerMap = m_pmgi;
						
						// Copy the Pylons to the realm!
						for (int16_t i=0;i < 256;i++) m_pRealm->m_asPylonUIDs[i] = m_ausPylonUIDs[i];
						}
					}
				}
			}

		// Make sure there were no file errors or format errors . . .
		if (!pFile->Error() && sResult == 0)
			{
			}
		else
			{
			sResult = -1;
			TRACE("CTrigger::Load(): Error reading from file!\n");
			}
		}
	else
		{
		TRACE("CTrigger::Load(): CThing::Load() failed.\n");
		}

	return sResult;
	}


////////////////////////////////////////////////////////////////////////////////
// Save object (should call base class version!)
////////////////////////////////////////////////////////////////////////////////
int16_t CTrigger::Save(								// Returns 0 if successfull, non-zero otherwise
	RFile* pFile,									// In:  File to save to
	int16_t sFileCount)								// In:  File count (unique per file, never 0)
	{
	int16_t	sResult	= 0;

	// In most cases, the base class Save() should be called.
	sResult	= CThing::Save(pFile, sFileCount);
	if (sResult == 0)
		{
		// Save object data
		int16_t sData = 0; // NO DATA

		if (m_pmgi == NULL) 
			{
			sData = 0;
			pFile->Write(sData);
			}
		else
			{
			// There IS an attribute:
			sData = 1;
			pFile->Write(sData);
			if (m_pmgi->Save(pFile) != SUCCESS)
				{
				sResult = -1;
				TRACE("CTrigger::Save(): Error - coudln't save trigger attributes.\n");
				}
			else
				{
				// Save the Pylon Data:
				if (pFile->Write(m_ausPylonUIDs,256) != 256)
					{
					sResult = -1;
					TRACE("CTrigger::Save(): Error - coudln't save Pylon IDs.\n");
					}
				}
			}

		sResult	= pFile->Error();
		if (sResult == 0)
			{
			}
		else
			{
			TRACE("CTrigger::Save(): Error writing to file.\n");
			}
		}
	else
		{
		TRACE("CTrigger::Save(): CThing::Save() failed.\n");
		}

	return sResult;
	}


////////////////////////////////////////////////////////////////////////////////
// Startup object
////////////////////////////////////////////////////////////////////////////////
int16_t CTrigger::Startup(void)								// Returns 0 if successfull, non-zero otherwise
	{
	return 0;
	}


////////////////////////////////////////////////////////////////////////////////
// Shutdown object
////////////////////////////////////////////////////////////////////////////////
int16_t CTrigger::Shutdown(void)							// Returns 0 if successfull, non-zero otherwise
	{
	return 0;
	}


////////////////////////////////////////////////////////////////////////////////
// Suspend object
////////////////////////////////////////////////////////////////////////////////
void CTrigger::Suspend(void)
	{
	}


////////////////////////////////////////////////////////////////////////////////
// Resume object
////////////////////////////////////////////////////////////////////////////////
void CTrigger::Resume(void)
	{
	}


////////////////////////////////////////////////////////////////////////////////
// Update object
////////////////////////////////////////////////////////////////////////////////
void CTrigger::Update(void)
	{
	}


////////////////////////////////////////////////////////////////////////////////
// Render object
////////////////////////////////////////////////////////////////////////////////
void CTrigger::Render(void)
	{
	}


////////////////////////////////////////////////////////////////////////////////
// Called by editor to init new object at specified position
////////////////////////////////////////////////////////////////////////////////
int16_t CTrigger::EditNew(									// Returns 0 if successfull, non-zero otherwise
	int16_t sX,												// In:  New x coord
	int16_t sY,												// In:  New y coord
	int16_t sZ)												// In:  New z coord
	{
	return 0;
	}


////////////////////////////////////////////////////////////////////////////////
// Called by editor to modify object
////////////////////////////////////////////////////////////////////////////////
int16_t CTrigger::EditModify(void)
	{
	return 0;
	}


////////////////////////////////////////////////////////////////////////////////
// Called by editor to move object to specified position
////////////////////////////////////////////////////////////////////////////////
int16_t CTrigger::EditMove(									// Returns 0 if successfull, non-zero otherwise
	int16_t /*sX*/,											// In:  New x coord
	int16_t /*sY*/,											// In:  New y coord
	int16_t /*sZ*/)											// In:  New z coord
	{
	return 0;
	}


////////////////////////////////////////////////////////////////////////////////
// Called by editor to update object
////////////////////////////////////////////////////////////////////////////////
void CTrigger::EditUpdate(void)
	{
	}


////////////////////////////////////////////////////////////////////////////////
// Called by editor to render object
////////////////////////////////////////////////////////////////////////////////
void CTrigger::EditRender(void)
	{
	}

////////////////////////////////////////////////////////////////////////////////
// Add myself into the realm that created me.
////////////////////////////////////////////////////////////////////////////////
void	CTrigger::AddData(RMultiGridIndirect* pmgi)
	{
	m_pRealm->m_pTriggerMap = m_pmgi = pmgi;

	// Copy my Pylon Data into the Realm's:
	for (int16_t i=0;i < 256;i++) m_pRealm->m_asPylonUIDs[i] = m_ausPylonUIDs[i];
	}

////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////