Skip to content

Commit

Permalink
Allow setting propulsion types via chat command
Browse files Browse the repository at this point in the history
Plus more tweaking to this functionality.
  • Loading branch information
KJeff01 committed Aug 3, 2023
1 parent 60022bf commit bc06d89
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
4 changes: 4 additions & 0 deletions data/base/script/campaign/libcampaign_includes/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function cam_eventChat(from, to, message)
camSetExpLevel(Number(message.substring(5)));
camSetOnMapEnemyUnitExp();
}
if (message.lastIndexOf("prop ", 0) === 0)
{
camSetPropulsionTypeLimit(Number(message.substring(5)));
}
if (!camIsCheating())
{
return;
Expand Down
46 changes: 23 additions & 23 deletions data/base/script/campaign/libcampaign_includes/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ function camQueueDroidProduction(playerId, template)

//;; ## camSetPropulsionTypeLimit([limit])
//;;
//;; On hard and insane the propulsion type can be limited with this.
//;; For type II pass in `2`, and for type III pass in `3`. Hard defaults to type II and insane defaults to type III.
//;; If nothing is passed in then the type limit will match what is in templates.json.
//;; This function can automatically augment units to use Type I/II/III propulsions.
//;; If nothing or zero is passed in then the type limit will match what is in templates.json.
//;;
//;; @param {number} [limit]
//;; @returns {void}
Expand All @@ -164,6 +163,10 @@ function camSetPropulsionTypeLimit(limit)
{
__camPropulsionTypeLimit = "NO_USE";
}
else if (limit === 1)
{
__camPropulsionTypeLimit = "01";
}
else if (limit === 2)
{
__camPropulsionTypeLimit = "02";
Expand All @@ -172,6 +175,10 @@ function camSetPropulsionTypeLimit(limit)
{
__camPropulsionTypeLimit = "03";
}
else
{
camTrace("Unknown propulsion level specified. Use 1 - 3 to force the propulsion type, 0 to disable.");
}
}

//;; ## camUpgradeOnMapTemplates(template1, template2, playerId[, excluded])
Expand Down Expand Up @@ -238,7 +245,7 @@ function camUpgradeOnMapTemplates(template1, template2, playerId, excluded)
let droidInfo = {x: dr.x, y: dr.y, name: dr.name};
camSafeRemoveObject(dr, false);
let droid = addDroid(playerId, droidInfo.x, droidInfo.y, droidInfo.name, template2.body,
__camChangePropulsionOnDiff(template2.prop), "", "", template2.weap);
__camChangePropulsionOnDiff(template2.prop, playerId), "", "", template2.weap);
camSetDroidExperience(droid);
}
}
Expand Down Expand Up @@ -297,40 +304,33 @@ function __camAddDroidToFactoryGroup(droid, structure)
__camFactoryUpdateTactics(flabel);
}

function __camChangePropulsionOnDiff(propulsion)
function __camChangePropulsionOnDiff(propulsion, playerId)
{
if (__camPropulsionTypeLimit === "NO_USE")
if (__camPropulsionTypeLimit === "NO_USE" || playerId === CAM_HUMAN_PLAYER)
{
return propulsion; //this mission don't want this feature then
return propulsion;
}

var name = propulsion;
const VALID_PROPS = [
"CyborgLegs", "HalfTrack", "V-Tol", "hover", "tracked", "wheeled",
];
let name = propulsion;
const VALID_PROPS = ["CyborgLegs", "HalfTrack", "V-Tol", "hover", "tracked", "wheeled"];
const SPECPROPS = ["CyborgLegs", "HalfTrack", "V-Tol"]; //Some have "01" at the end and others don't for the base ones.

var lastTwo = name.substring(name.length - 2);
let lastTwo = name.substring(name.length - 2);
if (lastTwo === "01" || lastTwo === "02" || lastTwo === "03")
{
name = name.substring(0, name.length - 2);
}

for (let i = 0, l = VALID_PROPS.length; i < l; ++i)
{
var currentProp = VALID_PROPS[i];
let currentProp = VALID_PROPS[i];
if (name === currentProp)
{
var typeModifier;
//if a future template has a type III and the limit is type II then this will ensure it stays type III.
if (__camPropulsionTypeLimit === "02" && lastTwo === "03")
{
typeModifier = "03";
}
else
if ((__camPropulsionTypeLimit === "01") && (SPECPROPS.indexOf(currentProp) !== -1))
{
typeModifier = __camPropulsionTypeLimit;
return currentProp;
}
return currentProp.concat(typeModifier);
return currentProp.concat(__camPropulsionTypeLimit);
}
}

Expand All @@ -350,7 +350,7 @@ function __camBuildDroid(template, structure)
{
return false;
}
var prop = __camChangePropulsionOnDiff(template.prop);
var prop = __camChangePropulsionOnDiff(template.prop, structure.player);
makeComponentAvailable(template.body, structure.player);
makeComponentAvailable(prop, structure.player);
makeComponentAvailable(template.weap, structure.player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function camSendReinforcement(playerId, position, templates, kind, data)
for (let i = 0, l = templates.length; i < l; ++i)
{
var template = templates[i];
var prop = __camChangePropulsionOnDiff(template.prop);
var prop = __camChangePropulsionOnDiff(template.prop, playerId);
var droid = addDroid(playerId, pos.x, pos.y, "Reinforcement", template.body, prop, "", "", template.weap);
camSetDroidExperience(droid);
droids.push(droid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function __camDispatchTransporterUnsafe()
for (let i = 0, l = list.length; i < l; ++i)
{
var template = list[i];
var prop = __camChangePropulsionOnDiff(template.prop);
var prop = __camChangePropulsionOnDiff(template.prop, player);
var droid = addDroid(player, -1, -1, "Reinforcement", template.body, prop, "", "", template.weap);
droids.push(droid);
addDroidToTransporter(trans, droid);
Expand Down

0 comments on commit bc06d89

Please sign in to comment.