/* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive Copyright (C) 2005-2007 Warzone Resurrection 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 */ /* * Mechanics.c * * Game world mechanics. * */ /* extra structures required for demo */ //#define DEMO #include "lib/framework/frame.h" #include "mechanics.h" #include "stats.h" #include "structure.h" #include "game.h" #include "power.h" #include "projectile.h" #include "move.h" #include "message.h" #include "deliverance.h" #include "astar.h" #include "visibility.h" BOOL gameStatStart(void); void gameStatEnd(void); /* Initialise the mechanics system */ //BOOL mechInitialise(void) //{ // UBYTE *pFileData; // UDWORD fileSize; /* Initialise the map */ /*if (!loadFile("blank.map", &pFileData, &fileSize)) { return FALSE; } if (!mapLoad(pFileData, fileSize)) { return FALSE; } FREE(pFileData); */ //load all the component stats from the access database /*if (!loadStats()) { return FALSE; }*/ //load the droid Templates /*if (!loadDroidTemplates()) { return FALSE; }*/ /*if (!loadFunctionStats()) { return FALSE; }*/ /*if (!loadStructureStats()) { return FALSE; }*/ /*if (!loadStructureWeapons()) { return FALSE; } if (!loadStructureFunctions()) { return FALSE; }*/ //load the research stats - must have loaded the structure and functions stats first /* if (!loadResearch()) { return FALSE; } */ /*the template weapons and programs should have been read in through the wrf file by now so calculate build points and power points*/ //initTemplatePoints(); DONE IN SAVE GAME NOW SINCE ALWAYS STARTING IN ONE //sets up the initial game stats - what the player's got etc // gameStatStart(); - moved to data.c when stats are loaded from WRF - John. /*set up the Power levels for each player - again this is set up in load game now*/ //initPlayerPower(); // return TRUE; //} /* Shutdown the mechanics system */ BOOL mechShutdown(void) { // UDWORD i; // DROID *psCurr; BASE_OBJECT *psObj, *psNext; /* for(i=0; ipsNext) { FREE(psCurr->pName); if (psCurr->numWeaps > 0) { FREE(psCurr->asWeaps); } if (psCurr->numProgs > 0) { FREE(psCurr->asProgs); } } }*/ for(psObj = psDestroyedObj; psObj; psObj = psNext) { psNext = psObj->psNext; if (psObj->type == OBJ_DROID) { /* FREE(((DROID *)psObj)->pName); if (((DROID *)psObj)->numWeaps > 0) { FREE(((DROID *)psObj)->asWeaps); } if (((DROID *)psObj)->numProgs > 0) { FREE(((DROID *)psObj)->asProgs); }*/ droidRelease((DROID *)psObj); heapFree(psDroidHeap, (DROID *)psObj); } if (psObj->type == OBJ_STRUCTURE) { structureRelease((STRUCTURE *)psObj); heapFree(psStructHeap, (STRUCTURE *)psObj); } if (psObj->type == OBJ_FEATURE) { featureRelease((FEATURE *)psObj); heapFree(psFeatureHeap, (FEATURE *)psObj); } } psDestroyedObj = NULL; //Free the space allocated for the players lists // gameStatEnd(); return TRUE; } // Allocate the list for a component BOOL allocComponentList(COMPONENT_TYPE type, SDWORD number) { SDWORD inc, comp; //allocate the space for the Players' component lists for (inc=0; inc < MAX_PLAYERS; inc++) { apCompLists[inc][type] = (UBYTE *) MALLOC(sizeof(UBYTE) * number); if (apCompLists[inc][type] == NULL) { debug( LOG_ERROR, "Out of memory assigning Player Component Lists" ); abort(); return FALSE; } //initialise the players' lists for (comp=0; comp status = SS_BUILT; builtRes = TRUE; } if (asStructureStats[comp].type == REF_POWER_GEN) { // apStructTypeLists[inc][comp] = AVAILABLE; do { posX = rand()%mapWidth/2+mapWidth/4; posY = rand()%mapHeight/2+mapHeight/4; } while(blockingTile(posX,posY,TER_ALL)); /* psStructure = buildStructure(&asStructureStats[comp], posX << TILE_SHIFT + TILE_UNITS/2, (posY << TILE_SHIFT) + TILE_UNITS/2, inc); */ psStructure = buildStructure(&asStructureStats[comp], posX << TILE_SHIFT, posY << TILE_SHIFT, inc,FALSE); psStructure->status = SS_BUILT; builtGen = TRUE; } if (builtRes & builtGen) { break; } } } #endif //#ifdef DEMO #if 0 for (inc = 1; inc < MAX_PLAYERS; inc++) { pCurrTempl = NULL; for(pTemplate = apsDroidTemplates[0]; pTemplate; pTemplate=pTemplate->psNext) { if (createTemplate(pTemplate, &pNewTempl)) { if (pCurrTempl == NULL) { apsDroidTemplates[inc] = pNewTempl; } else { pCurrTempl->psNext = pNewTempl; } pCurrTempl = pNewTempl; } } } #endif return TRUE; } void gameStatEnd(void) { UDWORD inc; for (inc=0; inc < MAX_PLAYERS; inc++) { //free the component lists FREE(apCompLists[inc][COMP_BODY]); FREE(apCompLists[inc][COMP_BRAIN]); FREE(apCompLists[inc][COMP_PROPULSION]); FREE(apCompLists[inc][COMP_SENSOR]); FREE(apCompLists[inc][COMP_ECM]); FREE(apCompLists[inc][COMP_REPAIRUNIT]); FREE(apCompLists[inc][COMP_CONSTRUCT]); FREE(apCompLists[inc][COMP_WEAPON]); //FREE(apCompLists[inc][COMP_PROGRAM]); //free the structure lists if(apStructTypeLists[inc]) { FREE(apStructTypeLists[inc]); } } } //TEST FUNCTION - MAKE EVERYTHING AVAILABLE void makeAllAvailable(void) { UDWORD comp,i; for(i=0;i