1
0
forked from mirrors/0ad

Fix getting units by cheat.

Introduced in 0c4f59d0a7.
Noticed by: @loveheaven at
https://wildfiregames.com/forum/topic/64877-cannot-cheat-any-longer-by-iwanttopwnthem-50/.

Differential revision: https://code.wildfiregames.com/D4374
Comments by: @Silier, @Stan
This was SVN commit r26084.
This commit is contained in:
Freagarach
2021-12-17 15:34:49 +00:00
parent 3b9b7cd605
commit e4925e02d0
2 changed files with 46 additions and 61 deletions
@@ -30,15 +30,11 @@ Researcher.prototype.Schema =
/**
* This object represents a technology being researched.
*/
Researcher.prototype.Item = function() {};
/**
* @param {string} templateName - The name of the template we ought to research.
* @param {number} researcher - The entity ID of our researcher.
* @param {string} metadata - Optionally any metadata to attach to us.
*/
Researcher.prototype.Item.prototype.Init = function(templateName, researcher, metadata)
Researcher.prototype.Item = function(templateName, researcher, metadata)
{
this.templateName = templateName;
this.researcher = researcher;
@@ -154,33 +150,32 @@ Researcher.prototype.Item.prototype.GetBasicInfo = function()
};
};
Researcher.prototype.Item.prototype.SerializableAttributes = [
"metadata",
"paused",
"player",
"researcher",
"resources",
"started",
"templateName",
"timeRemaining",
"timeTotal"
];
Researcher.prototype.Item.prototype.Serialize = function(id)
{
return {
"id": id,
"metadata": this.metadata,
"paused": this.paused,
"player": this.player,
"researcher": this.researcher,
"resource": this.resources,
"started": this.started,
"templateName": this.templateName,
"timeRemaining": this.timeRemaining,
"timeTotal": this.timeTotal,
const result = {
"id": id
};
for (const att in this.SerializableAttributes)
result[att] = this[att];
return result;
};
Researcher.prototype.Item.prototype.Deserialize = function(data)
{
this.Init(data.templateName, data.researcher, data.metadata);
this.paused = data.paused;
this.player = data.player;
this.researcher = data.researcher;
this.resources = data.resources;
this.started = data.started;
this.timeRemaining = data.timeRemaining;
this.timeTotal = data.timeTotal;
for (const att of this.SerializableAttributes)
this[att] = data[att];
};
Researcher.prototype.Init = function()
@@ -351,8 +346,7 @@ Researcher.prototype.QueueTechnology = function(templateName, metadata)
return -1;
}
const item = new this.Item();
item.Init(templateName, this.entity, metadata);
const item = new this.Item(templateName, this.entity, metadata);
const techCostMultiplier = this.GetTechCostMultiplier();
if (!item.Queue(techCostMultiplier))
@@ -24,16 +24,12 @@ Trainer.prototype.Schema =
/**
* This object represents a batch of entities being trained.
*/
Trainer.prototype.Item = function() {};
/**
* @param {string} templateName - The name of the template we ought to train.
* @param {number} count - The size of the batch to train.
* @param {number} trainer - The entity ID of our trainer.
* @param {string} metadata - Optionally any metadata to attach to us.
*/
Trainer.prototype.Item.prototype.Init = function(templateName, count, trainer, metadata)
Trainer.prototype.Item = function(templateName, count, trainer, metadata)
{
this.count = count;
this.templateName = templateName;
@@ -376,40 +372,36 @@ Trainer.prototype.Item.prototype.GetBasicInfo = function()
};
};
Trainer.prototype.Item.prototype.SerializableAttributes = [
"count",
"entities",
"metadata",
"missingPopSpace",
"paused",
"player",
"population",
"trainer",
"resources",
"started",
"templateName",
"timeRemaining",
"timeTotal"
];
Trainer.prototype.Item.prototype.Serialize = function(id)
{
return {
"id": id,
"count": this.count,
"entities": this.entities,
"metadata": this.metadata,
"missingPopSpace": this.missingPopSpace,
"paused": this.paused,
"player": this.player,
"population": this.population,
"trainer": this.trainer,
"resource": this.resources,
"started": this.started,
"templateName": this.templateName,
"timeRemaining": this.timeRemaining,
"timeTotal": this.timeTotal,
const result = {
"id": id
};
for (const att of this.SerializableAttributes)
result[att] = this[att];
return result;
};
Trainer.prototype.Item.prototype.Deserialize = function(data)
{
this.Init(data.templateName, data.count, data.trainer, data.metadata);
this.entities = data.entities;
this.missingPopSpace = data.missingPopSpace;
this.paused = data.paused;
this.player = data.player;
this.population = data.population;
this.trainer = data.trainer;
this.resources = data.resources;
this.started = data.started;
this.timeRemaining = data.timeRemaining;
this.timeTotal = data.timeTotal;
for (const att of this.SerializableAttributes)
this[att] = data[att];
};
Trainer.prototype.Init = function()
@@ -614,8 +606,7 @@ Trainer.prototype.CanTrain = function(templateName)
*/
Trainer.prototype.QueueBatch = function(templateName, count, metadata)
{
const item = new this.Item();
item.Init(templateName, count, this.entity, metadata);
const item = new this.Item(templateName, count, this.entity, metadata);
const trainCostMultiplier = this.GetTrainCostMultiplier();
const batchTimeMultiplier = this.GetBatchTime(count);