Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix ticket:3133 - Unable to order cyborg engineer production via JS api.

The problem was that a simplified droidType was passed in as a function
parameter to buildDroid(), and those droid types simplified out could not
be built. Solution chosen was to remove the droidType parameter - it is now
unused. Instead, the body stats can set the droid type, allowing us to know
which droid type we mean when we have specified a body component.
  • Loading branch information...
commit 4f030f4b6de8eb6ca9fb422f4b9548ca6127acb8 1 parent 4af3297
@perim perim authored
View
15 data/base/stats/body.ini
@@ -25,6 +25,7 @@ powerOutput = 2000
armourKinetic = 100
armourHeat = 100
designable = false
+droidType = TRANSPORTER
[Superbody]
name = "*Kev's Super Body*"
@@ -67,6 +68,7 @@ powerOutput = 600
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgRkt1Ground]
name = "*CyborgRocket1Ground*"
@@ -81,6 +83,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgFlamerGrd]
name = "*Cyborg Flamer*"
@@ -95,6 +98,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgChain1Ground]
name = "*CyborgChaingun1Ground*"
@@ -109,6 +113,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgCannonGrd]
name = "*Cyborg Cannon*"
@@ -123,6 +128,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CybNXRail1Jmp]
name = "*CybNXRail1Jmp*"
@@ -137,6 +143,7 @@ powerOutput = 675
armourKinetic = 18
armourHeat = 15
designable = false
+droidType = CYBORG
[CybNXPulseLasJmp]
name = "*CybNXPulseLasJ*"
@@ -151,6 +158,7 @@ powerOutput = 675
armourKinetic = 18
armourHeat = 15
designable = false
+droidType = CYBORG
[CybNXMissJmp]
name = "*CybNXMissJmp*"
@@ -165,6 +173,7 @@ powerOutput = 675
armourKinetic = 18
armourHeat = 15
designable = false
+droidType = CYBORG
[CybFlamer01CGrd]
name = "*Cyborg Flamer*"
@@ -179,6 +188,7 @@ powerOutput = 600
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Bod-Rail1]
name = "*Cyb-Bod-Rail1*"
@@ -193,6 +203,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Bod-Las1]
name = "*Cyb-Bod-Las1*"
@@ -207,6 +218,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Bod-Atmiss]
name = "*Cyb-Bod-Atmiss*"
@@ -221,6 +233,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[BusBody]
name = "*School Bus Body*"
@@ -499,4 +512,4 @@ powerOutput = 125
armourKinetic = 1
armourHeat = 1
designable = false
-
+droidType = PERSON
View
14 data/mp/multiplay/script/scavfact.js
@@ -12,7 +12,7 @@ function activateProduction(fac)
// Remind factory to produce
if (structureIdle(fac))
{
- buildDroid(fac, "Trike", "B4body-sml-trike01", "BaBaProp", "", DROID_WEAPON, "bTrikeMG");
+ buildDroid(fac, "Trike", "B4body-sml-trike01", "BaBaProp", null, null, "bTrikeMG");
}
}
@@ -105,12 +105,12 @@ function eventDroidBuilt(droid, fac1)
// We now have switch statements! And we can use the built-in Math library
switch (Math.floor(Math.random() * 10))
{
- case 0: buildDroid(fac1, "Trike", "B4body-sml-trike01", "BaBaProp", "", DROID_WEAPON, "bTrikeMG"); break;
- case 1: buildDroid(fac1, "Buggy", "B3body-sml-buggy01", "BaBaProp", "", DROID_WEAPON, "BuggyMG"); break;
- case 2: buildDroid(fac1, "Jeep", "B2JeepBody", "BaBaProp", "", DROID_WEAPON, "BJeepMG"); break;
- case 3: buildDroid(fac1, "Cannonbus", "BusBody", "BaBaProp", "", DROID_WEAPON, "BusCannon"); break;
- case 4: buildDroid(fac1, "Firebus", "BusBody", "BaBaProp", "", DROID_WEAPON, "BabaFlame"); break;
- default: buildDroid(fac1, "Bloke", "B1BaBaPerson01", "BaBaLegs", "", DROID_PERSON, "BaBaMG"); break;
+ case 0: buildDroid(fac1, "Trike", "B4body-sml-trike01", "BaBaProp", null, null, "bTrikeMG"); break;
+ case 1: buildDroid(fac1, "Buggy", "B3body-sml-buggy01", "BaBaProp", null, null, "BuggyMG"); break;
+ case 2: buildDroid(fac1, "Jeep", "B2JeepBody", "BaBaProp", null, null, "BJeepMG"); break;
+ case 3: buildDroid(fac1, "Cannonbus", "BusBody", "BaBaProp", null, null, "BusCannon"); break;
+ case 4: buildDroid(fac1, "Firebus", "BusBody", "BaBaProp", null, null, "BabaFlame"); break;
+ default: buildDroid(fac1, "Bloke", "B1BaBaPerson01", "BaBaLegs", null, null, "BaBaMG"); break;
}
}
}
View
14 data/mp/multiplay/skirmish/semperfi.js
@@ -65,7 +65,7 @@ function buildAttacker(struct)
"MG2Mk1", // twin mg
"MG1Mk1", // mg, initial weapon
];
- if (!buildDroid(struct, "Ranged Attacker", bodylist, proplist, "", DROID_WEAPON, weaplist, weaplist))
+ if (!buildDroid(struct, "Ranged Attacker", bodylist, proplist, null, null, weaplist, weaplist))
{
debug("Failed to construct new attacker");
}
@@ -84,7 +84,7 @@ function buildTruck(struct)
"hover01", // hover
"wheeled01", // wheels
];
- if (!buildDroid(struct, "Constructor", bodylist, proplist, "", DROID_CONSTRUCT, "Spade1Mk1"))
+ if (!buildDroid(struct, "Constructor", bodylist, proplist, null, null, "Spade1Mk1"))
{
debug("Failed to construct new truck");
}
@@ -93,11 +93,11 @@ function buildTruck(struct)
function buildCyborg(struct)
{
// Cyborg templates are special -- their bodies, legs and weapons are linked. We should fix this one day...
- if (!buildDroid(struct, "Cyborg Thermite", "Cyb-Bod-Thermite", "CyborgLegs", "", DROID_CYBORG, "Cyb-Wpn-Thermite"))
+ if (!buildDroid(struct, "Cyborg Thermite", "Cyb-Bod-Thermite", "CyborgLegs", null, null, "Cyb-Wpn-Thermite"))
{
- if (!buildDroid(struct, "Cyborg Flamer", "CyborgFlamerGrd", "CyborgLegs", "", DROID_CYBORG, "CyborgFlamer01"))
+ if (!buildDroid(struct, "Cyborg Flamer", "CyborgFlamerGrd", "CyborgLegs", null, null, "CyborgFlamer01"))
{
- if (!buildDroid(struct, "Cyborg MG", "CyborgChain1Ground", "CyborgLegs", "", DROID_CYBORG, "CyborgChaingun"))
+ if (!buildDroid(struct, "Cyborg MG", "CyborgChain1Ground", "CyborgLegs", null, null, "CyborgChaingun"))
{
debug("Failed to construct new cyborg");
}
@@ -119,7 +119,7 @@ function buildVTOL(struct)
"Body4ABT", // bug
"Body1REC", // viper
];
- if (!buildDroid(struct, "Bomber", bodylist, "V-Tol", "", DROID_WEAPON, bomblist))
+ if (!buildDroid(struct, "Bomber", bodylist, "V-Tol", null, null, bomblist))
{
debug("Failed to construct new VTOL");
}
@@ -459,7 +459,7 @@ function eventDroidBuilt(droid, struct)
{
var sensorlist = enumBlips(me);
- if (struct)
+ if (struct && structureIdle(struct))
{
if (struct.stattype == FACTORY)
{
View
27 data/mp/stats/body.ini
@@ -25,6 +25,7 @@ powerOutput = 2000
armourKinetic = 20
armourHeat = 9
designable = false
+droidType = TRANSPORTER
[MP-SuperTransportBody]
name = "Super Transport Body"
@@ -39,6 +40,7 @@ powerOutput = 6100
armourKinetic = 200
armourHeat = 200
designable = false
+droidType = TRANSPORTER
[Superbody]
name = "Kev's Super Body"
@@ -81,6 +83,7 @@ powerOutput = 600
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgRkt1Ground]
name = "*CyborgRocket1Ground*"
@@ -95,6 +98,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgFlamerGrd]
name = "*Cyborg Flamer*"
@@ -109,6 +113,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgChain1Ground]
name = "*CyborgChaingun1Ground*"
@@ -123,6 +128,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CyborgCannonGrd]
name = "*Cyborg Cannon*"
@@ -137,6 +143,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[CybNXRail1Jmp]
name = "*CybNXRail1Jmp*"
@@ -151,6 +158,7 @@ powerOutput = 675
armourKinetic = 18
armourHeat = 15
designable = false
+droidType = CYBORG
[CybNXPulseLasJmp]
name = "*CybNXPulseLasJ*"
@@ -165,6 +173,7 @@ powerOutput = 675
armourKinetic = 18
armourHeat = 15
designable = false
+droidType = CYBORG
[CybNXMissJmp]
name = "*CybNXMissJmp*"
@@ -179,6 +188,7 @@ powerOutput = 675
armourKinetic = 18
armourHeat = 15
designable = false
+droidType = CYBORG
[CybFlamer01CGrd]
name = "*Cyborg Flamer*"
@@ -193,6 +203,7 @@ powerOutput = 600
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Hvybod-TK]
name = "Super Tank-Killer Cyborg"
@@ -207,6 +218,7 @@ powerOutput = 500
armourKinetic = 15
armourHeat = 8
designable = false
+droidType = CYBORG_SUPER
[Cyb-Hvybod-RailGunner]
name = "Super Rail-Gunner"
@@ -221,6 +233,7 @@ powerOutput = 500
armourKinetic = 15
armourHeat = 8
designable = false
+droidType = CYBORG_SUPER
[Cyb-Hvybod-PulseLsr]
name = "Super Pulse Laser Cyborg"
@@ -235,6 +248,7 @@ powerOutput = 500
armourKinetic = 15
armourHeat = 8
designable = false
+droidType = CYBORG_SUPER
[Cyb-Hvybod-Mcannon]
name = "Super Heavy-Gunner"
@@ -249,6 +263,7 @@ powerOutput = 500
armourKinetic = 15
armourHeat = 8
designable = false
+droidType = CYBORG_SUPER
[Cyb-Hvybod-HPV]
name = "Super HPV Cyborg"
@@ -263,6 +278,7 @@ powerOutput = 500
armourKinetic = 15
armourHeat = 8
designable = false
+droidType = CYBORG_SUPER
[Cyb-Hvybod-Acannon]
name = "Super Auto-Cannon Cyborg"
@@ -277,6 +293,7 @@ powerOutput = 500
armourKinetic = 15
armourHeat = 8
designable = false
+droidType = CYBORG_SUPER
[Cyb-Hvybod-A-T]
name = "Super Scourge Cyborg"
@@ -291,6 +308,7 @@ powerOutput = 500
armourKinetic = 15
armourHeat = 8
designable = false
+droidType = CYBORG_SUPER
[Cyb-Bod-Thermite]
name = "*Thermite Body*"
@@ -305,6 +323,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Bod-Rail1]
name = "*Cyb-Bod-Rail1*"
@@ -319,6 +338,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Bod-Mechanic]
name = "*Cyborg Mechanic*"
@@ -333,6 +353,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG_REPAIR
[Cyb-Bod-Las1]
name = "*Cyb-Bod-Las1*"
@@ -347,6 +368,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Bod-Grenade]
name = "*Grenadier Body*"
@@ -361,6 +383,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[Cyb-Bod-ComEng]
name = "*Combat Engineer*"
@@ -375,6 +398,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG_CONSTRUCT
[Cyb-Bod-Atmiss]
name = "*Cyb-Bod-Atmiss*"
@@ -389,6 +413,7 @@ powerOutput = 500
armourKinetic = 12
armourHeat = 6
designable = false
+droidType = CYBORG
[BusBody]
name = "*School Bus Body*"
@@ -697,4 +722,4 @@ powerOutput = 125
armourKinetic = 1
armourHeat = 1
designable = false
-
+droidType = PERSON
View
22 src/droiddef.h
@@ -56,28 +56,6 @@
//used to get a location next to a droid - withinh one tile
#define LOOK_NEXT_TO_DROID 8
-
-/* The different types of droid */
-// NOTE, if you add to, or change this list then you'll need
-// to update the DroidSelectionWeights lookup table in Display.c
-enum DROID_TYPE
-{
- DROID_WEAPON, ///< Weapon droid
- DROID_SENSOR, ///< Sensor droid
- DROID_ECM, ///< ECM droid
- DROID_CONSTRUCT, ///< Constructor droid
- DROID_PERSON, ///< person
- DROID_CYBORG, ///< cyborg-type thang
- DROID_TRANSPORTER, ///< guess what this is!
- DROID_COMMAND, ///< Command droid
- DROID_REPAIR, ///< Repair droid
- DROID_DEFAULT, ///< Default droid
- DROID_CYBORG_CONSTRUCT, ///< cyborg constructor droid - new for update 28/5/99
- DROID_CYBORG_REPAIR, ///< cyborg repair droid - new for update 28/5/99
- DROID_CYBORG_SUPER, ///< cyborg repair droid - new for update 7/6/99
- DROID_ANY, ///< Any droid. Only used as a parameter for intGotoNextDroidType(DROID_TYPE).
-};
-
struct COMPONENT
{
UBYTE nStat; ///< Allowing a maximum of 255 stats per file
View
102 src/qtscriptfuncs.cpp
@@ -786,7 +786,7 @@ static int get_first_available_component(STRUCTURE *psFactory, const QScriptValu
QString compName = list.property(k).toString();
int result = getCompFromName(type, compName.toUtf8().constData());
if (result >= 0 && apCompLists[player][type][result] == AVAILABLE
- && (asBodyStats[result].size <= capacity || type != COMP_BODY))
+ && (type != COMP_BODY || asBodyStats[result].size <= capacity))
{
return result; // found one!
}
@@ -800,7 +800,7 @@ static int get_first_available_component(STRUCTURE *psFactory, const QScriptValu
{
int result = getCompFromName(type, list.toString().toUtf8().constData());
if (result >= 0 && apCompLists[player][type][result] == AVAILABLE
- && (asBodyStats[result].size <= capacity || type != COMP_BODY))
+ && (type != COMP_BODY || asBodyStats[result].size <= capacity))
{
return result; // found it!
}
@@ -812,15 +812,16 @@ static int get_first_available_component(STRUCTURE *psFactory, const QScriptValu
return -1; // no available component found in list
}
-//-- \subsection{buildDroid(factory, name, body, propulsion, reserved, droid type, turrets...)}
+//-- \subsection{buildDroid(factory, name, body, propulsion, reserved, reserved, turrets...)}
//-- Start factory production of new droid with the given name, body, propulsion and turrets.
-//-- The reserved parameter should be passed an empty string for now. The components can be
+//-- The reserved parameter should be passed \emph{null} for now. The components can be
//-- passed as ordinary strings, or as a list of strings. If passed as a list, the first available
-//-- component in the list will be used. The droid type must be set to match the type of turret
-//-- passed in.
+//-- component in the list will be used. The second reserved parameter used to be a droid type.
+//-- It is now unused and should be passed \emph{null}.
// TODO - fix memory leaks
static QScriptValue js_buildDroid(QScriptContext *context, QScriptEngine *engine)
{
+ const int firstTurret = 6; // index position of first turret parameter
QScriptValue structVal = context->argument(0);
int id = structVal.property("id").toInt32();
int player = structVal.property("player").toInt32();
@@ -830,9 +831,8 @@ static QScriptValue js_buildDroid(QScriptContext *context, QScriptEngine *engine
|| psStruct->pStructureType->type == REF_VTOL_FACTORY), "Structure %s is not a factory", objInfo(psStruct));
QString templName = context->argument(1).toString();
DROID_TEMPLATE *psTemplate = new DROID_TEMPLATE;
- DROID_TYPE droidType = (DROID_TYPE)context->argument(5).toInt32();
- int numTurrets = context->argumentCount() - 6; // anything beyond first six parameters, are turrets
- COMPONENT_TYPE compType = COMP_NUMCOMPONENTS;
+ int numTurrets = context->argumentCount() - firstTurret; // anything beyond first six parameters, are turrets
+ int result;
memset(psTemplate->asParts, 0, sizeof(psTemplate->asParts)); // reset to defaults
memset(psTemplate->asWeaps, 0, sizeof(psTemplate->asWeaps));
@@ -855,63 +855,79 @@ static QScriptValue js_buildDroid(QScriptContext *context, QScriptEngine *engine
psTemplate->numWeaps = 0;
numTurrets = MIN(numTurrets, asBodyStats[body].weaponSlots); // Restrict max no. turrets
- for (int i = 0; i < numTurrets; i++)
+ if (asBodyStats[body].droidTypeOverride != DROID_ANY)
{
- context->argument(6 + i).toString();
- int j;
- switch (droidType)
+ psTemplate->droidType = asBodyStats[body].droidTypeOverride; // set droidType based on body
+ }
+ // Find first turret component type (assume every component in list is same type)
+ QString compName;
+ if (context->argument(firstTurret).isArray())
+ {
+ compName = context->argument(firstTurret).property(0).toString();
+ }
+ else // must be string
+ {
+ compName = context->argument(firstTurret).toString();
+ }
+ if ((result = getCompFromName(COMP_WEAPON, compName.toUtf8().constData())) >= 0)
+ {
+ for (int i = 0; i < numTurrets; i++) // may be multi-weapon
{
- case DROID_PERSON:
- case DROID_WEAPON:
- case DROID_CYBORG:
- case DROID_TRANSPORTER:
- case DROID_DEFAULT:
- case DROID_CYBORG_SUPER:
- j = get_first_available_component(psStruct, context->argument(6 + i), COMP_WEAPON);
- if (j < 0)
+ result = get_first_available_component(psStruct, context->argument(firstTurret + i), COMP_WEAPON);
+ if (result < 0)
{
debug(LOG_SCRIPT, "Wanted to build %s at %s, but no weapon unavailable",
templName.toUtf8().constData(), objInfo(psStruct));
return QScriptValue(false);
}
- psTemplate->asWeaps[i] = j;
+ psTemplate->asWeaps[i] = result;
psTemplate->numWeaps++;
- continue;
- case DROID_CYBORG_CONSTRUCT:
- case DROID_CONSTRUCT:
+ }
+ }
+ else
+ {
+ COMPONENT_TYPE compType = COMP_NUMCOMPONENTS;
+
+ if ((result = getCompFromName(COMP_CONSTRUCT, compName.toUtf8().constData())) >= 0)
+ {
compType = COMP_CONSTRUCT;
- break;
- case DROID_COMMAND:
+ }
+ else if ((result = getCompFromName(COMP_BRAIN, compName.toUtf8().constData())) >= 0)
+ {
compType = COMP_BRAIN;
psTemplate->numWeaps = 1; // hack, necessary to pass intValidTemplate
- break;
- case DROID_REPAIR:
- case DROID_CYBORG_REPAIR:
+ }
+ else if ((result = getCompFromName(COMP_REPAIRUNIT, compName.toUtf8().constData())) >= 0)
+ {
compType = COMP_REPAIRUNIT;
- break;
- case DROID_ECM:
+ }
+ else if ((result = getCompFromName(COMP_ECM, compName.toUtf8().constData())) >= 0)
+ {
compType = COMP_ECM;
- break;
- case DROID_SENSOR:
+ }
+ else if ((result = getCompFromName(COMP_SENSOR, compName.toUtf8().constData())) >= 0)
+ {
compType = COMP_SENSOR;
- break;
- case DROID_ANY:
- break; // wtf
}
- j = get_first_available_component(psStruct, context->argument(6 + i), compType);
- if (j < 0)
+ else
{
- debug(LOG_SCRIPT, "Wanted to build %s at %s, but turret unavailable",
+ debug(LOG_ERROR, "No known component type found for %s", compName.toUtf8().constData());
+ return QScriptValue(false);
+ }
+ result = get_first_available_component(psStruct, context->argument(firstTurret), compType);
+ if (result < 0)
+ {
+ debug(LOG_SCRIPT, "Wanted to build %s at %s, but turret unavailable",
templName.toUtf8().constData(), objInfo(psStruct));
return QScriptValue(false);
}
- psTemplate->asParts[compType] = j;
+ psTemplate->asParts[compType] = result;
}
- psTemplate->droidType = droidType; // may be overwritten by the call below
bool valid = intValidTemplate(psTemplate, templName.toUtf8().constData(), true);
if (valid)
{
- SCRIPT_ASSERT(context, validTemplateForFactory(psTemplate, psStruct), "Invalid template %s for factory %s",
+ SCRIPT_ASSERT(context, validTemplateForFactory(psTemplate, psStruct, true),
+ "Invalid template %s for factory %s",
psTemplate->aName, psStruct->pStructureType->pName);
// Delete similar template from existing list before adding this one
for (int j = 0; j < apsTemplateList.size(); j++)
View
2  src/scriptai.cpp
@@ -1395,7 +1395,7 @@ bool scrSkCanBuildTemplate(void)
}
// is factory big enough?
- if(!validTemplateForFactory(psTempl, psStructure) )
+ if (!validTemplateForFactory(psTempl, psStructure, false))
{
goto failTempl;
}
View
2  src/scriptfuncs.cpp
@@ -1586,7 +1586,7 @@ bool scrBuildDroid(void)
psFactory->pStructureType->type == REF_CYBORG_FACTORY ||
psFactory->pStructureType->type == REF_VTOL_FACTORY),
"Structure is not a factory");
- ASSERT_OR_RETURN(false, validTemplateForFactory(psTemplate, psFactory), "Invalid template - %s for factory - %s",
+ ASSERT_OR_RETURN(false, validTemplateForFactory(psTemplate, psFactory, true), "Invalid template - %s for factory - %s",
psTemplate->aName, psFactory->pStructureType->pName);
if (productionRun != 1)
View
26 src/stats.cpp
@@ -1018,6 +1018,32 @@ bool loadBodyStats(const char *pFileName)
psStats->armourValue[WC_KINETIC] = ini.value("armourKinetic").toInt();
psStats->armourValue[WC_HEAT] = ini.value("armourHeat").toInt();
psStats->designable = ini.value("designable").toBool();
+ QString dtype = ini.value("droidType", "DROID").toString();
+ psStats->droidTypeOverride = DROID_DEFAULT;
+ if (dtype.compare("PERSON") == 0)
+ {
+ psStats->droidTypeOverride = DROID_PERSON;
+ }
+ else if (dtype.compare("TRANSPORTER") == 0)
+ {
+ psStats->droidTypeOverride = DROID_TRANSPORTER;
+ }
+ else if (dtype.compare("CYBORG") == 0)
+ {
+ psStats->droidTypeOverride = DROID_CYBORG;
+ }
+ else if (dtype.compare("CYBORG_SUPER") == 0)
+ {
+ psStats->droidTypeOverride = DROID_CYBORG_SUPER;
+ }
+ else if (dtype.compare("CYBORG_CONSTRUCT") == 0)
+ {
+ psStats->droidTypeOverride = DROID_CYBORG_CONSTRUCT;
+ }
+ else if (dtype.compare("CYBORG_REPAIR") == 0)
+ {
+ psStats->droidTypeOverride = DROID_CYBORG_REPAIR;
+ }
psStats->ref = REF_BODY_START + i;
if (!getBodySize(ini.value("size").toString().toUtf8().constData(), &psStats->size))
{
View
22 src/statsdef.h
@@ -29,6 +29,27 @@
#include <vector>
#include <algorithm>
+/* The different types of droid */
+// NOTE, if you add to, or change this list then you'll need
+// to update the DroidSelectionWeights lookup table in Display.c
+enum DROID_TYPE
+{
+ DROID_WEAPON, ///< Weapon droid
+ DROID_SENSOR, ///< Sensor droid
+ DROID_ECM, ///< ECM droid
+ DROID_CONSTRUCT, ///< Constructor droid
+ DROID_PERSON, ///< person
+ DROID_CYBORG, ///< cyborg-type thang
+ DROID_TRANSPORTER, ///< guess what this is!
+ DROID_COMMAND, ///< Command droid
+ DROID_REPAIR, ///< Repair droid
+ DROID_DEFAULT, ///< Default droid
+ DROID_CYBORG_CONSTRUCT, ///< cyborg constructor droid - new for update 28/5/99
+ DROID_CYBORG_REPAIR, ///< cyborg repair droid - new for update 28/5/99
+ DROID_CYBORG_SUPER, ///< cyborg repair droid - new for update 7/6/99
+ DROID_ANY, ///< Any droid. Used as a parameter for various stuff.
+};
+
static inline bool stringToEnumSortFunction(std::pair<char const *, unsigned> const &a, std::pair<char const *, unsigned> const &b) { return strcmp(a.first, b.first) < 0; }
template <typename STATS>
static inline STATS *findStatsByName(std::string const &name, STATS *asStats, unsigned numStats)
@@ -504,6 +525,7 @@ struct BODY_STATS : public COMPONENT_STATS
BODY_SIZE size; ///< How big the body is - affects how hit
UDWORD weaponSlots; ///< The number of weapon slots on the body
UDWORD armourValue[WC_NUM_WEAPON_CLASSES]; ///< A measure of how much protection the armour provides. Cross referenced with the weapon types.
+ DROID_TYPE droidTypeOverride; // if not DROID_ANY, sets droid type
// A measure of how much energy the power plant outputs
UDWORD powerOutput; ///< this is the engine output of the body
View
11 src/structure.cpp
@@ -5723,14 +5723,17 @@ void printStructureInfo(STRUCTURE *psStructure)
/*Checks the template type against the factory type - returns false
if not a good combination!*/
-bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory)
+bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory, bool complain)
{
+ enum code_part level = complain ? LOG_ERROR : LOG_NEVER;
+
//not in multiPlayer! - AB 26/5/99
if (!bMultiPlayer)
{
//ignore Transporter Droids
if (psTemplate->droidType == DROID_TRANSPORTER)
{
+ debug(level, "Cannot build transporter in campaign.");
return false;
}
}
@@ -5743,6 +5746,7 @@ bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory)
{
if (psFactory->pStructureType->type != REF_CYBORG_FACTORY)
{
+ debug(level, "Cannot build cyborg except in cyborg factory, not in %s.", objInfo(psFactory));
return false;
}
}
@@ -5752,6 +5756,7 @@ bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory)
{
if (psFactory->pStructureType->type != REF_VTOL_FACTORY)
{
+ debug(level, "Cannot build vtol except in vtol factory, not in %s.", objInfo(psFactory));
return false;
}
}
@@ -5759,12 +5764,13 @@ bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory)
//check if cyborg factory
if (psFactory->pStructureType->type == REF_CYBORG_FACTORY)
{
- //if (psTemplate->droidType != DROID_CYBORG)
if (!(psTemplate->droidType == DROID_CYBORG ||
psTemplate->droidType == DROID_CYBORG_SUPER ||
psTemplate->droidType == DROID_CYBORG_CONSTRUCT ||
psTemplate->droidType == DROID_CYBORG_REPAIR))
{
+ debug(level, "Can only build cyborg in cyborg factory, not droidType %d in %s.",
+ psTemplate->droidType, objInfo(psFactory));
return false;
}
}
@@ -5774,6 +5780,7 @@ bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory)
if (!psTemplate->asParts[COMP_PROPULSION] ||
((asPropulsionStats + psTemplate->asParts[COMP_PROPULSION])->propulsionType != PROPULSION_TYPE_LIFT))
{
+ debug(level, "Can only build vtol in vtol factory, not in %s.", objInfo(psFactory));
return false;
}
}
View
2  src/structure.h
@@ -258,7 +258,7 @@ extern void printStructureInfo(STRUCTURE *psStructure);
/*Checks the template type against the factory type - returns false
if not a good combination!*/
-extern bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory);
+extern bool validTemplateForFactory(DROID_TEMPLATE *psTemplate, STRUCTURE *psFactory, bool complain);
/*calculates the damage caused to the resistance levels of structures*/
//extern bool electronicDamage(STRUCTURE *psStructure, UDWORD damage, UBYTE attackPlayer);
View
3  src/template.cpp
@@ -691,7 +691,8 @@ void fillTemplateList(std::vector<DROID_TEMPLATE *> &pList, STRUCTURE *psFactory
}
}
- if (!psCurr->enabled || !validTemplateForFactory(psCurr, psFactory) || !researchedTemplate(psCurr, player))
+ if (!psCurr->enabled || !validTemplateForFactory(psCurr, psFactory, false)
+ || !researchedTemplate(psCurr, player))
{
continue;
}
Please sign in to comment.
Something went wrong with that request. Please try again.