forked from 0ad/0ad
Script work for techs (start/cancel/finish production handlers) as well as more sensible values for real_example.xml.
This was SVN commit r4145.
This commit is contained in:
parent
8eae620b11
commit
35fa0c35e8
@ -1328,11 +1328,13 @@ function entityStartConstruction( evt )
|
|||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
|
const TECH_RESOURCES = new Array("food", "wood", "stone", "ore");
|
||||||
|
|
||||||
function entityStartProduction( evt )
|
function entityStartProduction( evt )
|
||||||
{
|
{
|
||||||
console.write("StartProduction: " + evt.productionType + " " + evt.name);
|
console.write("StartProduction: " + evt.productionType + " " + evt.name);
|
||||||
|
|
||||||
if(evt.productionType == PRODUCTION_TRAIN)
|
if( evt.productionType == PRODUCTION_TRAIN )
|
||||||
{
|
{
|
||||||
var template = getEntityTemplate( evt.name, this.player );
|
var template = getEntityTemplate( evt.name, this.player );
|
||||||
var result = checkEntityReqs( this.player, template );
|
var result = checkEntityReqs( this.player, template );
|
||||||
@ -1375,6 +1377,50 @@ function entityStartProduction( evt )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( evt.productionType == PRODUCTION_RESEARCH )
|
||||||
|
{
|
||||||
|
var tech = getTechnology( evt.name, this.player );
|
||||||
|
|
||||||
|
if( !tech )
|
||||||
|
{
|
||||||
|
console.write( "No such tech: " + evt.name );
|
||||||
|
evt.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check tech requirements other than resources
|
||||||
|
if( !tech.isValid() )
|
||||||
|
{
|
||||||
|
console.write( "Tech " + evt.name + " is currently unavailable" );
|
||||||
|
evt.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for sufficient resources
|
||||||
|
for( i in TECH_RESOURCES )
|
||||||
|
{
|
||||||
|
var res = TECH_RESOURCES[i];
|
||||||
|
if( this.player.resources[res] < tech[res] )
|
||||||
|
{
|
||||||
|
console.write( "Cannot afford " + evt.name + ": need " + tech[res] + " " + res );
|
||||||
|
evt.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subtract resources
|
||||||
|
for( i in TECH_RESOURCES )
|
||||||
|
{
|
||||||
|
var res = TECH_RESOURCES[i];
|
||||||
|
this.player.resources[res] -= tech[res];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark it as in progress
|
||||||
|
tech.in_progress = true;
|
||||||
|
|
||||||
|
// Set the amount of time it will take to complete production of the tech.
|
||||||
|
evt.time = tech.time;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@ -1385,7 +1431,7 @@ function entityCancelProduction( evt )
|
|||||||
{
|
{
|
||||||
console.write("CancelProduction: " + evt.productionType + " " + evt.name);
|
console.write("CancelProduction: " + evt.productionType + " " + evt.name);
|
||||||
|
|
||||||
if(evt.productionType == PRODUCTION_TRAIN)
|
if( evt.productionType == PRODUCTION_TRAIN )
|
||||||
{
|
{
|
||||||
// Give back all the resources spent on this entry.
|
// Give back all the resources spent on this entry.
|
||||||
var template = getEntityTemplate( evt.name, this.player );
|
var template = getEntityTemplate( evt.name, this.player );
|
||||||
@ -1413,13 +1459,27 @@ function entityCancelProduction( evt )
|
|||||||
this.player.resources.population -= parseInt(template.traits.population.rem);
|
this.player.resources.population -= parseInt(template.traits.population.rem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( evt.productionType == PRODUCTION_RESEARCH )
|
||||||
|
{
|
||||||
|
var tech = getTechnology( evt.name, this.player );
|
||||||
|
|
||||||
|
// Give back the player's resources
|
||||||
|
for( i in TECH_RESOURCES )
|
||||||
|
{
|
||||||
|
var res = TECH_RESOURCES[i];
|
||||||
|
this.player.resources[res] += tech[res];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmark tech as in progress
|
||||||
|
tech.in_progress = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function entityFinishProduction( evt )
|
function entityFinishProduction( evt )
|
||||||
{
|
{
|
||||||
console.write("FinishProduction: " + evt.productionType + " " + evt.name);
|
console.write("FinishProduction: " + evt.productionType + " " + evt.name);
|
||||||
|
|
||||||
if(evt.productionType == PRODUCTION_TRAIN)
|
if( evt.productionType == PRODUCTION_TRAIN )
|
||||||
{
|
{
|
||||||
var template = getEntityTemplate( evt.name, this.player );
|
var template = getEntityTemplate( evt.name, this.player );
|
||||||
|
|
||||||
@ -1455,6 +1515,12 @@ function entityFinishProduction( evt )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( evt.productionType == PRODUCTION_RESEARCH )
|
||||||
|
{
|
||||||
|
// Apply the tech's effects
|
||||||
|
var tech = getTechnology( evt.name, this.player );
|
||||||
|
tech.applyEffects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Old training queue system
|
// Old training queue system
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</ID>
|
</ID>
|
||||||
|
|
||||||
<Req>
|
<Req>
|
||||||
<Time>120</Time>
|
<Time>5</Time>
|
||||||
<Resource>
|
<Resource>
|
||||||
<Food>50</Food>
|
<Food>50</Food>
|
||||||
<Wood>80</Wood>
|
<Wood>80</Wood>
|
||||||
@ -25,35 +25,21 @@
|
|||||||
|
|
||||||
<Entity>Melee</Entity>
|
<Entity>Melee</Entity>
|
||||||
<Entity>Ranged</Entity>
|
<Entity>Ranged</Entity>
|
||||||
<Entity>some_entity_class_name</Entity>
|
<!--<Entity>some_entity_class_name</Entity>-->
|
||||||
|
|
||||||
<Tech>otherexample</Tech>
|
<!--<Tech>otherexample</Tech>
|
||||||
<Tech>tech_file_name</Tech>
|
<Tech>tech_file_name</Tech>-->
|
||||||
</Req>
|
</Req>
|
||||||
|
|
||||||
<Effect>
|
<Effect>
|
||||||
<Target>Infantry</Target>
|
<Target>Infantry</Target>
|
||||||
<Target>some_entity_class_name</Target>
|
<Target>some_entity_class_name</Target>
|
||||||
|
|
||||||
<Pair>tech_shared_wood_gather_1</Pair>
|
<Pair>real_example</Pair>
|
||||||
<Pair>some_tech_name</Pair>
|
|
||||||
|
|
||||||
<Modifier>
|
|
||||||
<Attribute>traits.health.max</Attribute>
|
|
||||||
<Value>2</Value>
|
|
||||||
</Modifier>
|
|
||||||
<Modifier>
|
|
||||||
<Attribute>traits.some_attribute</Attribute>
|
|
||||||
<Value>2</Value>
|
|
||||||
</Modifier>
|
|
||||||
|
|
||||||
<Set>
|
<Set>
|
||||||
<Attribute>traits.health.max</Attribute>
|
<Attribute>traits.health.max</Attribute>
|
||||||
<Value>2</Value>
|
<Value>17</Value>
|
||||||
</Set>
|
|
||||||
<Set>
|
|
||||||
<Attribute>traits.some_attribute</Attribute>
|
|
||||||
<Value>2</Value>
|
|
||||||
</Set>
|
</Set>
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</ID>
|
</ID>
|
||||||
|
|
||||||
<Req>
|
<Req>
|
||||||
<Time>120</Time>
|
<Time>5</Time>
|
||||||
<Resource>
|
<Resource>
|
||||||
<Food>50</Food>
|
<Food>50</Food>
|
||||||
<Wood>80</Wood>
|
<Wood>80</Wood>
|
||||||
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
<Modifier>
|
<Modifier>
|
||||||
<Attribute>traits.health.max</Attribute>
|
<Attribute>traits.health.max</Attribute>
|
||||||
<Value>2</Value>
|
<Value>5</Value>
|
||||||
</Modifier>
|
</Modifier>
|
||||||
|
|
||||||
<Script File="scripts/tech_functions.js" />
|
<Script File="scripts/tech_functions.js" />
|
||||||
|
Loading…
Reference in New Issue
Block a user