Skip to content

Commit

Permalink
Allow scripts to control whether new designs are allowed. Default off.
Browse files Browse the repository at this point in the history
  • Loading branch information
perim committed Jan 18, 2012
1 parent a51de16 commit 599dddf
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion data/mp/multiplay/skirmish/rules.js
Expand Up @@ -244,7 +244,8 @@ function eventStructureBuilt(struct)
{
if (struct.player == selectedPlayer && struct.type == STRUCTURE && struct.stattype == HQ)
{
setMiniMap(true); // hide minimap if HQ is destroyed
setMiniMap(true); // show minimap
setDesign(true); // permit designs
}
}

Expand All @@ -253,5 +254,6 @@ function eventDestroyed(victim)
if (victim.player == selectedPlayer && victim.type == STRUCTURE && victim.stattype == HQ)
{
setMiniMap(false); // hide minimap if HQ is destroyed
//setDesign(false); // and disallow design
}
}
1 change: 1 addition & 0 deletions src/droiddef.h
Expand Up @@ -119,6 +119,7 @@ struct DROID_TEMPLATE : public BASE_STATS
DROID_TEMPLATE* psNext; ///< Pointer to next template
bool prefab; ///< Not player designed, not saved, never delete or change
bool stored; ///< Stored template
bool enabled; ///< Has been enabled
};

struct PACKAGED_CHECK;
Expand Down
2 changes: 2 additions & 0 deletions src/game.cpp
Expand Up @@ -3669,6 +3669,7 @@ bool gameLoadV(PHYSFS_file* fileHandle, unsigned int version)
}
}
radarPermitted = (bool)powerSaved[0].extractedPower; // nice hack, eh? don't want to break savegames now...
allowDesign = (bool)powerSaved[1].extractedPower; // nice hack, eh? don't want to break savegames now...

return true;
}
Expand Down Expand Up @@ -3748,6 +3749,7 @@ static bool writeGameFile(const char* fileName, SDWORD saveType)
saveGame.power[i].currentPower = getPower(i);
}
saveGame.power[0].extractedPower = radarPermitted; // hideous hack, don't want to break savegames now...
saveGame.power[1].extractedPower = allowDesign; // hideous hack, don't want to break savegames now...

//camera position
disp3d_getView(&(saveGame.currentPlayerPos));
Expand Down
2 changes: 1 addition & 1 deletion src/hci.cpp
Expand Up @@ -6032,7 +6032,7 @@ void intCheckReticuleButtons(void)
ReticuleEnabled[RETBUT_FACTORY].Enabled = editMode;
ReticuleEnabled[RETBUT_RESEARCH].Enabled = false;
ReticuleEnabled[RETBUT_BUILD].Enabled = editMode;
ReticuleEnabled[RETBUT_DESIGN].Enabled = true;
ReticuleEnabled[RETBUT_DESIGN].Enabled = allowDesign;
ReticuleEnabled[RETBUT_INTELMAP].Enabled = true;
ReticuleEnabled[RETBUT_COMMAND].Enabled = false;

Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Expand Up @@ -1271,6 +1271,7 @@ static void initMiscVars(void)

radarOnScreen = true;
radarPermitted = true;
allowDesign = true;
enableConsoleDisplay(true);

setSelectedGroup(UBYTE_MAX);
Expand Down
22 changes: 22 additions & 0 deletions src/qtscriptfuncs.cpp
Expand Up @@ -1580,6 +1580,27 @@ static QScriptValue js_setMiniMap(QScriptContext *context, QScriptEngine *engine
return QScriptValue();
}

//-- \subsection{setDesign(bool)} Whether to allow player to design stuff.
static QScriptValue js_setDesign(QScriptContext *context, QScriptEngine *engine)
{
DROID_TEMPLATE *psCurr;
allowDesign = context->argument(0).toBool();
// Switch on or off future templates
// FIXME: This dual data structure for templates is just plain insane.
for (psCurr = apsDroidTemplates[selectedPlayer]; psCurr != NULL; psCurr = psCurr->psNext)
{
bool researched = researchedTemplate(psCurr, selectedPlayer);
psCurr->enabled = (researched || allowDesign);
}
for (std::list<DROID_TEMPLATE>::iterator i = localTemplates.begin(); i != localTemplates.end(); ++i)
{
psCurr = &*i;
bool researched = researchedTemplate(psCurr, selectedPlayer);
psCurr->enabled = (researched || allowDesign);
}
return QScriptValue();
}

//-- \subsection{addReticuleButton(button type)} Add reticule button. FIXME: This currently only works in tutorial.
static QScriptValue js_addReticuleButton(QScriptContext *context, QScriptEngine *engine)
{
Expand Down Expand Up @@ -1880,6 +1901,7 @@ bool registerFunctions(QScriptEngine *engine)
engine->globalObject().setProperty("enableResearch", engine->newFunction(js_enableResearch));
engine->globalObject().setProperty("setPower", engine->newFunction(js_setPower));
engine->globalObject().setProperty("setTutorialMode", engine->newFunction(js_setTutorialMode));
engine->globalObject().setProperty("setDesign", engine->newFunction(js_setDesign));
engine->globalObject().setProperty("setMiniMap", engine->newFunction(js_setMiniMap));
engine->globalObject().setProperty("addReticuleButton", engine->newFunction(js_addReticuleButton));
engine->globalObject().setProperty("removeReticuleButton", engine->newFunction(js_removeReticuleButton));
Expand Down
6 changes: 5 additions & 1 deletion src/template.cpp
Expand Up @@ -46,6 +46,8 @@ extern DROID_TEMPLATE sDefaultDesignTemplate;
DROID_TEMPLATE *apsDroidTemplates[MAX_PLAYERS];
DROID_TEMPLATE *apsStaticTemplates; // for AIs and scripts

bool allowDesign = true;

static const StringToEnum<DROID_TYPE> map_DROID_TYPE[] =
{
{"PERSON", DROID_PERSON },
Expand Down Expand Up @@ -152,6 +154,7 @@ bool initTemplates()
ini.endGroup();
continue; // next!
}
design.enabled = allowDesign;
addTemplateToList(&design, &apsDroidTemplates[selectedPlayer]);
sendTemplate(selectedPlayer, &design);
localTemplates.push_back(design);
Expand Down Expand Up @@ -274,6 +277,7 @@ DROID_TEMPLATE::DROID_TEMPLATE(LineView line)
, psNext(NULL)
, prefab(false)
, stored(false)
, enabled(true)
// Ignored columns: 6 - but used later to decide whether the template is for human players.
{
std::string name = line.s(0);
Expand Down Expand Up @@ -688,7 +692,7 @@ void fillTemplateList(std::vector<DROID_TEMPLATE *> &pList, STRUCTURE *psFactory
}
}

if (!validTemplateForFactory(psCurr, psFactory) || !researchedTemplate(psCurr, player))
if (!psCurr->enabled || !validTemplateForFactory(psCurr, psFactory) || !researchedTemplate(psCurr, player))
{
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions src/template.h
Expand Up @@ -7,6 +7,8 @@
extern DROID_TEMPLATE *apsDroidTemplates[MAX_PLAYERS];
extern DROID_TEMPLATE *apsStaticTemplates; // for AIs and scripts

extern bool allowDesign;

bool initTemplates();
bool shutdownTemplates();
bool storeTemplates();
Expand Down

0 comments on commit 599dddf

Please sign in to comment.