Construction JavaScript and XML changes, at least for houses (still need to convert the other building types over).
This was SVN commit r3565.
This commit is contained in:
parent
192ddf9ddf
commit
422c1e1bc4
26
binaries/data/mods/official/entities/foundation_2x2.xml
Normal file
26
binaries/data/mods/official/entities/foundation_2x2.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||||
|
|
||||||
|
<Entity
|
||||||
|
Parent="template_foundation"
|
||||||
|
>
|
||||||
|
<Traits>
|
||||||
|
|
||||||
|
<Id>
|
||||||
|
<Generic>Foundation 2x2</Generic>
|
||||||
|
|
||||||
|
<Icon>sheet_civ</Icon>
|
||||||
|
|
||||||
|
<Classes>Foundation</Classes>
|
||||||
|
</Id>
|
||||||
|
|
||||||
|
<Footprint>
|
||||||
|
<Width>9.0</Width>
|
||||||
|
<Depth>9.0</Depth>
|
||||||
|
<Height>8.0</Height>
|
||||||
|
</Footprint>
|
||||||
|
|
||||||
|
</Traits>
|
||||||
|
|
||||||
|
<Actor>structures/fndn_2x2.xml</Actor>
|
||||||
|
|
||||||
|
</Entity>
|
@ -20,7 +20,7 @@ const ACTION_ATTACK = 1;
|
|||||||
const ACTION_GATHER = 2;
|
const ACTION_GATHER = 2;
|
||||||
const ACTION_HEAL = 3;
|
const ACTION_HEAL = 3;
|
||||||
const ACTION_ATTACK_RANGED = 4;
|
const ACTION_ATTACK_RANGED = 4;
|
||||||
|
const ACTION_BUILD = 5;
|
||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
@ -30,6 +30,19 @@ function entityInit()
|
|||||||
|
|
||||||
this.addCreateQueue = entityAddCreateQueue;
|
this.addCreateQueue = entityAddCreateQueue;
|
||||||
|
|
||||||
|
// If this is a foundation, initialize traits from the building we're converting into
|
||||||
|
if( this.building != "" )
|
||||||
|
{
|
||||||
|
var building = getEntityTemplate( this.building );
|
||||||
|
this.traits.id.generic = building.traits.id.generic;
|
||||||
|
this.traits.id.specific = building.traits.id.specific;
|
||||||
|
this.traits.id.civ = building.traits.id.civ;
|
||||||
|
this.traits.health.max = building.traits.health.max;
|
||||||
|
this.build_points = new Object();
|
||||||
|
this.build_points.curr = 0.0;
|
||||||
|
this.build_points.max = parseFloat( building.traits.creation.time );
|
||||||
|
}
|
||||||
|
|
||||||
// Generate civ code (1st four characters of civ name, in lower case eg "Carthaginians" => "cart").
|
// Generate civ code (1st four characters of civ name, in lower case eg "Carthaginians" => "cart").
|
||||||
if (this.traits.id && this.traits.id.civ)
|
if (this.traits.id && this.traits.id.civ)
|
||||||
{
|
{
|
||||||
@ -43,27 +56,27 @@ function entityInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If entity can contain garrisoned units, empty it.
|
// If entity can contain garrisoned units, empty it.
|
||||||
if (this.traits.garrison && this.traits.garrison.max)
|
if ( this.traits.garrison && this.traits.garrison.max )
|
||||||
this.traits.garrison.curr = 0
|
this.traits.garrison.curr = 0;
|
||||||
|
|
||||||
// If entity has health, set current to same.
|
// If entity has health, set current to same, unless it's a foundation, in which case we set it to 0.
|
||||||
if (this.traits.health && this.traits.health.max)
|
if ( this.traits.health && this.traits.health.max )
|
||||||
this.traits.health.curr = this.traits.health.max
|
this.traits.health.curr = ( this.building!="" ? 0.0 : this.traits.health.max );
|
||||||
|
|
||||||
// If entity has stamina, set current to same.
|
// If entity has stamina, set current to same.
|
||||||
if (this.traits.stamina && this.traits.stamina.max)
|
if ( this.traits.stamina && this.traits.stamina.max )
|
||||||
this.traits.stamina.curr = this.traits.stamina.max
|
this.traits.stamina.curr = this.traits.stamina.max;
|
||||||
|
|
||||||
if (this.traits.supply)
|
if (this.traits.supply)
|
||||||
{
|
{
|
||||||
// If entity has supply, set current to same.
|
// If entity has supply, set current to same.
|
||||||
if (this.traits.supply.max)
|
if (this.traits.supply.max)
|
||||||
this.traits.supply.curr = this.traits.supply.max
|
this.traits.supply.curr = this.traits.supply.max;
|
||||||
|
|
||||||
// If entity has type of supply and no subtype, set subtype to same
|
// If entity has type of supply and no subtype, set subtype to same
|
||||||
// (so we don't have to say type="wood", subtype="wood"
|
// (so we don't have to say type="wood", subtype="wood"
|
||||||
if (this.traits.supply.type && !this.traits.supply.subtype)
|
if (this.traits.supply.type && !this.traits.supply.subtype)
|
||||||
this.traits.supply.subtype = this.traits.supply.type
|
this.traits.supply.subtype = this.traits.supply.type;
|
||||||
|
|
||||||
// The "dropsitecount" array holds the number of units with gather aura in range of the object;
|
// The "dropsitecount" array holds the number of units with gather aura in range of the object;
|
||||||
// this is important so that if you have two mills near something and one of them is destroyed,
|
// this is important so that if you have two mills near something and one of them is destroyed,
|
||||||
@ -157,6 +170,10 @@ function entityInit()
|
|||||||
// this animation should actually be "ranged" except the current actors still have it called "melee"
|
// this animation should actually be "ranged" except the current actors still have it called "melee"
|
||||||
this.setActionParams( ACTION_ATTACK_RANGED, minRange, a.range, a.speed, "melee" );
|
this.setActionParams( ACTION_ATTACK_RANGED, minRange, a.range, a.speed, "melee" );
|
||||||
}
|
}
|
||||||
|
if( this.actions.build )
|
||||||
|
{
|
||||||
|
this.setActionParams( ACTION_BUILD, 0.0, 2.0, this.actions.build.speed, "build" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach functions to ourselves
|
// Attach functions to ourselves
|
||||||
@ -165,7 +182,9 @@ function entityInit()
|
|||||||
this.performAttackRanged = performAttackRanged;
|
this.performAttackRanged = performAttackRanged;
|
||||||
this.performGather = performGather;
|
this.performGather = performGather;
|
||||||
this.performHeal = performHeal;
|
this.performHeal = performHeal;
|
||||||
|
this.performBuild = performBuild;
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
|
this.entityComplete = entityComplete;
|
||||||
this.GotoInRange = GotoInRange;
|
this.GotoInRange = GotoInRange;
|
||||||
|
|
||||||
// Attach Auras if the entity is entitled to them.
|
// Attach Auras if the entity is entitled to them.
|
||||||
@ -233,7 +252,7 @@ function entityInit()
|
|||||||
// Set default stance for non-combat units.
|
// Set default stance for non-combat units.
|
||||||
this.traits.ai.stance.curr = "Avoid";
|
this.traits.ai.stance.curr = "Avoid";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Generate entity's personal name (if it needs one).
|
// Generate entity's personal name (if it needs one).
|
||||||
if (this.traits.id.personal)
|
if (this.traits.id.personal)
|
||||||
@ -271,15 +290,35 @@ function entityInit()
|
|||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
|
function foundationDestroyed( evt )
|
||||||
|
{
|
||||||
|
if( this.building != "" ) // Check that we're *really* a foundation since the event handler is kept when we change templates (probably a bug)
|
||||||
|
{
|
||||||
|
//console.write( "Hari Seldon made a small calculation error." );
|
||||||
|
|
||||||
|
var bp = this.build_points;
|
||||||
|
var fractionToReturn = (bp.max - bp.curr) / bp.max;
|
||||||
|
|
||||||
|
var resources = getEntityTemplate( this.building ).traits.creation.resource;
|
||||||
|
for( r in resources )
|
||||||
|
{
|
||||||
|
amount = parseInt( fractionToReturn * parseInt(resources[r]) );
|
||||||
|
getGUIGlobal().giveResources( r.toString(), amount );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====================================================================
|
||||||
|
|
||||||
function performAttack( evt )
|
function performAttack( evt )
|
||||||
{
|
{
|
||||||
this.last_combat_time = getGameTime();
|
this.last_combat_time = getGameTime();
|
||||||
|
|
||||||
curr_hit = getGUIGlobal().newRandomSound("voice", "hit", this.traits.audio.path);
|
var curr_hit = getGUIGlobal().newRandomSound("voice", "hit", this.traits.audio.path);
|
||||||
curr_hit.play();
|
curr_hit.play();
|
||||||
|
|
||||||
// Attack logic.
|
// Attack logic.
|
||||||
dmg = new DamageType();
|
var dmg = new DamageType();
|
||||||
|
|
||||||
if ( this.getRunState() )
|
if ( this.getRunState() )
|
||||||
{
|
{
|
||||||
@ -454,18 +493,43 @@ function performHeal( evt )
|
|||||||
{
|
{
|
||||||
switch( resource.toString() )
|
switch( resource.toString() )
|
||||||
{
|
{
|
||||||
case "Population" || "Housing":
|
case "Population":
|
||||||
break;
|
case "Housing":
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Deduct resources to pay for healing.
|
// Deduct resources to pay for healing.
|
||||||
getGUIGlobal().deductResources(toTitleCase (resource.toString()), parseInt(evt.target.actions.heal.cost * evt.target.traits.creation.cost[resource]));
|
getGUIGlobal().deductResources(toTitleCase (resource.toString()), parseInt(evt.target.actions.heal.cost * evt.target.traits.creation.cost[resource]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
|
function performBuild( evt )
|
||||||
|
{
|
||||||
|
var t = evt.target;
|
||||||
|
var b = this.actions.build;
|
||||||
|
var bp = t.build_points;
|
||||||
|
var hp = t.traits.health;
|
||||||
|
|
||||||
|
var points = parseFloat( b.rate ) * parseFloat( b.speed ) / 1000.0;
|
||||||
|
bp.curr += points;
|
||||||
|
hp.curr = Math.min( hp.max, hp.curr + (points/bp.max)*hp.max );
|
||||||
|
|
||||||
|
if( bp.curr >= bp.max )
|
||||||
|
{
|
||||||
|
if( t.building != "" ) // Might be false if another unit finished building the thing during our last anim cycle
|
||||||
|
{
|
||||||
|
t.template = getEntityTemplate( t.building );
|
||||||
|
t.building = "";
|
||||||
|
}
|
||||||
|
evt.preventDefault(); // Stop performing this action
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====================================================================
|
||||||
|
|
||||||
function damage( dmg, inflictor )
|
function damage( dmg, inflictor )
|
||||||
{
|
{
|
||||||
if(!this.traits.armour) return; // corpses have no armour, everything else should
|
if(!this.traits.armour) return; // corpses have no armour, everything else should
|
||||||
@ -568,7 +632,7 @@ function damage( dmg, inflictor )
|
|||||||
console.write("Kill!!");
|
console.write("Kill!!");
|
||||||
this.kill();
|
this.kill();
|
||||||
}
|
}
|
||||||
else if( inflictor && this.actions.attack )
|
else if( inflictor && this.actions && this.actions.attack )
|
||||||
{
|
{
|
||||||
// If we're not already doing something else, take a measured response - hit 'em back.
|
// If we're not already doing something else, take a measured response - hit 'em back.
|
||||||
// You know, I think this is quite possibly the first AI code the AI divlead has written
|
// You know, I think this is quite possibly the first AI code the AI divlead has written
|
||||||
@ -592,6 +656,8 @@ function entityEventGeneric( evt )
|
|||||||
this.performHeal( evt ); break;
|
this.performHeal( evt ); break;
|
||||||
case ACTION_ATTACK_RANGED:
|
case ACTION_ATTACK_RANGED:
|
||||||
this.performAttackRanged( evt ); break;
|
this.performAttackRanged( evt ); break;
|
||||||
|
case ACTION_BUILD:
|
||||||
|
this.performBuild( evt ); break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.write( "Unknown generic action: " + evt.action );
|
console.write( "Unknown generic action: " + evt.action );
|
||||||
@ -645,6 +711,14 @@ function getAttackAction( source, target )
|
|||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
|
// TODO: Change this to an event so that it gets passed to our parent too, like other events
|
||||||
|
function entityComplete()
|
||||||
|
{
|
||||||
|
console.write( this + " is finished building." );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====================================================================
|
||||||
|
|
||||||
function entityEventTargetChanged( evt )
|
function entityEventTargetChanged( evt )
|
||||||
{
|
{
|
||||||
// This event lets us know when the user moves his/her cursor to a different unit (provided this
|
// This event lets us know when the user moves his/her cursor to a different unit (provided this
|
||||||
@ -659,7 +733,7 @@ function entityEventTargetChanged( evt )
|
|||||||
evt.defaultAction = ACTION_NONE;
|
evt.defaultAction = ACTION_NONE;
|
||||||
evt.secondaryAction = ACTION_NONE;
|
evt.secondaryAction = ACTION_NONE;
|
||||||
evt.secondaryCursor = "arrow-default";
|
evt.secondaryCursor = "arrow-default";
|
||||||
if ( this.actions.run && this.actions.run.speed > 0 )
|
if ( this.actions && this.actions.run && this.actions.run.speed > 0 )
|
||||||
{
|
{
|
||||||
evt.secondaryOrder = NMT_Run;
|
evt.secondaryOrder = NMT_Run;
|
||||||
}
|
}
|
||||||
@ -679,6 +753,7 @@ function entityEventTargetChanged( evt )
|
|||||||
evt.secondaryAction = getAttackAction( this, evt.target );
|
evt.secondaryAction = getAttackAction( this, evt.target );
|
||||||
evt.secondaryCursor = "action-attack";
|
evt.secondaryCursor = "action-attack";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.actions.escort &&
|
if ( this.actions.escort &&
|
||||||
this != evt.target &&
|
this != evt.target &&
|
||||||
evt.target.player == this.player &&
|
evt.target.player == this.player &&
|
||||||
@ -695,7 +770,6 @@ function entityEventTargetChanged( evt )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( canGather( this, evt.target ) )
|
if ( canGather( this, evt.target ) )
|
||||||
{
|
{
|
||||||
evt.defaultOrder = NMT_Generic;
|
evt.defaultOrder = NMT_Generic;
|
||||||
@ -708,6 +782,17 @@ function entityEventTargetChanged( evt )
|
|||||||
// Set cursor (eg "action-gather-fruit").
|
// Set cursor (eg "action-gather-fruit").
|
||||||
evt.secondaryCursor = "action-gather-" + evt.target.traits.supply.subtype;
|
evt.secondaryCursor = "action-gather-" + evt.target.traits.supply.subtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( canBuild( this, evt.target ) )
|
||||||
|
{
|
||||||
|
evt.defaultOrder = NMT_Generic;
|
||||||
|
evt.defaultAction = ACTION_BUILD;
|
||||||
|
evt.defaultCursor = "action-build";
|
||||||
|
|
||||||
|
evt.secondaryOrder = NMT_Generic;
|
||||||
|
evt.secondaryAction = ACTION_BUILD;
|
||||||
|
evt.secondaryCursor = "action-build";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -726,7 +811,7 @@ function entityEventPrepareOrder( evt )
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//evt.notifySource is the entity order data will be obtained from, so if we're attacking and we
|
//evt.notifySource is the entity order data will be obtained from, so if we're attacking and we
|
||||||
//want our listeners to copy us, then we will use our own order as the source.
|
//want our listeners to copy us, then we will use our own order as the source.
|
||||||
|
|
||||||
@ -737,21 +822,20 @@ function entityEventPrepareOrder( evt )
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.notifyType = NOTIFY_GOTO;
|
evt.notifyType = NOTIFY_GOTO;
|
||||||
evt.notifySource = this;
|
evt.notifySource = this;
|
||||||
|
break;
|
||||||
break
|
|
||||||
case ORDER_RUN:
|
case ORDER_RUN:
|
||||||
if ( !this.actions.move.run )
|
if ( !this.actions.move.run )
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
evt.notifyType = NOTIFY_RUN;
|
evt.notifyType = NOTIFY_RUN;
|
||||||
evt.notifySource = this;
|
evt.notifySource = this;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ORDER_PATROL:
|
case ORDER_PATROL:
|
||||||
if ( !this.actions.patrol )
|
if ( !this.actions.patrol )
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ORDER_GENERIC:
|
case ORDER_GENERIC:
|
||||||
evt.notifySource = this;
|
evt.notifySource = this;
|
||||||
switch ( evt.action )
|
switch ( evt.action )
|
||||||
@ -769,11 +853,18 @@ function entityEventPrepareOrder( evt )
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.notifyType = NOTIFY_GATHER;
|
evt.notifyType = NOTIFY_GATHER;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_HEAL:
|
case ACTION_HEAL:
|
||||||
if ( !this.actions.heal )
|
if ( !this.actions.heal )
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.notifyType = NOTIFY_HEAL;
|
evt.notifyType = NOTIFY_HEAL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ACTION_BUILD:
|
||||||
|
if ( !this.actions.build )
|
||||||
|
evt.preventDefault();
|
||||||
|
evt.notifyType = NOTIFY_NONE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -992,7 +1083,6 @@ function entityCheckQueueReq( entity, template )
|
|||||||
function canGather( source, target )
|
function canGather( source, target )
|
||||||
{
|
{
|
||||||
// Checks whether we're allowed to gather from a target entity (this involves looking at both the type and subtype).
|
// Checks whether we're allowed to gather from a target entity (this involves looking at both the type and subtype).
|
||||||
|
|
||||||
if( !source.actions )
|
if( !source.actions )
|
||||||
return false;
|
return false;
|
||||||
g = source.actions.gather;
|
g = source.actions.gather;
|
||||||
@ -1005,6 +1095,17 @@ function canGather( source, target )
|
|||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
|
function canBuild( source, target )
|
||||||
|
{
|
||||||
|
// Checks whether we're allowed to build a target entity
|
||||||
|
if( !source.actions )
|
||||||
|
return false;
|
||||||
|
b = source.actions.build;
|
||||||
|
return (b && target.building != "" && target.player.id == source.player.id );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====================================================================
|
||||||
|
|
||||||
function DamageType()
|
function DamageType()
|
||||||
{
|
{
|
||||||
this.typeless = 0.0;
|
this.typeless = 0.0;
|
||||||
|
31
binaries/data/mods/official/entities/template_foundation.xml
Normal file
31
binaries/data/mods/official/entities/template_foundation.xml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||||
|
|
||||||
|
<Entity
|
||||||
|
Parent="template_entity_full"
|
||||||
|
>
|
||||||
|
<Traits>
|
||||||
|
|
||||||
|
<Id>
|
||||||
|
<Internal_Only />
|
||||||
|
|
||||||
|
<Generic>Foundation</Generic>
|
||||||
|
|
||||||
|
<Icon>sheet_civ</Icon>
|
||||||
|
|
||||||
|
<Classes>Foundation</Classes>
|
||||||
|
</Id>
|
||||||
|
|
||||||
|
<Health>
|
||||||
|
<Bar_Height>6.0</Bar_Height>
|
||||||
|
<Regen_Rate>0.0</Regen_Rate>
|
||||||
|
</Health>
|
||||||
|
|
||||||
|
<Vision>
|
||||||
|
<LOS>3</LOS>
|
||||||
|
</Vision>
|
||||||
|
|
||||||
|
</Traits>
|
||||||
|
|
||||||
|
<Script File="entities/template_entity_script.js" />
|
||||||
|
<Event On="Death" Function="foundationDestroyed" />
|
||||||
|
</Entity>
|
@ -18,6 +18,8 @@
|
|||||||
<Rollover>A civic building that increases the player's population.</Rollover>
|
<Rollover>A civic building that increases the player's population.</Rollover>
|
||||||
|
|
||||||
</Id>
|
</Id>
|
||||||
|
|
||||||
|
<Foundation>foundation_2x2</Foundation>
|
||||||
|
|
||||||
<Footprint>
|
<Footprint>
|
||||||
<Width>9.0</Width>
|
<Width>9.0</Width>
|
||||||
|
@ -87,6 +87,11 @@
|
|||||||
|
|
||||||
<Repair />
|
<Repair />
|
||||||
|
|
||||||
|
<Build>
|
||||||
|
<Rate>1.0</Rate>
|
||||||
|
<Speed>1500</Speed>
|
||||||
|
</Build>
|
||||||
|
|
||||||
</Actions>
|
</Actions>
|
||||||
|
|
||||||
</Entity>
|
</Entity>
|
Loading…
Reference in New Issue
Block a user