1
0
forked from 0ad/0ad

Some fixes after the ProductionQueue split.

0c4f59d0a7 / 8475c16c31 introduced a serialisation error (#6391).
Also the templates and the code could be improved.

Differential revision: https://code.wildfiregames.com/D4352
Comments by: @Silier, @Stan
Fixes: #6391

This was SVN commit r26015.
This commit is contained in:
Freagarach 2021-11-26 17:12:26 +00:00
parent 809e3ed0bd
commit 8d80a2186e
40 changed files with 78 additions and 68 deletions

View File

@ -20,9 +20,32 @@ ProductionQueue.prototype.Item.prototype.Init = function(producer, metadata)
{
this.producer = producer;
this.metadata = metadata;
};
/**
* @param {string} type - The type of queue to use.
* @param {string} templateName - The template to queue.
* @param {number} count - The amount of template to queue. Only applicable for type == "unit".
*
* @return {boolean} - Whether the item could be queued.
*/
ProductionQueue.prototype.Item.prototype.Queue = function(type, templateName, count)
{
if (type == "unit")
return this.QueueEntity(templateName, count);
if (type == "technology")
return this.QueueTechnology(templateName);
warn("Tried to add invalid item of type \"" + type + "\" and template \"" + templateName + "\" to a production queue (entity: " + this.producer + ").");
return false;
};
/**
* @param {string} templateName - The name of the entity to queue.
* @param {number} count - The number of entities that should be produced.
* @return {boolean} - Whether the batch was successfully created.
*/
ProductionQueue.prototype.Item.prototype.QueueEntity = function(templateName, count)
{
const cmpTrainer = Engine.QueryInterface(this.producer, IID_Trainer);
@ -40,20 +63,21 @@ ProductionQueue.prototype.Item.prototype.QueueEntity = function(templateName, co
return true;
};
/**
* @param {string} templateName - The name of the technology to queue.
* @return {boolean} - Whether the technology was successfully queued.
*/
ProductionQueue.prototype.Item.prototype.QueueTechnology = function(templateName)
{
const cmpResearcher = Engine.QueryInterface(this.producer, IID_Researcher);
if (!cmpResearcher)
return false;
this.technology = cmpResearcher.QueueTechnology(templateName, this.metadata);
if (this.technology == -1)
return false;
return true;
return this.technology != -1;
};
/**
* @param {number} id - The id of this item.
* @param {number} id - The id this item needs to get.
*/
ProductionQueue.prototype.Item.prototype.SetID = function(id)
{
@ -62,19 +86,11 @@ ProductionQueue.prototype.Item.prototype.SetID = function(id)
ProductionQueue.prototype.Item.prototype.Stop = function()
{
if (this.entity)
{
const cmpTrainer = Engine.QueryInterface(this.producer, IID_Trainer);
if (cmpTrainer)
cmpTrainer.StopBatch(this.entity);
}
if (this.entity > 0)
Engine.QueryInterface(this.producer, IID_Trainer)?.StopBatch(this.entity);
if (this.technology)
{
const cmpResearcher = Engine.QueryInterface(this.producer, IID_Researcher);
if (cmpResearcher)
cmpResearcher.StopResearching(this.technology);
}
if (this.technology > 0)
Engine.QueryInterface(this.producer, IID_Researcher)?.StopResearching(this.technology);
};
/**
@ -85,6 +101,9 @@ ProductionQueue.prototype.Item.prototype.Start = function()
this.started = true;
};
/**
* @return {boolean} - Whether there is work done on the item.
*/
ProductionQueue.prototype.Item.prototype.IsStarted = function()
{
return !!this.started;
@ -142,6 +161,9 @@ ProductionQueue.prototype.Item.prototype.Unpause = function()
Engine.QueryInterface(this.producer, IID_Researcher).UnpauseTechnology(this.technology);
};
/**
* @return {boolean} - Whether the item is currently paused.
*/
ProductionQueue.prototype.Item.prototype.IsPaused = function()
{
return !!this.paused;
@ -199,7 +221,6 @@ ProductionQueue.prototype.Item.prototype.Deserialize = function(data)
ProductionQueue.prototype.Init = function()
{
this.nextID = 1;
this.queue = [];
};
@ -309,21 +330,8 @@ ProductionQueue.prototype.AddItem = function(templateName, type, count, metadata
const item = new this.Item();
item.Init(this.entity, metadata);
if (type == "unit")
{
if (!item.QueueEntity(templateName, count))
return false;
}
else if (type == "technology")
{
if (!item.QueueTechnology(templateName))
return false;
}
else
{
warn("Tried to add invalid item of type \"" + type + "\" and template \"" + templateName + "\" to a production queue");
if (!item.Queue(type, templateName, count))
return false;
}
item.SetID(this.nextID++);
if (pushFront)
@ -342,7 +350,7 @@ ProductionQueue.prototype.AddItem = function(templateName, type, count, metadata
};
/*
* Removes an item from the queue.
* @param {number} - The ID of the item to remove from the queue.
*/
ProductionQueue.prototype.RemoveItem = function(id)
{
@ -457,7 +465,6 @@ ProductionQueue.prototype.PauseProduction = function()
this.StopTimer();
this.paused = true;
this.queue[0]?.Pause();
this.StopTimer();
};
ProductionQueue.prototype.UnpauseProduction = function()
@ -492,6 +499,9 @@ ProductionQueue.prototype.StopTimer = function()
delete this.timer;
};
/**
* @return {boolean} - Whether this entity is currently producing.
*/
ProductionQueue.prototype.HasQueuedProduction = function()
{
return this.queue.length > 0;

View File

@ -221,8 +221,7 @@ Researcher.prototype.GetTechnologiesList = function()
if (!this.template.Technologies)
return [];
let string = this.template.Technologies._string;
string = ApplyValueModificationsToEntity("Researcher/Technologies/_string", string, this.entity);
const string = ApplyValueModificationsToEntity("Researcher/Technologies/_string", this.template.Technologies._string, this.entity);
if (!string)
return [];

View File

@ -386,6 +386,7 @@ Trainer.prototype.Item.prototype.Serialize = function(id)
"missingPopSpace": this.missingPopSpace,
"paused": this.paused,
"player": this.player,
"population": this.population,
"trainer": this.trainer,
"resource": this.resources,
"started": this.started,
@ -403,6 +404,7 @@ Trainer.prototype.Item.prototype.Deserialize = function(data)
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;

View File

@ -33,6 +33,7 @@
<Obstruction>
<Static width="28.0" depth="28.0"/>
</Obstruction>
<ProductionQueue/>
<Sound>
<SoundGroups>
<select>interface/select/building/sel_gymnasium.xml</select>

View File

@ -33,6 +33,7 @@
<Obstruction>
<Static width="24.0" depth="30.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
long_walls

View File

@ -38,6 +38,7 @@
<Obstruction>
<Static width="25.0" depth="25.0"/>
</Obstruction>
<ProductionQueue/>
<Resistance>
<Entity>
<Damage>

View File

@ -37,6 +37,7 @@
<Obstruction>
<Static width="30.0" depth="30.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
immortals

View File

@ -83,6 +83,7 @@
<Obstruction>
<Static width="36.0" depth="36.0"/>
</Obstruction>
<ProductionQueue/>
<Resistance>
<Entity>
<Damage>

View File

@ -33,6 +33,7 @@
<Obstruction>
<Static width="20.0" depth="20.0"/>
</Obstruction>
<ProductionQueue/>
<Sound>
<SoundGroups>
<select>interface/select/building/sel_tholos.xml</select>

View File

@ -34,6 +34,7 @@
<Obstruction>
<Static width="16.0" depth="26.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
agoge

View File

@ -77,7 +77,6 @@
<FloatDepth>0</FloatDepth>
<TurnRate>6</TurnRate>
</Position>
<ProductionQueue/>
<RallyPoint/>
<RallyPointRenderer>
<MarkerTemplate>special/rallypoint</MarkerTemplate>
@ -94,15 +93,6 @@
<Repairable>
<RepairTimeRatio>2.0</RepairTimeRatio>
</Repairable>
<Researcher>
<TechCostMultiplier>
<food>1.0</food>
<wood>1.0</wood>
<stone>1.0</stone>
<metal>1.0</metal>
<time>1.0</time>
</TechCostMultiplier>
</Researcher>
<Resistance>
<Entity>
<ApplyStatus>
@ -161,9 +151,6 @@
<DecayRate>20</DecayRate>
<Territory>neutral enemy</Territory>
</TerritoryDecay>
<Trainer>
<BatchTimeModifier>1.0</BatchTimeModifier>
</Trainer>
<Visibility>
<RetainInFog>true</RetainInFog>
<AlwaysVisible>false</AlwaysVisible>

View File

@ -90,6 +90,7 @@
<Population>
<Bonus>20</Bonus>
</Population>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
phase_town_{civ}

View File

@ -38,6 +38,7 @@
<Population>
<Bonus>5</Bonus>
</Population>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
health_females_01

View File

@ -39,6 +39,7 @@
<Obstruction>
<Static width="17.5" depth="30.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
heal_range

View File

@ -37,6 +37,7 @@
<Obstruction>
<Static width="6.0" depth="6.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
outpost_vision

View File

@ -16,9 +16,7 @@
<VisibleClasses datatype="tokens">Palisade</VisibleClasses>
<Icon>gaia/special_palisade.png</Icon>
</Identity>
<ProductionQueue disable=""/>
<RallyPoint disable=""/>
<Researcher disable=""/>
<Resistance>
<Entity>
<Damage>
@ -34,5 +32,4 @@
<constructed>interface/complete/building/complete_wall.xml</constructed>
</SoundGroups>
</Sound>
<Trainer disable=""/>
</Entity>

View File

@ -60,6 +60,7 @@
<Obstruction>
<Static width="7.0" depth="7.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
tower_health

View File

@ -57,6 +57,7 @@
<Obstruction>
<Static width="7.0" depth="7.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
tower_health

View File

@ -38,6 +38,7 @@
<Obstruction>
<Static width="9.0" depth="7.5"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
tower_watch

View File

@ -37,6 +37,7 @@
<Obstruction>
<Static width="7.0" depth="7.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
tower_watch

View File

@ -19,11 +19,9 @@
<Obstruction>
<Static width="6.0" depth="6.0"/>
</Obstruction>
<ProductionQueue disable=""/>
<Repairable>
<RepairTimeRatio>4.5</RepairTimeRatio>
</Repairable>
<Researcher disable=""/>
<Sound>
<SoundGroups>
<select>interface/select/building/sel_wall.xml</select>
@ -35,5 +33,4 @@
<Radius>20</Radius>
<Weight>65535</Weight>
</TerritoryInfluence>
<Trainer disable=""/>
</Entity>

View File

@ -34,6 +34,7 @@
<Loot>
<wood>20</wood>
</Loot>
<ProductionQueue/>
<RallyPoint disable=""/>
<Researcher>
<Technologies datatype="tokens">

View File

@ -39,6 +39,7 @@
<Obstruction>
<Static width="30.0" depth="26.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
trader_health

View File

@ -35,6 +35,7 @@
<Obstruction>
<Static width="13.0" depth="13.0"/>
</Obstruction>
<ProductionQueue/>
<RallyPoint disable=""/>
<Researcher>
<Technologies datatype="tokens">

View File

@ -35,6 +35,7 @@
<Obstruction>
<Static width="29.0" depth="29.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
siege_attack

View File

@ -37,6 +37,7 @@
<Obstruction>
<Static width="17.0" depth="17.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
barracks_batch_training

View File

@ -41,6 +41,7 @@
<Floating>true</Floating>
<FloatDepth>0.0</FloatDepth>
</Position>
<ProductionQueue/>
<RallyPointRenderer>
<LinePassabilityClass>ship</LinePassabilityClass>
</RallyPointRenderer>

View File

@ -37,6 +37,7 @@
<Obstruction>
<Static width="29" depth="27"/>
</Obstruction>
<ProductionQueue/>
<Sound>
<SoundGroups>
<constructed>interface/complete/building/complete_elephant_stable.xml</constructed>

View File

@ -27,6 +27,7 @@
<Obstruction>
<Static width="16.0" depth="16.0"/>
</Obstruction>
<ProductionQueue/>
<Resistance>
<Entity>
<Damage>

View File

@ -33,6 +33,7 @@
<Obstruction>
<Static width="17.0" depth="17.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
soldier_attack_melee_01

View File

@ -77,6 +77,7 @@
<Obstruction>
<Static width="25.0" depth="25.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
attack_soldiers_will

View File

@ -32,6 +32,7 @@
<Obstruction>
<Static width="24.0" depth="24.0"/>
</Obstruction>
<ProductionQueue/>
<Sound>
<SoundGroups>
<constructed>interface/complete/building/complete_range.xml</constructed>

View File

@ -37,6 +37,7 @@
<Obstruction>
<Static width="20.0" depth="20.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
stable_batch_training

View File

@ -28,6 +28,7 @@
<Obstruction>
<Static width="16.0" depth="15.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
gather_animals_stockbreeding

View File

@ -32,9 +32,7 @@
<BlockMovement>false</BlockMovement>
<BlockPathfinding>false</BlockPathfinding>
</Obstruction>
<ProductionQueue disable=""/>
<RallyPoint disable=""/>
<Researcher disable=""/>
<Resistance>
<Entity>
<Damage>
@ -60,7 +58,6 @@
<StatusBars>
<HeightOffset>8.0</HeightOffset>
</StatusBars>
<Trainer disable=""/>
<Vision>
<Range>0</Range>
</Vision>

View File

@ -27,6 +27,7 @@
<Obstruction>
<Static width="62" depth="86"/>
</Obstruction>
<ProductionQueue/>
<Sound>
<SoundGroups>
<select>interface/select/building/sel_tholos.xml</select>

View File

@ -34,8 +34,6 @@
<Obstruction>
<Static width="25.0" depth="30.0"/>
</Obstruction>
<ProductionQueue disable=""/>
<Researcher disable=""/>
<Sound>
<SoundGroups>
<select>interface/select/building/sel_library.xml</select>
@ -47,7 +45,6 @@
<Radius>50</Radius>
<Weight>40000</Weight>
</TerritoryInfluence>
<Trainer disable=""/>
<Vision>
<Range>40</Range>
</Vision>

View File

@ -28,9 +28,7 @@
<Obstruction>
<Static width="16.0" depth="16.0"/>
</Obstruction>
<ProductionQueue disable=""/>
<RallyPoint disable=""/>
<Researcher disable=""/>
<ResourceDropsite>
<Types>food</Types>
<Sharable>true</Sharable>
@ -49,7 +47,6 @@
<Radius>32</Radius>
<Weight>40000</Weight>
</TerritoryInfluence>
<Trainer disable=""/>
<Vision>
<Range>40</Range>
</Vision>

View File

@ -35,8 +35,6 @@
<Obstruction>
<Static width="40" depth="46"/>
</Obstruction>
<ProductionQueue disable=""/>
<Researcher disable=""/>
<Sound>
<SoundGroups>
<select>interface/select/building/sel_greek_theater.xml</select>
@ -48,7 +46,6 @@
<Radius>100</Radius>
<Weight>40000</Weight>
</TerritoryInfluence>
<Trainer disable=""/>
<Vision>
<Range>40</Range>
</Vision>

View File

@ -50,6 +50,7 @@
<Obstruction>
<Static width="30.0" depth="30.0"/>
</Obstruction>
<ProductionQueue/>
<Researcher>
<Technologies datatype="tokens">
wonder_population_cap