From e7aa1a7e9794dee90bbe893df438439ace73c0e2 Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Sat, 17 Dec 2011 14:29:19 +0100 Subject: [PATCH] Moves implementation of base settings into rules.js script. Handling of 'some base' option is not the same as current, but since few play with that anyway, we can take some time to think about what to do about that. Network sync is handled with an ugly hack for now. --- data/base/multiplay/skirmish/rules.js | 36 +++++-- src/multiopt.cpp | 145 -------------------------- src/qtscriptfuncs.cpp | 20 ++++ 3 files changed, 47 insertions(+), 154 deletions(-) diff --git a/data/base/multiplay/skirmish/rules.js b/data/base/multiplay/skirmish/rules.js index 61eac6c87..548be87b2 100644 --- a/data/base/multiplay/skirmish/rules.js +++ b/data/base/multiplay/skirmish/rules.js @@ -10,15 +10,6 @@ var lastHitTime = 0; function eventGameInit() { - //set up the reticule buttons - addReticuleButton(COMMAND); - addReticuleButton(CANCEL); - addReticuleButton(BUILD); - addReticuleButton(MANUFACTURE); - addReticuleButton(RESEARCH); - addReticuleButton(INTELMAP); - addReticuleButton(DESIGN); - for (var playnum = 0; playnum < maxPlayers; playnum++) { enableStructure("A0CommandCentre", playnum); // make structures available to build @@ -100,6 +91,20 @@ function eventGameInit() { completeResearch(techlist[count], playnum); } + // Keep only some structures for insane AI + hackNetOff(); + var structs = enumStruct(playnum); + for (var i = 0; i < structs.length; i++) + { + var s = structs[i]; + if (playerData[playnum].difficulty != INSANE + || (s.stattype != WALL && s.stattype != DEFENSE && s.stattype != GATE + && s.stattype != RESOURCE_EXTRACTOR)) + { + removeStruct(s); + } + } + hackNetOn(); } else if (baseType == CAMP_BASE) { @@ -108,6 +113,19 @@ function eventGameInit() { completeResearch(techlist[count], playnum); } + // Keep only some structures + hackNetOff(); + var structs = enumStruct(playnum); + for (var i = 0; i < structs.length; i++) + { + var s = structs[i]; + if ((playerData[playnum].difficulty != INSANE && (s.stattype == WALL || s.stattype == DEFENSE)) + || s.stattype == GATE || s.stattype == CYBORG_FACTORY || s.stattype == COMMAND_CONTROL) + { + removeStruct(s); + } + } + hackNetOn(); } else // CAMP_WALLS { diff --git a/src/multiopt.cpp b/src/multiopt.cpp index 7450155bc..efe2bf51c 100644 --- a/src/multiopt.cpp +++ b/src/multiopt.cpp @@ -375,146 +375,6 @@ bool multiTemplateSetup(void) return true; } -// //////////////////////////////////////////////////////////////////////////// -// remove structures from map before campaign play. -static bool cleanMap(UDWORD player) -{ - DROID *psD,*psD2; - STRUCTURE *psStruct; - bool firstFact,firstRes; - - bMultiPlayer = false; - bMultiMessages = false; - - firstFact = true; - firstRes = true; - - switch(game.base) - { - case CAMP_CLEAN: //clean map - psStruct = apsStructLists[player]; - while (psStruct) //strip away structures. - { - if ((psStruct->pStructureType->type != REF_WALL && psStruct->pStructureType->type != REF_WALLCORNER - && psStruct->pStructureType->type != REF_DEFENSE && psStruct->pStructureType->type != REF_GATE - && psStruct->pStructureType->type != REF_RESOURCE_EXTRACTOR) - || NetPlay.players[player].difficulty != DIFFICULTY_INSANE || NetPlay.players[player].allocated) - { - removeStruct(psStruct, true); - psStruct = apsStructLists[player]; //restart,(list may have changed). - } - else - { - psStruct = psStruct->psNext; - } - } - psD = apsDroidLists[player]; // remove all but construction droids. - while(psD) - { - psD2=psD->psNext; - if (psD->droidType != DROID_CONSTRUCT && psD->droidType != DROID_CYBORG_CONSTRUCT) - { - killDroid(psD); - } - psD = psD2; - } - break; - - case CAMP_BASE: //just structs, no walls - psStruct = apsStructLists[player]; - while(psStruct) - { - if (((psStruct->pStructureType->type == REF_WALL || psStruct->pStructureType->type == REF_WALLCORNER - || psStruct->pStructureType->type == REF_DEFENSE || psStruct->pStructureType->type == REF_GATE) - && (NetPlay.players[player].difficulty != DIFFICULTY_INSANE || NetPlay.players[player].allocated)) - || psStruct->pStructureType->type == REF_BLASTDOOR - || psStruct->pStructureType->type == REF_CYBORG_FACTORY - || psStruct->pStructureType->type == REF_COMMAND_CONTROL) - { - removeStruct(psStruct, true); - psStruct= apsStructLists[player]; //restart,(list may have changed). - } - else if( (psStruct->pStructureType->type == REF_FACTORY) - ||(psStruct->pStructureType->type == REF_RESEARCH) - ||(psStruct->pStructureType->type == REF_POWER_GEN)) - { - if(psStruct->pStructureType->type == REF_FACTORY ) - { - if(firstFact == true) - { - firstFact = false; - removeStruct(psStruct, true); - psStruct= apsStructLists[player]; - } - else // don't delete, just rejig! - { - if(((FACTORY*)psStruct->pFunctionality)->capacity != 0) - { - ((FACTORY*)psStruct->pFunctionality)->capacity = 0; - ((FACTORY*)psStruct->pFunctionality)->productionOutput = (UBYTE)((PRODUCTION_FUNCTION*)psStruct->pStructureType->asFuncList[0])->productionOutput; - - psStruct->sDisplay.imd = psStruct->pStructureType->pIMD[0]; - psStruct->body = (UWORD)(structureBody(psStruct)); - - } - psStruct = psStruct->psNext; - } - } - else if(psStruct->pStructureType->type == REF_RESEARCH) - { - if(firstRes == true) - { - firstRes = false; - removeStruct(psStruct, true); - psStruct= apsStructLists[player]; - } - else - { - if(((RESEARCH_FACILITY*)psStruct->pFunctionality)->capacity != 0) - { // downgrade research - ((RESEARCH_FACILITY*)psStruct->pFunctionality)->capacity = 0; - ((RESEARCH_FACILITY*)psStruct->pFunctionality)->researchPoints = ((RESEARCH_FUNCTION*)psStruct->pStructureType->asFuncList[0])->researchPoints; - psStruct->sDisplay.imd = psStruct->pStructureType->pIMD[0]; - psStruct->body = (UWORD)(structureBody(psStruct)); - } - psStruct=psStruct->psNext; - } - } - else if(psStruct->pStructureType->type == REF_POWER_GEN) - { - if(((POWER_GEN*)psStruct->pFunctionality)->capacity != 0) - { // downgrade powergen. - ((POWER_GEN*)psStruct->pFunctionality)->capacity = 0; - - psStruct->sDisplay.imd = psStruct->pStructureType->pIMD[0]; - psStruct->body = (UWORD)(structureBody(psStruct)); - } - structurePowerUpgrade(psStruct); - psStruct=psStruct->psNext; - } - } - - else - { - psStruct=psStruct->psNext; - } - } - break; - - - case CAMP_WALLS: //everything. - break; - default: - debug( LOG_FATAL, "Unknown Campaign Style" ); - abort(); - break; - } - - bMultiPlayer = true; - bMultiMessages = true; - return true; -} - // //////////////////////////////////////////////////////////////////////////// static bool gameInit(void) { @@ -532,11 +392,6 @@ static bool gameInit(void) return true; } - for(player = 0;playerglobalObject().setProperty("_", engine->newFunction(js_translate)); engine->globalObject().setProperty("label", engine->newFunction(js_label)); + // horrible hacks follow -- do not rely on these being present! + engine->globalObject().setProperty("hackNetOff", engine->newFunction(js_hackNetOff)); + engine->globalObject().setProperty("hackNetOn", engine->newFunction(js_hackNetOn)); + // General functions -- geared for use in AI scripts engine->globalObject().setProperty("debug", engine->newFunction(js_debug)); engine->globalObject().setProperty("console", engine->newFunction(js_console));