* turn some macrofunctions into inlines

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1353 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-04-03 16:19:15 +00:00
parent 39b4a1da37
commit 84bfec1742
2 changed files with 332 additions and 321 deletions

View File

@ -101,143 +101,110 @@ static void checkMessages(MSG_VIEWDATA *psViewData);
// ajl modified for netgames
extern UDWORD selectedPlayer;
#define CREATE_MSG(heap, new, msgType) \
if (HEAP_ALLOC(heap, ((void**) new))) \
{ \
(*(new))->type = msgType; \
(*(new))->id = (msgID<<3)|selectedPlayer; \
msgID++; \
}
//void HEAP_ALLOC(OBJ_HEAP* psHeap, void** ppObject)
inline MESSAGE* createMessage(OBJ_HEAP *heap, MESSAGE_TYPE msgType)
{
MESSAGE *newMsg;
// Allocate memory for the message, and on failure return a NULL pointer
if ( !HEAP_ALLOC(heap, ((void**) &newMsg)) )
return NULL;
newMsg->type = msgType;
newMsg->id = (msgID << 3) | selectedPlayer;
msgID++;
return newMsg;
}
/* Add the message to the BOTTOM of the list
* list is a pointer to the message list
* Order is now CAMPAIGN, MISSION, RESEARCH/PROXIMITY
*/
#define ADD_MSG(list, msg, player) \
ASSERT( msg != NULL, \
"addMessage: Invalid message pointer" ); \
if (list[player] == NULL) \
{ \
list[player] = msg; \
} \
else \
{ \
MESSAGE *psCurr, *psPrev; \
switch (msg->type) \
{ \
case MSG_CAMPAIGN: \
/*add to bottom of the list*/ \
for(psCurr = list[player]; psCurr->psNext != NULL; \
psCurr = psCurr->psNext) \
{ \
} \
psCurr->psNext = msg; \
msg->psNext = NULL; \
break; \
case MSG_MISSION: \
/*add it before the first campaign message */ \
for(psCurr = list[player]; psCurr->psNext != NULL && psCurr->type == MSG_CAMPAIGN; \
psCurr = psCurr->psNext) \
{ \
psPrev = psCurr; \
} \
psPrev->psNext = msg; \
msg->psNext = psCurr; \
break; \
case MSG_RESEARCH: \
case MSG_PROXIMITY: \
/*add it before the first mission message */ \
for(psCurr = list[player]; psCurr->psNext != NULL && psCurr->type == MSG_MISSION; \
psCurr = psCurr->psNext) \
{ \
psPrev = psCurr; \
} \
psPrev->psNext = msg; \
msg->psNext = psCurr; \
break; \
} \
}
static void add_msg(MESSAGE *list[MAX_PLAYERS], MESSAGE *msg, UDWORD player)
inline void addMessageToList(MESSAGE *list[MAX_PLAYERS], MESSAGE *msg, UDWORD player)
{
MESSAGE *psCurr = NULL, *psPrev = NULL;
ASSERT( msg != NULL,
"addMessage: Invalid message pointer" );
"addMessageToList: Invalid message pointer" );
// If there is no message list, create one
if (list[player] == NULL)
{
list[player] = msg;
msg->psNext = NULL;
}
else
{
MESSAGE *psCurr, *psPrev;
msg->psNext = NULL;
psCurr = psPrev = NULL;
switch (msg->type)
{
case MSG_CAMPAIGN:
/*add it before the first mission/research/prox message */
for(psCurr = list[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->type == MSG_MISSION ||
psCurr->type == MSG_RESEARCH ||
psCurr->type == MSG_PROXIMITY)
{
break;
}
psPrev = psCurr;
}
if (psPrev)
{
psPrev->psNext = msg;
msg->psNext = psCurr;
}
else
{
//must be top of list
psPrev = list[player];
list[player] = msg;
msg->psNext = psPrev;
}
break;
case MSG_MISSION:
/*add it before the first research/prox message */
for(psCurr = list[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->type == MSG_RESEARCH ||
psCurr->type == MSG_PROXIMITY)
{
break;
}
psPrev = psCurr;
}
if (psPrev)
{
psPrev->psNext = msg;
msg->psNext = psCurr;
}
else
{
//must be top of list
psPrev = list[player];
list[player] = msg;
msg->psNext = psPrev;
}
break;
case MSG_RESEARCH:
case MSG_PROXIMITY:
/*add it to the bottom of the list */
for(psCurr = list[player]; psCurr->psNext != NULL;
psCurr = psCurr->psNext)
{
}
psCurr->psNext = msg;
msg->psNext = NULL;
break;
default:
debug(LOG_ERROR, "add_msg: unknown message type");
break;
}
return;
}
switch (msg->type)
{
case MSG_CAMPAIGN:
/*add it before the first mission/research/prox message */
for(psCurr = list[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->type == MSG_MISSION ||
psCurr->type == MSG_RESEARCH ||
psCurr->type == MSG_PROXIMITY)
break;
psPrev = psCurr;
}
if (psPrev)
{
psPrev->psNext = msg;
msg->psNext = psCurr;
}
else
{
//must be top of list
psPrev = list[player];
list[player] = msg;
msg->psNext = psPrev;
}
break;
case MSG_MISSION:
/*add it before the first research/prox message */
for(psCurr = list[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->type == MSG_RESEARCH ||
psCurr->type == MSG_PROXIMITY)
break;
psPrev = psCurr;
}
if (psPrev)
{
psPrev->psNext = msg;
msg->psNext = psCurr;
}
else
{
//must be top of list
psPrev = list[player];
list[player] = msg;
msg->psNext = psPrev;
}
break;
case MSG_RESEARCH:
case MSG_PROXIMITY:
/*add it to the bottom of the list */
// Iterate to the last item in the list
for(psCurr = list[player]; psCurr->psNext != NULL; psCurr = psCurr->psNext);
// Append the new message to the end of the list
psCurr->psNext = msg;
msg->psNext = NULL;
break;
default:
debug(LOG_ERROR, "addMessageToList: unknown message type");
break;
}
}
@ -247,46 +214,55 @@ static void add_msg(MESSAGE *list[MAX_PLAYERS], MESSAGE *msg, UDWORD player)
* list is a pointer to the message list
* del is a pointer to the message to remove
*/
#define REMOVEMSG(list, heap, del, player) \
ASSERT( del != NULL, \
"removeMessage: Invalid message pointer" ); \
if (list[player] == del) \
{ \
list[player] = list[player]->psNext; \
HEAP_FREE(heap, del); \
} \
else \
{ \
MESSAGE *psPrev = NULL, *psCurr; \
for(psCurr = list[player]; (psCurr != del) && (psCurr != NULL); \
psCurr = psCurr->psNext) \
{ \
psPrev = psCurr; \
} \
ASSERT( psCurr != NULL, \
"removeMessage: message not found" ); \
if (psCurr != NULL) \
{ \
psPrev->psNext = psCurr->psNext; \
HEAP_FREE(heap, del); \
} \
inline void removeMessageFromList(MESSAGE *list[], OBJ_HEAP *heap, MESSAGE *del, UDWORD player)
{
MESSAGE *psPrev = NULL, *psCurr;
ASSERT( del != NULL,
"removeMessageFromList: Invalid message pointer" );
// If the message to remove is the first one in the list then mark the next one as the first
if (list[player] == del)
{
list[player] = list[player]->psNext;
HEAP_FREE(heap, del);
}
#define RELEASEALLMSG(list, heap) \
{ \
UDWORD i; \
MESSAGE *psCurr, *psNext; \
for(i=0; i<MAX_PLAYERS; i++) \
{ \
for(psCurr = list[i]; psCurr != NULL; psCurr = psNext) \
{ \
psNext = psCurr->psNext; \
HEAP_FREE(heap, psCurr); \
} \
list[i] = NULL; \
} \
// Iterate through the list and find the item before the message to delete
for(psCurr = list[player]; (psCurr != del) && (psCurr != NULL); psCurr = psCurr->psNext)
{
psPrev = psCurr;
}
ASSERT( psCurr != NULL,
"removeMessage: message not found in list" );
if (psCurr != NULL)
{
// Modify the "next" pointer of the previous item to
// point to the "next" item of the item to delete.
psPrev->psNext = psCurr->psNext;
HEAP_FREE(heap, del);
}
}
inline void releaseAllMessages(MESSAGE *list[], OBJ_HEAP *heap)
{
UDWORD i;
MESSAGE *psCurr, *psNext;
// Iterate through all players' message lists
for(i=0; i < MAX_PLAYERS; i++)
{
// Iterate through all messages in list
for(psCurr = list[i]; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
HEAP_FREE(heap, psCurr);
}
list[i] = NULL;
}
}
BOOL messageInitVars(void)
{
@ -326,44 +302,42 @@ void viewDataHeapShutDown(void)
}
/*Add a message to the list */
MESSAGE * addMessage(MESSAGE_TYPE msgType, BOOL proxPos, UDWORD player)
{
MESSAGE *psMsgToAdd = NULL;
MESSAGE * addMessage(MESSAGE_TYPE msgType, BOOL proxPos, UDWORD player)
{
//first create a message of the required type
MESSAGE* psMsgToAdd = createMessage(psMsgHeap, msgType);
debug(LOG_WZ, "addMessage: adding message for player %d, type is %d, proximity is %d", player, msgType, proxPos);
debug(LOG_WZ, "addMessage: adding message for player %d, type is %d, proximity is %d", player, msgType, proxPos);
//first create a message of the required type
CREATE_MSG(psMsgHeap, &psMsgToAdd, msgType);
if (!psMsgToAdd)
{
debug(LOG_ERROR, "addMessage: CREATE_MSG failed");
return NULL;
}
//then add to the players' list
//ADD_MSG(apsMessages, psMsgToAdd, player);
add_msg(apsMessages, psMsgToAdd, player);
if (!psMsgToAdd)
{
debug(LOG_ERROR, "addMessage: createMessage failed");
return NULL;
}
//then add to the players' list
addMessageToList(apsMessages, psMsgToAdd, player);
//initialise the message data
psMsgToAdd->player = player;
psMsgToAdd->pViewData = NULL;
//psMsgToAdd->frameNumber = 0;
psMsgToAdd->read = FALSE;
//initialise the message data
psMsgToAdd->player = player;
psMsgToAdd->pViewData = NULL;
//psMsgToAdd->frameNumber = 0;
psMsgToAdd->read = FALSE;
//add a proximity display
if (msgType == MSG_PROXIMITY)
{
addProximityDisplay(psMsgToAdd, proxPos, player);
}
// else
// {
// //make the reticule button flash as long as not prox msg or multiplayer game.
//add a proximity display
if (msgType == MSG_PROXIMITY)
{
addProximityDisplay(psMsgToAdd, proxPos, player);
}
// else
// {
// //make the reticule button flash as long as not prox msg or multiplayer game.
// if (player == selectedPlayer && !bMultiPlayer)
// {
// flashReticuleButton(IDRET_INTEL_MAP);
// }
// }
// }
return psMsgToAdd;
return psMsgToAdd;
}
/* adds a proximity display - holds varaibles that enable the message to be
@ -416,7 +390,7 @@ void removeMessage(MESSAGE *psDel, UDWORD player)
{
removeProxDisp(psDel, player);
}
REMOVEMSG(apsMessages, psMsgHeap, psDel, player);
removeMessageFromList(apsMessages, psMsgHeap, psDel, player);
}
/* remove a proximity display */
@ -456,7 +430,7 @@ void removeProxDisp(MESSAGE *psMessage, UDWORD player)
void freeMessages(void)
{
releaseAllProxDisp();
RELEASEALLMSG(apsMessages, psMsgHeap);
releaseAllMessages(apsMessages, psMsgHeap);
}
/* removes all the proximity displays */

View File

@ -335,145 +335,167 @@ void objmemUpdate(void)
/**************************************************************************************
*
* Macros for the object memory functions
* Inlines for the object memory functions
* The code is the same for the different object types only the pointer types
* change.
*/
/* Creating a new object
* new is a pointer to a pointer to the new object
* type is the type of the object
*/
inline BASE_OBJECT* createObject(UDWORD player, OBJ_HEAP *heap, OBJECT_TYPE objType)
{
BASE_OBJECT* newObject;
// ajl modified for netplaying..
ASSERT(player < MAX_PLAYERS,
"createObject: invalid player number");
#define CREATE(plyr, heap, new, objType, structType) \
ASSERT( plyr<MAX_PLAYERS, "addObject: invalid player number" ); \
if (!HEAP_ALLOC(heap, (void**)new)) \
{ \
return FALSE; \
} \
(*(new))->type = objType; \
(*(new))->id = ((objID<<3)|plyr); \
objID++; \
(*(new))->player = (UBYTE)plyr; \
(*(new))->died = 0; \
return TRUE
if (!HEAP_ALLOC(heap, ((void**) &newObject)))
return NULL;
newObject->type = objType;
newObject->id = (objID << 3) | player;
objID++;
newObject->player = (UBYTE)player;
newObject->died = 0;
return newObject;
}
/* Add the object to its list
* list is a pointer to the object list
* \param list is a pointer to the object list
*/
#define ADD(list, objType, type) \
ASSERT( objType != NULL, \
"addObject: Invalid " #type " pointer" ); \
(objType)->psNext = list[(objType)->player]; \
list[(objType)->player] = (objType)
inline void addObjectToList(BASE_OBJECT *list[], BASE_OBJECT *object)
{
ASSERT(object != NULL,
"addObjectToList: Invalid pointer");
// Prepend the object to the top of the list
object->psNext = list[object->player];
list[object->player] = object;
}
/* Move an object from the active list to the destroyed list.
* list is a pointer to the object list
* del is a pointer to the object to remove
* type is the type of the object
* \param list is a pointer to the object list
* \param del is a pointer to the object to remove
*/
#define _DESTROY(list, del, type) \
ASSERT( del != NULL, \
"destroyObject: Invalid " #type " pointer" ); \
if (list[(del)->player] == (del)) \
{ \
list[(del)->player] = list[(del)->player]->psNext; \
((BASE_OBJECT *)(del))->psNext = psDestroyedObj; \
psDestroyedObj = (BASE_OBJECT *)(del); \
(del)->died = gameTime; \
} \
else \
{ \
type *psPrev=NULL, *psCurr; \
for(psCurr = list[(del)->player]; (psCurr != (del)) && (psCurr != NULL); \
psCurr = psCurr->psNext) \
{ \
psPrev = psCurr; \
} \
ASSERT( psCurr != NULL, \
"destroyObject:" #type " object not found" ); \
if (psCurr != NULL) \
{ \
psPrev->psNext = psCurr->psNext; \
((BASE_OBJECT *)(del))->psNext = psDestroyedObj; \
psDestroyedObj = (BASE_OBJECT *)(del); \
(del)->died = gameTime; \
} \
inline void destroyObject(BASE_OBJECT* list[], BASE_OBJECT* object)
{
BASE_OBJECT *psPrev = NULL, *psCurr;
ASSERT(object != NULL,
"destroyObject: Invalid pointer");
// If the message to remove is the first one in the list then mark the next one as the first
if (list[object->player] == object)
{
list[object->player] = list[object->player]->psNext;
((BASE_OBJECT *)object)->psNext = psDestroyedObj;
psDestroyedObj = (BASE_OBJECT *)object;
object->died = gameTime;
return;
}
// turn off the list integrity check for all builds
//#ifdef DEBUG
#if 0
#define DESTROY(list, del, type) \
_DESTROY(list, del, type); \
objListIntegCheck()
#else
#define DESTROY(list, del, type) \
_DESTROY(list, del, type)
#endif
// Iterate through the list and find the item before the object to delete
for(psCurr = list[object->player]; (psCurr != object) && (psCurr != NULL); psCurr = psCurr->psNext)
{
psPrev = psCurr;
}
ASSERT(psCurr != NULL,
"destroyObject: object not found in list");
if (psCurr != NULL)
{
// Modify the "next" pointer of the previous item to
// point to the "next" item of the item to delete.
psPrev->psNext = psCurr->psNext;
// Prepend the object to the destruction list
((BASE_OBJECT *)object)->psNext = psDestroyedObj;
psDestroyedObj = (BASE_OBJECT *)object;
// Set destruction time
object->died = gameTime;
}
}
/* Remove an object from the active list
* list is a pointer to the object list
* remove is a pointer to the object to remove
* type is the type of the object
* \param list is a pointer to the object list
* \param remove is a pointer to the object to remove
* \param type is the type of the object
*/
#define REMOVE(list, remove, type) \
ASSERT( remove != NULL, \
"removeObject: Invalid " #type " pointer" ); \
if (list[(remove)->player] == (remove)) \
{ \
list[(remove)->player] = list[(remove)->player]->psNext; \
} \
else \
{ \
type *psPrev=NULL, *psCurr; \
for(psCurr = list[(remove)->player]; (psCurr != (remove)) && (psCurr != NULL); \
psCurr = psCurr->psNext) \
{ \
psPrev = psCurr; \
} \
ASSERT( psCurr != NULL, \
"removeObject:" #type " object not found" ); \
if (psCurr != NULL) \
{ \
psPrev->psNext = psCurr->psNext; \
} \
inline void removeObjectFromList(BASE_OBJECT *list[], BASE_OBJECT *object)
{
BASE_OBJECT *psPrev = NULL, *psCurr;
ASSERT( object != NULL,
"removeObjectFromList: Invalid pointer" );
// If the message to remove is the first one in the list then mark the next one as the first
if (list[object->player] == object)
{
list[object->player] = list[object->player]->psNext;
return;
}
// Iterate through the list and find the item before the object to delete
for(psCurr = list[object->player]; (psCurr != object) && (psCurr != NULL); psCurr = psCurr->psNext)
{
psPrev = psCurr;
}
ASSERT( psCurr != NULL,
"removeObjectFromList: object not found in list" );
#define FIND(list, idNum, type) \
{ \
type *psCurr; \
for(psCurr = (list); psCurr != NULL; psCurr = psCurr->psNext) \
{ \
if (psCurr->id == (idNum)) \
{ \
return psCurr; \
} \
} \
return NULL; \
if (psCurr != NULL)
{
// Modify the "next" pointer of the previous item to
// point to the "next" item of the item to delete.
psPrev->psNext = psCurr->psNext;
}
}
inline BASE_OBJECT* findObjectInList(BASE_OBJECT list[], UDWORD idNum)
{
BASE_OBJECT *psCurr;
for(psCurr = list; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->id == (idNum))
{
return psCurr;
}
}
#define RELEASEALL(list, heap, freeFunc, type) \
{ \
UDWORD i; \
type *psCurr, *psNext; \
for(i=0; i<MAX_PLAYERS; i++) \
{ \
for(psCurr = list[i]; psCurr != NULL; psCurr = psNext) \
{ \
psNext = psCurr->psNext; \
freeFunc(psCurr); \
HEAP_FREE(heap, psCurr); \
} \
list[i] = NULL; \
} \
return NULL;
}
// Necessary for a nice looking cast in calls to releaseAllObjectsInList
typedef void (*OBJECT_DESTRUCTOR)(BASE_OBJECT*);
inline void releaseAllObjectsInList(BASE_OBJECT *list[], OBJ_HEAP *heap, OBJECT_DESTRUCTOR objectDestructor)
{
UDWORD i;
BASE_OBJECT *psCurr, *psNext;
// Iterate through all players' object lists
for(i=0; i<MAX_PLAYERS; i++)
{
// Iterate through all objects in list
for(psCurr = list[i]; psCurr != NULL; psCurr = psNext)
{
psNext = psCurr->psNext;
// Call a specialized destruction function
// (will do all cleanup except for releasing memory of object)
objectDestructor(psCurr);
// Release object's memory
HEAP_FREE(heap, psCurr);
}
list[i] = NULL;
}
}
/***************************************************************************************
*
@ -485,7 +507,12 @@ void objmemUpdate(void)
/* Create a new droid */
BOOL createDroid(UDWORD player, DROID **ppsNew)
{
CREATE(player, psDroidHeap, ppsNew, OBJ_DROID, DROID);
*ppsNew = (DROID*)createObject(player, psDroidHeap, OBJ_DROID);
if (*ppsNew == NULL)
return FALSE;
return TRUE;
}
/* add the droid to the Droid Lists */
@ -493,7 +520,7 @@ BOOL createDroid(UDWORD player, DROID **ppsNew)
{
DROID_GROUP *psGroup;
ADD(pList, psDroidToAdd, DROID);
addObjectToList((BASE_OBJECT**)pList, (BASE_OBJECT*)psDroidToAdd);
/*whenever a droid gets added to a list other than the current list
its died flag is set to NOT_CURRENT_LIST so that anything targetting
it will cancel itself - HACK?!*/
@ -520,13 +547,13 @@ void killDroid(DROID *psDel)
"killUnit: pointer is not a unit" );
ASSERT( psDel->player < MAX_PLAYERS,
"killUnit: invalid player for unit" );
DESTROY(apsDroidLists, psDel, DROID);
destroyObject((BASE_OBJECT**)apsDroidLists, (BASE_OBJECT*)psDel);
}
/* Remove all droids */
void freeAllDroids(void)
{
RELEASEALL(apsDroidLists, psDroidHeap, droidRelease, DROID);
releaseAllObjectsInList((BASE_OBJECT**)apsDroidLists, psDroidHeap, (OBJECT_DESTRUCTOR)droidRelease);
}
/*Remove a single Droid from a list*/
@ -536,7 +563,7 @@ void removeDroid(DROID *psDroidToRemove, DROID *pList[MAX_PLAYERS])
"removeUnit: pointer is not a unit" );
ASSERT( psDroidToRemove->player < MAX_PLAYERS,
"removeUnit: invalid player for unit" );
REMOVE(pList, psDroidToRemove, DROID);
removeObjectFromList((BASE_OBJECT**)pList, (BASE_OBJECT*)psDroidToRemove);
/*whenever a droid is removed from the current list its died
flag is set to NOT_CURRENT_LIST so that anything targetting
@ -550,13 +577,13 @@ void removeDroid(DROID *psDroidToRemove, DROID *pList[MAX_PLAYERS])
/*Removes all droids that may be stored in the mission lists*/
void freeAllMissionDroids(void)
{
RELEASEALL(mission.apsDroidLists, psDroidHeap, droidRelease, DROID);
releaseAllObjectsInList((BASE_OBJECT**)mission.apsDroidLists, psDroidHeap, (OBJECT_DESTRUCTOR)droidRelease);
}
/*Removes all droids that may be stored in the limbo lists*/
void freeAllLimboDroids(void)
{
RELEASEALL(apsLimboDroids, psDroidHeap, droidRelease, DROID);
releaseAllObjectsInList((BASE_OBJECT**)apsLimboDroids, psDroidHeap, (OBJECT_DESTRUCTOR)droidRelease);
}
/************************** STRUCTURE *******************************/
@ -564,13 +591,18 @@ void freeAllLimboDroids(void)
/* Create a new structure */
BOOL createStruct(UDWORD player, STRUCTURE **ppsNew)
{
CREATE(player, psStructHeap, ppsNew, OBJ_STRUCTURE, STRUCTURE);
*ppsNew = (STRUCTURE*)createObject(player, psStructHeap, OBJ_STRUCTURE);
if (*ppsNew == NULL)
return FALSE;
return TRUE;
}
/* add the structure to the Structure Lists */
void addStructure(STRUCTURE *psStructToAdd)
{
ADD(apsStructLists, psStructToAdd, STRUCTURE);
addObjectToList((BASE_OBJECT**)apsStructLists, (BASE_OBJECT*)psStructToAdd);
}
/* Destroy a structure */
@ -580,13 +612,13 @@ void killStruct(STRUCTURE *psDel)
"killStruct: pointer is not a droid" );
ASSERT( psDel->player < MAX_PLAYERS,
"killStruct: invalid player for stucture" );
DESTROY(apsStructLists, psDel, STRUCTURE);
destroyObject((BASE_OBJECT**)apsStructLists, (BASE_OBJECT*)psDel);
}
/* Remove heapall structures */
void freeAllStructs(void)
{
RELEASEALL(apsStructLists, psStructHeap, structureRelease, STRUCTURE);
releaseAllObjectsInList((BASE_OBJECT**)apsStructLists, psStructHeap, (OBJECT_DESTRUCTOR)structureRelease);
}
/*Remove a single Structure from a list*/
@ -596,7 +628,7 @@ void removeStructureFromList(STRUCTURE *psStructToRemove, STRUCTURE *pList[MAX_P
"removeStructureFromList: pointer is not a structure" );
ASSERT( psStructToRemove->player < MAX_PLAYERS,
"removeStructureFromList: invalid player for structure" );
REMOVE(pList, psStructToRemove, STRUCTURE);
removeObjectFromList((BASE_OBJECT**)pList, (BASE_OBJECT*)psStructToRemove);
}
/************************** FEATURE *********************************/
@ -604,30 +636,35 @@ void removeStructureFromList(STRUCTURE *psStructToRemove, STRUCTURE *pList[MAX_P
/* Create a new Feature */
BOOL createFeature(FEATURE **ppsNew)
{
CREATE(0, psFeatureHeap, ppsNew, OBJ_FEATURE, FEATURE);
*ppsNew = (FEATURE*)createObject(0, psFeatureHeap, OBJ_FEATURE);
if (*ppsNew == NULL)
return FALSE;
return TRUE;
}
/* add the feature to the Feature Lists */
void addFeature(FEATURE *psFeatureToAdd)
{
ADD(apsFeatureLists, psFeatureToAdd, FEATURE);
addObjectToList((BASE_OBJECT**)apsFeatureLists, (BASE_OBJECT*)psFeatureToAdd);
}
/* Destroy a feature */
// set the player to 0 since features have player = maxplayers+1. This screws up DESTROY
// set the player to 0 since features have player = maxplayers+1. This screws up destroyObject
// it's a bit of a hack, but hey, it works
void killFeature(FEATURE *psDel)
{
ASSERT( psDel->type == OBJ_FEATURE,
"killFeature: pointer is not a feature" );
psDel->player = 0;
DESTROY(apsFeatureLists, psDel, FEATURE);
destroyObject((BASE_OBJECT**)apsFeatureLists, (BASE_OBJECT*)psDel);
}
/* Remove all features */
void freeAllFeatures(void)
{
RELEASEALL(apsFeatureLists, psFeatureHeap, featureRelease, FEATURE);
releaseAllObjectsInList((BASE_OBJECT**)apsFeatureLists, psFeatureHeap, (OBJECT_DESTRUCTOR)featureRelease);
}
/************************** FLAG_POSITION ********************************/