Update the fast-actions cheat and AI bonuses to use the modifiers manager
This deletes custom-code and shows how to use this system component for triggers. Differential Revision: https://code.wildfiregames.com/D1011 This was SVN commit r22964.
This commit is contained in:
parent
d1bcce55db
commit
026ce76e3f
@ -44,9 +44,7 @@ Cost.prototype.GetPopBonus = function()
|
||||
|
||||
Cost.prototype.GetBuildTime = function()
|
||||
{
|
||||
var cmpPlayer = QueryOwnerInterface(this.entity);
|
||||
var buildTime = (+this.template.BuildTime) * cmpPlayer.GetTimeMultiplier();
|
||||
return ApplyValueModificationsToEntity("Cost/BuildTime", buildTime, this.entity);
|
||||
return ApplyValueModificationsToEntity("Cost/BuildTime", +this.template.BuildTime, this.entity);
|
||||
};
|
||||
|
||||
Cost.prototype.GetResourceCosts = function(owner)
|
||||
|
@ -96,9 +96,7 @@ Pack.prototype.CancelPack = function()
|
||||
|
||||
Pack.prototype.GetPackTime = function()
|
||||
{
|
||||
let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
|
||||
|
||||
return ApplyValueModificationsToEntity("Pack/Time", +this.template.Time, this.entity) * cmpPlayer.GetTimeMultiplier();
|
||||
return ApplyValueModificationsToEntity("Pack/Time", +this.template.Time, this.entity);
|
||||
};
|
||||
|
||||
Pack.prototype.GetElapsedTime = function()
|
||||
|
@ -64,11 +64,7 @@ Player.prototype.Init = function()
|
||||
this.startCam = undefined;
|
||||
this.controlAllUnits = false;
|
||||
this.isAI = false;
|
||||
this.timeMultiplier = 1;
|
||||
this.gatherRateMultiplier = 1;
|
||||
this.tradeRateMultiplier = 1;
|
||||
this.cheatsEnabled = false;
|
||||
this.cheatTimeMultiplier = 1;
|
||||
this.panelEntities = [];
|
||||
this.resourceNames = {};
|
||||
this.disabledTemplates = {};
|
||||
@ -224,21 +220,6 @@ Player.prototype.GetBarterMultiplier = function()
|
||||
return this.barterMultiplier;
|
||||
};
|
||||
|
||||
Player.prototype.GetGatherRateMultiplier = function()
|
||||
{
|
||||
return this.gatherRateMultiplier / this.cheatTimeMultiplier;
|
||||
};
|
||||
|
||||
Player.prototype.GetTimeMultiplier = function()
|
||||
{
|
||||
return this.timeMultiplier * this.cheatTimeMultiplier;
|
||||
};
|
||||
|
||||
Player.prototype.GetTradeRateMultiplier = function()
|
||||
{
|
||||
return this.tradeRateMultiplier;
|
||||
};
|
||||
|
||||
Player.prototype.GetSpyCostMultiplier = function()
|
||||
{
|
||||
return this.spyCostMultiplier;
|
||||
@ -247,22 +228,6 @@ Player.prototype.GetSpyCostMultiplier = function()
|
||||
/**
|
||||
* Setters currently used by the AI to set the difficulty level
|
||||
*/
|
||||
Player.prototype.SetGatherRateMultiplier = function(value)
|
||||
{
|
||||
this.gatherRateMultiplier = value;
|
||||
Engine.BroadcastMessage(MT_MultiplierChanged, { "player": this.playerID, "type": "gather" });
|
||||
};
|
||||
|
||||
Player.prototype.SetTimeMultiplier = function(value)
|
||||
{
|
||||
this.timeMultiplier = value;
|
||||
Engine.BroadcastMessage(MT_MultiplierChanged, { "player": this.playerID, "type": "time" });
|
||||
};
|
||||
|
||||
Player.prototype.SetTradeRateMultiplier = function(value)
|
||||
{
|
||||
this.tradeRateMultiplier = value;
|
||||
};
|
||||
|
||||
Player.prototype.GetPanelEntities = function()
|
||||
{
|
||||
@ -845,17 +810,6 @@ Player.prototype.GetCheatsEnabled = function()
|
||||
return this.cheatsEnabled;
|
||||
};
|
||||
|
||||
Player.prototype.SetCheatTimeMultiplier = function(time)
|
||||
{
|
||||
this.cheatTimeMultiplier = time;
|
||||
Engine.BroadcastMessage(MT_MultiplierChanged, { "player": this.playerID, "type": "cheat" });
|
||||
};
|
||||
|
||||
Player.prototype.GetCheatTimeMultiplier = function()
|
||||
{
|
||||
return this.cheatTimeMultiplier;
|
||||
};
|
||||
|
||||
Player.prototype.TributeResource = function(player, amounts)
|
||||
{
|
||||
var cmpPlayer = QueryPlayerIDInterface(player);
|
||||
|
@ -335,7 +335,7 @@ ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat
|
||||
|
||||
let template = TechnologyTemplates.Get(templateName);
|
||||
let techCostMultiplier = this.GetTechCostMultiplier();
|
||||
let time = techCostMultiplier.time * template.researchTime * cmpPlayer.GetTimeMultiplier();
|
||||
let time = techCostMultiplier.time * template.researchTime;
|
||||
|
||||
let cost = {};
|
||||
for (let res in template.cost)
|
||||
@ -498,12 +498,8 @@ ProductionQueue.prototype.ResetQueue = function()
|
||||
*/
|
||||
ProductionQueue.prototype.GetBatchTime = function(batchSize)
|
||||
{
|
||||
var cmpPlayer = QueryOwnerInterface(this.entity);
|
||||
|
||||
var batchTimeModifier = ApplyValueModificationsToEntity("ProductionQueue/BatchTimeModifier", +this.template.BatchTimeModifier, this.entity);
|
||||
|
||||
// TODO: work out what equation we should use here.
|
||||
return Math.pow(batchSize, batchTimeModifier) * cmpPlayer.GetTimeMultiplier();
|
||||
return Math.pow(batchSize, ApplyValueModificationsToEntity("ProductionQueue/BatchTimeModifier", +this.template.BatchTimeModifier, this.entity));
|
||||
};
|
||||
|
||||
ProductionQueue.prototype.OnOwnershipChanged = function(msg)
|
||||
|
@ -101,9 +101,7 @@ ResourceGatherer.prototype.GetLastCarriedType = function()
|
||||
// Since this code is very performancecritical and applying technologies quite slow, cache it.
|
||||
ResourceGatherer.prototype.RecalculateGatherRatesAndCapacities = function()
|
||||
{
|
||||
let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
|
||||
let multiplier = cmpPlayer ? cmpPlayer.GetGatherRateMultiplier() : 1;
|
||||
this.baseSpeed = multiplier * ApplyValueModificationsToEntity("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity);
|
||||
this.baseSpeed = ApplyValueModificationsToEntity("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity);
|
||||
|
||||
this.rates = {};
|
||||
for (let r in this.template.Rates)
|
||||
|
@ -275,9 +275,7 @@ Upgrade.prototype.GetUpgradeTime = function(templateArg)
|
||||
if (!this.template[choice].Time)
|
||||
return 0;
|
||||
|
||||
let cmpPlayer = QueryPlayerIDInterface(this.owner, IID_Player);
|
||||
return ApplyValueModificationsToEntity("Upgrade/Time", +this.template[choice].Time, this.entity) *
|
||||
cmpPlayer.GetTimeMultiplier();
|
||||
return ApplyValueModificationsToEntity("Upgrade/Time", +this.template[choice].Time, this.entity);
|
||||
};
|
||||
|
||||
Upgrade.prototype.GetElapsedTime = function()
|
||||
|
@ -33,10 +33,6 @@ AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
|
||||
"GetPlayerByID": id => 11
|
||||
});
|
||||
|
||||
AddMock(11, IID_Player, {
|
||||
"GetTimeMultiplier": () => 1
|
||||
});
|
||||
|
||||
AddMock(ent, IID_Sound, {
|
||||
"PlaySoundGroup": name => {}
|
||||
});
|
||||
|
@ -110,7 +110,6 @@ AddMock(SYSTEM_ENTITY, IID_ModifiersManager, {
|
||||
AddMock(10, IID_Player, {
|
||||
"AddResources": () => {}, // Called in components/Upgrade.js::CancelUpgrade().
|
||||
"GetPlayerID": () => playerID, // Called in helpers/Player.js::QueryOwnerInterface() (and several times below).
|
||||
"GetTimeMultiplier": () => 1.0, // Called in components/Upgrade.js::GetUpgradeTime().
|
||||
"TrySubtractResources": () => true // Called in components/Upgrade.js::Upgrade().
|
||||
});
|
||||
|
||||
|
@ -69,10 +69,17 @@ function Cheat(input)
|
||||
cmpProductionQueue.SpawnUnits(input.templates[i % input.templates.length], 1, null);
|
||||
return;
|
||||
case "fastactions":
|
||||
cmpPlayer.SetCheatTimeMultiplier((cmpPlayer.GetCheatTimeMultiplier() == 1) ? 0.01 : 1);
|
||||
return;
|
||||
case "changespeed":
|
||||
cmpPlayer.SetCheatTimeMultiplier(input.parameter);
|
||||
let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager);
|
||||
if (cmpModifiersManager.HasAnyModifier("cheat/fastactions", playerEnt))
|
||||
cmpModifiersManager.RemoveAllModifiers("cheat/fastactions", playerEnt);
|
||||
else
|
||||
cmpModifiersManager.AddModifiers("cheat/fastactions", {
|
||||
"Cost/BuildTime": { "affects": [["Structure"], ["Unit"]], "multiply": 0.01 },
|
||||
"ResourceGatherer/BaseSpeed": { "affects": [["Structure"], ["Unit"]], "multiply": 1000 },
|
||||
"Pack/Time": { "affects": [["Structure"], ["Unit"]], "multiply": 0.01 },
|
||||
"Upgrade/Time": { "affects": [["Structure"], ["Unit"]], "multiply": 0.01 },
|
||||
"ProductionQueue/TechCostMultiplier/time": { "affects": [["Structure"], ["Unit"]], "multiply": 0.01 }
|
||||
}, playerEnt);
|
||||
return;
|
||||
case "changephase":
|
||||
var cmpTechnologyManager = Engine.QueryInterface(playerEnt, IID_TechnologyManager);
|
||||
|
@ -46,6 +46,7 @@ function InitGame(settings)
|
||||
// time apply on building, upgrading, packing, training and technologies
|
||||
let rate = [ 0.42, 0.56, 0.75, 1.00, 1.25, 1.56 ];
|
||||
let time = [ 1.40, 1.25, 1.10, 1.00, 1.00, 1.00 ];
|
||||
let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager);
|
||||
let cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager);
|
||||
for (let i = 0; i < settings.PlayerData.length; ++i)
|
||||
{
|
||||
@ -57,9 +58,11 @@ function InitGame(settings)
|
||||
cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i, AIDiff, settings.PlayerData[i].AIBehavior || "random");
|
||||
cmpPlayer.SetAI(true);
|
||||
AIDiff = Math.min(AIDiff, rate.length - 1);
|
||||
cmpPlayer.SetGatherRateMultiplier(rate[AIDiff]);
|
||||
cmpPlayer.SetTradeRateMultiplier(rate[AIDiff]);
|
||||
cmpPlayer.SetTimeMultiplier(time[AIDiff]);
|
||||
cmpModifiersManager.AddModifiers("AI Bonus", {
|
||||
"ResourceGatherer/BaseSpeed": { "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] },
|
||||
"Trader/GainMultiplier": { "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] },
|
||||
"Cost/BuildTime": { "affects": ["Unit", "Structure"], "multiply": time[AIDiff] },
|
||||
}, cmpPlayer.entity);
|
||||
}
|
||||
if (settings.PopulationCap)
|
||||
cmpPlayer.SetMaxPopulation(settings.PopulationCap);
|
||||
|
@ -95,11 +95,6 @@ function LoadPlayerSettings(settings, newPlayers)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Note: this is not yet implemented but I leave it commented to highlight it's easy
|
||||
// If anyone ever adds handicap.
|
||||
//if (getSetting(playerData, playerDefaults, i, "GatherRateMultiplier") !== undefined)
|
||||
// cmpPlayer.SetGatherRateMultiplier(getSetting(playerData, playerDefaults, i, "GatherRateMultiplier"));
|
||||
|
||||
if (getSetting(playerData, playerDefaults, i, "PopulationLimit") !== undefined)
|
||||
cmpPlayer.SetMaxPopulation(getSetting(playerData, playerDefaults, i, "PopulationLimit"));
|
||||
|
||||
|
@ -27,7 +27,7 @@ function CalculateTraderGain(firstMarket, secondMarket, traderTemplate, trader)
|
||||
return null;
|
||||
gainMultiplier *= cmpTrader.GetTraderGainMultiplier();
|
||||
}
|
||||
else //called from the gui, modifications already applied
|
||||
else // Called from the gui, modifications already applied.
|
||||
{
|
||||
if (!traderTemplate || !traderTemplate.GainMultiplier)
|
||||
return null;
|
||||
@ -50,19 +50,15 @@ function CalculateTraderGain(firstMarket, secondMarket, traderTemplate, trader)
|
||||
if (!cmpPlayer)
|
||||
return null;
|
||||
gain.traderOwner = cmpPlayer.GetPlayerID();
|
||||
// Add potential player trade multipliers
|
||||
let playerBonus = cmpPlayer.GetTradeRateMultiplier();
|
||||
|
||||
// If markets belong to different players, add gain from international trading
|
||||
if (gain.market1Owner != gain.market2Owner)
|
||||
{
|
||||
let market1PlayerBonus = cmpMarket1Player.GetTradeRateMultiplier();
|
||||
let market2PlayerBonus = cmpMarket2Player.GetTradeRateMultiplier();
|
||||
let internationalBonus1 = cmpMarket1.GetInternationalBonus();
|
||||
let internationalBonus2 = cmpMarket2.GetInternationalBonus();
|
||||
gain.market1Gain = Math.round(gain.traderGain * internationalBonus1 * market1PlayerBonus);
|
||||
gain.market2Gain = Math.round(gain.traderGain * internationalBonus2 * market2PlayerBonus);
|
||||
gain.market1Gain = Math.round(gain.traderGain * internationalBonus1);
|
||||
gain.market2Gain = Math.round(gain.traderGain * internationalBonus2);
|
||||
}
|
||||
gain.traderGain = Math.round(gain.traderGain * playerBonus);
|
||||
|
||||
return gain;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user