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:
Matei 2006-07-19 05:25:57 +00:00
parent 8eae620b11
commit 35fa0c35e8
3 changed files with 77 additions and 25 deletions

View File

@ -1328,11 +1328,13 @@ function entityStartConstruction( evt )
// ====================================================================
const TECH_RESOURCES = new Array("food", "wood", "stone", "ore");
function entityStartProduction( evt )
{
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 result = checkEntityReqs( this.player, template );
@ -1375,6 +1377,50 @@ function entityStartProduction( evt )
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
{
evt.preventDefault();
@ -1385,7 +1431,7 @@ function entityCancelProduction( evt )
{
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.
var template = getEntityTemplate( evt.name, this.player );
@ -1413,13 +1459,27 @@ function entityCancelProduction( evt )
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 )
{
console.write("FinishProduction: " + evt.productionType + " " + evt.name);
if(evt.productionType == PRODUCTION_TRAIN)
if( evt.productionType == PRODUCTION_TRAIN )
{
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

View File

@ -15,7 +15,7 @@
</ID>
<Req>
<Time>120</Time>
<Time>5</Time>
<Resource>
<Food>50</Food>
<Wood>80</Wood>
@ -25,35 +25,21 @@
<Entity>Melee</Entity>
<Entity>Ranged</Entity>
<Entity>some_entity_class_name</Entity>
<!--<Entity>some_entity_class_name</Entity>-->
<Tech>otherexample</Tech>
<Tech>tech_file_name</Tech>
<!--<Tech>otherexample</Tech>
<Tech>tech_file_name</Tech>-->
</Req>
<Effect>
<Target>Infantry</Target>
<Target>some_entity_class_name</Target>
<Pair>tech_shared_wood_gather_1</Pair>
<Pair>some_tech_name</Pair>
<Pair>real_example</Pair>
<Modifier>
<Attribute>traits.health.max</Attribute>
<Value>2</Value>
</Modifier>
<Modifier>
<Attribute>traits.some_attribute</Attribute>
<Value>2</Value>
</Modifier>
<Set>
<Attribute>traits.health.max</Attribute>
<Value>2</Value>
</Set>
<Set>
<Attribute>traits.some_attribute</Attribute>
<Value>2</Value>
<Value>17</Value>
</Set>

View File

@ -15,7 +15,7 @@
</ID>
<Req>
<Time>120</Time>
<Time>5</Time>
<Resource>
<Food>50</Food>
<Wood>80</Wood>
@ -38,7 +38,7 @@
<Modifier>
<Attribute>traits.health.max</Attribute>
<Value>2</Value>
<Value>5</Value>
</Modifier>
<Script File="scripts/tech_functions.js" />