aboutsummaryrefslogtreecommitdiff
path: root/src/libparsec/obj_clas.cpp
blob: 812bf96d4b755d255a611ebb128a830de01075f6 (plain)
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
/*
 * PARSEC - Object Class Management
 *
 * $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:44 $
 *
 * Orginally written by:
 *   Copyright (c) Markus Hadwiger     <msh@parsec.org>   1996-2000
 *
 *  This program 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.
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */ 

// C library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// compilation flags/debug support
#include "config.h"
#include "debug.h"

// general definitions
#include "general.h"
#include "objstruc.h"
#include "od_class.h"

// global externals
#include "globals.h"
#ifdef PARSEC_SERVER
	#include "e_world_trans.h"
#endif // PARSEC_SERVER

// local module header
#include "obj_clas.h"

// proprietary module headers
#include "obj_cust.h"
#include "obj_type.h"


// flags
//#define ALLOW_ONLY_KNOWN_CLASSES



// fetch object class via name ------------------------------------------------
//
GenObject *OBJ_FetchObjectClass( const char *classname )
{
	ASSERT( classname != NULL );
	ASSERT( NumObjClasses == NumLoadedObjects );

	// scan entire table of object classes
	int classid = 0;
	for ( classid = 0; classid < NumLoadedObjects; classid++ )
		if ( stricmp( ObjectInfo[ classid ].name, classname ) == 0 )
			break;

	if ( classid < NumObjClasses ) {

		ASSERT( ObjClasses[ classid ] != NULL );
		ASSERT( ObjClasses[ classid ]->ObjectClass == (dword)classid );
		return ObjClasses[ classid ];

	} else {

		return NULL;
	}
}


// fetch object class id via name ---------------------------------------------
//
dword OBJ_FetchObjectClassId( const char *classname )
{
	ASSERT( classname != NULL );
	ASSERT( NumObjClasses == NumLoadedObjects );

	// scan entire table of object classes
	for ( int classid = 0; classid < NumLoadedObjects; classid++ )
		if ( stricmp( ObjectInfo[ classid ].name, classname ) == 0 )
			return classid;

	// no object class of this name found
	return CLASS_ID_INVALID;
}


// fetch object class via name or id if already acquired ----------------------
//
GenObject *OBJ_ReacquireObjectClass( dword *classid, const char *classname )
{
	ASSERT( classid != NULL );
	ASSERT( classname != NULL );

	GenObject *classpo = NULL;
	dword tmpclassid   = *classid;

	if ( tmpclassid == CLASS_ID_INVALID ) {
		tmpclassid = OBJ_FetchObjectClassId( classname );
	}
	if ( tmpclassid != CLASS_ID_INVALID ) {
		ASSERT( tmpclassid < (dword)NumObjClasses );
		classpo = ObjClasses[ tmpclassid ];
	}

	*classid = tmpclassid;
	return classpo;
}


// init default values for object class ---------------------------------------
//
PRIVATE
void InitDefaultClassFields( GenObject *classpo, dword classid )
{
	ASSERT( classpo != NULL );
	ASSERT( classid < MAX_DISTINCT_OBJCLASSES );
	ASSERT( classid <= (dword)NumObjClasses );

	//NOTE:
	// ( classid == NumObjClasses ) is allowed since
	// this will occur when a new class is being added.
	// (NumObjClasses will only be increased afterwards.)

	switch ( classid ) {

		case SHIP_CLASS_1:
			break;

		case SHIP_CLASS_2:
			break;

		case SHIP_CLASS_3:
			break;

		case LASER0_CLASS_1:
			break;

		case LASER0_CLASS_2:
			break;

		case LASER1_CLASS_1:
			break;

		case LASER2_CLASS_1:
			break;

		case DUMB_CLASS_1:
			break;

		case GUIDE_CLASS_1:
			break;

		case SWARM_CLASS_1:
			break;

		case ENERGY_EXTRA_CLASS:
			break;

		case DUMB_PACK_CLASS:
			break;

		case GUIDE_PACK_CLASS:
			break;

		case HELIX_DEVICE_CLASS:
			break;

		case LIGHTNING_DEVICE_CLASS:
			break;

		case MINE_PACK_CLASS:
			break;

		case MINE_CLASS_1:
			break;

		case REPAIR_EXTRA_CLASS:
			break;

		case AFTERBURNER_DEVICE_CLASS:
			break;

		case SWARM_PACK_CLASS:
			break;

		case INVISIBILITY_CLASS:
			break;

		case INVULNERABILITY_CLASS:
			break;

		case PHOTON_DEVICE_CLASS:
			break;

		case DECOY_DEVICE_CLASS:
			break;

		case LASERUPGRADE1_CLASS:
			break;

		case LASERUPGRADE2_CLASS:
			break;

#ifdef ALLOW_ONLY_KNOWN_CLASSES

		default:
			PERROR( "unknown object class id: %d.", classid );
#endif

	}
}


// init class member variables to default values ------------------------------
//
void OBJ_InitClass( dword classid )
{
	ASSERT( classid < MAX_DISTINCT_OBJCLASSES );
	ASSERT( classid <= (dword)NumObjClasses );

	GenObject *classpo = ObjClasses[ classid ];

	//NOTE:
	// ( classid == NumObjClasses ) is allowed since
	// this will occur when a new class is being added.
	// (NumObjClasses will only be increased afterwards.)

	//NOTE:
	// distinction between "object classes" and "object types"
	// -------------------------------------------------------
	// different _objclasses_ originate in different object data files;
	// i.e. the list of objects that should be loaded is parsed and each
	// entry is read and inserted into the array containing pointers to
	// all _objclasses_. Thus each object loaded gets a sequentially
	// (in the order encountered in the control file) assigned number,
	// that is, its *objclass_number*. (these numbers are also contained
	// in file "od_class.h" in order to be used by the object control
	// code. If the order of entries in the control file doesn't
	// correspond to this header file then faulty behavior will occur.
	//
	// different objclass does not necessarily mean that objects *behave*
	// differently in the game as it does only mean that geometry and
	// shading data are different. therefore another concept manages
	// *behavior* of objects:
	//
	// an _objtype_ describes how an object should be handled by the
	// engine and also what data structure is used to manage the object
	// in memory. e.g. all objects of the same type are managed by the
	// same data structure and handled equally by the engine.
	//
	// i.e. objectclasses Laser#1..Laser#5 could all be the same type
	// of laser (concerning their behavior) but look differently.
	// The game *always* instantiates _objectclasses_ (as the look of
	// the object has to be determined), their type is determined
	// automatically. (as it is contained in the objectclass structure.)

	if ( ( classpo->ObjectType & TYPENUMBERMASK ) < NUM_DISTINCT_OBJTYPES ) {

		// init default values for object *type*
		OBJ_InitDefaultTypeFields( classpo );

		// init default values for object *class*
		InitDefaultClassFields( classpo, classid );

	} else {

		// init type and class fields for custom type
		OBJ_InitCustomType( classpo );
	}

	// ensure correct clipping when rendering
	// directly from class template
	classpo->CullMask = 0x3f;
}