- Fixed the issue that was causing crashes when you tried to place one of them. They had 2 problems: first the template_structure_special whose parent was itself, as Phillip pointed out, but second also incorrect actor names. I also made the Carthaginian wall refer to the right parent template.

- Added a "dropsite" aura to mills, farmsteads and civil centers, and
modified the gathering code so you can only gather objects that have
this aura on them from one of these buildings. You can also add a
traits.supply.forageable tag to an entity to make it ignore the
requirement for dropsites and gather it wherever it is. I did this for
hunting, so you can hunt without being near a farmstead.

This was SVN commit r3265.
This commit is contained in:
Matei 2005-12-17 09:28:26 +00:00
parent 2d477a09cf
commit 1bedd9457a
14 changed files with 144 additions and 45 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<Entity
Parent="template_structure_civic_wall"
Parent="template_structure_defense_wall"
>
<Traits>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<Entity
Parent="template_structure_economic_farmstead"
Parent="template_structure_economic_mill"
>
<Traits>

View File

@ -17,6 +17,6 @@
</Traits>
<Actor>structures/celts/Ffactri.xml</Actor>
<Actor>structures/celts/special.xml</Actor>
</Entity>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<Entity
Parent="template_structure_economic_farmstead"
Parent="template_structure_economic_mill"
>
<Traits>

View File

@ -17,6 +17,6 @@
</Traits>
<Actor>structures/hellenes/theatron.xml</Actor>
<Actor>structures/hellenes/special_theatre.xml</Actor>
</Entity>

View File

@ -17,6 +17,6 @@
</Traits>
<Actor>structures/hellenes/gymnasion.xml</Actor>
<Actor>structures/hellenes/special_gym.xml</Actor>
</Entity>

View File

@ -29,7 +29,6 @@ function entityInit()
if (this.traits.supply)
{
// If entity has supply, set current to same.
if (this.traits.supply.max)
this.traits.supply.curr = this.traits.supply.max
@ -38,6 +37,17 @@ function entityInit()
// (so we don't have to say type="wood", subtype="wood"
if (this.traits.supply.type && !this.traits.supply.subtype)
this.traits.supply.subtype = this.traits.supply.type
// 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,
// you can still gather from the thing. Initialize it to 0 (ungatherable) for every player unless
// the entity is forageable (e.g. for huntable animals).
this.traits.supply.dropsitecount = new Array();
initialCount = this.traits.supply.forageable ? 1 : 0;
for( i=0; i<=8; i++ )
{
this.traits.supply.dropsitecount[i] = initialCount;
}
}
if (!this.traits.promotion)
@ -109,6 +119,10 @@ function entityInit()
a = this.traits.auras.infidelity;
this.addAura ( name, a.radius, new InfidelityAura( this ) );
break;
case "dropsite":
a = this.traits.auras.dropsite;
this.addAura ( name, a.radius, new DropsiteAura( this, a.types ) );
break;
default:
console.write ( "Unknown aura: " + name + " on " + this + "; ignoring it." );
break;
@ -246,23 +260,39 @@ function projectileEventImpact( evt )
function entityEventGather( evt )
{
if (this.actions.gather.resource[evt.target.traits.supply.type][evt.target.traits.supply.subtype])
gather_amt = parseInt( this.actions.gather.resource[evt.target.traits.supply.type][evt.target.traits.supply.subtype] );
else
gather_amt = parseInt( this.actions.gather.resource[evt.target.traits.supply.type] );
g = this.actions.gather;
s = evt.target.traits.supply;
if( evt.target.traits.supply.max > 0 )
if( !s.dropsitecount[this.player.id] )
{
if( evt.target.traits.supply.curr <= gather_amt )
// Entity has become ungatherable for us, probably meaning our mill near it was killed
// Get that gather order off the queue (really there should be a stop() method for this)
this.order( ORDER_GOTO, this.position.x, this.position.z );
return;
}
if( g.resource[s.type][s.subtype])
gather_amt = parseInt( g.resource[s.type][s.subtype] );
else
gather_amt = parseInt( g.resource[s.type] );
if( s.max > 0 )
{
gather_amt = evt.target.traits.supply.curr;
evt.target.kill();
if( s.curr <= gather_amt )
{
gather_amt = s.curr;
}
// Remove amount from target.
evt.target.traits.supply.curr -= gather_amt;
s.curr -= gather_amt;
// Add extracted resources to player's resource pool.
getGUIGlobal().giveResources(evt.target.traits.supply.type.toString(), parseInt(gather_amt));
getGUIGlobal().giveResources(s.type.toString(), parseInt(gather_amt));
// Kill the target if it's now out of resources
if( s.curr == 0 )
{
evt.target.kill();
}
}
}
@ -448,16 +478,14 @@ function entityEventTargetChanged( evt )
if( evt.target && this.actions )
{
if( this.actions.attack &&
( evt.target.player != this.player ) )
evt.target.player != this.player &&
evt.target.traits.health &&
evt.target.traits.health.max != 0 )
{
evt.defaultAction = NMT_AttackMelee;
evt.defaultCursor = "action-attack";
}
g = this.actions.gather;
s = evt.target.traits.supply;
if( g && s && g.resource && g.resource[s.type] &&
( s.subtype==s.type || g.resource[s.type][s.subtype] ) &&
( s.curr > 0 || s.max == 0 ) )
if( canGather( this, evt.target ) )
{
evt.defaultAction = NMT_Gather;
// Set cursor (eg "action-gather-fruit").
@ -496,9 +524,7 @@ function entityEventPrepareOrder( evt )
evt.preventDefault();
break;
case ORDER_GATHER:
if( !this.actions.gather || !this.actions.gather.resource ||
!( this.actions.gather.resource[evt.target.traits.supply.type] ) ||
( ( evt.target.traits.supply.curr == 0 ) && ( evt.target.traits.supply.max > 0 ) ) )
if( !canGather( this, evt.target ) )
evt.preventDefault();
break;
default:
@ -685,6 +711,20 @@ function entityCheckQueueReq( entity, template )
// ====================================================================
function canGather( source, target )
{
if( !source.actions )
return false;
g = source.actions.gather;
s = target.traits.supply;
return ( g && s && g.resource && g.resource[s.type] &&
( s.subtype==s.type || g.resource[s.type][s.subtype] ) &&
( s.curr > 0 || s.max == 0 ) &&
s.dropsitecount[source.player.id] );
}
// ====================================================================
function DamageModifyAura ( source, ally, bonus )
{
// Defines the effects of the DamageModify Aura. (Adjacent units have modified attack bonus.)
@ -711,7 +751,7 @@ function DamageModifyAura ( source, ally, bonus )
{
if( this.affects( e ) )
{
console.write( "DamageModify aura: giving " + this.bonus + " damage to " + e );
//console.write( "DamageModify aura: giving " + this.bonus + " damage to " + e );
e.actions.attack.damage += this.bonus;
}
};
@ -720,7 +760,7 @@ function DamageModifyAura ( source, ally, bonus )
{
if( this.affects( e ) )
{
console.write( "DamageModify aura: taking away " + this.bonus + " damage from " + e );
//console.write( "DamageModify aura: taking away " + this.bonus + " damage from " + e );
e.actions.attack.damage -= this.bonus;
}
};
@ -728,6 +768,40 @@ function DamageModifyAura ( source, ally, bonus )
// ====================================================================
function DropsiteAura ( source, types )
{
// Defines the effects of the Gather aura. Enables resource gathering on entities
// near the source for it's owner.
this.source = source;
this.types = types;
this.affects = function( e )
{
return( e.traits.supply && this.types[e.traits.supply.type] );
}
this.onEnter = function( e )
{
if( this.affects( e ) )
{
//console.write( "Dropsite aura: adding +1 for " + this.source.player.id + " on " + e );
e.traits.supply.dropsitecount[this.source.player.id]++;
}
};
this.onExit = function( e )
{
if( this.affects( e ) )
{
//console.write( "Dropsite aura: adding -1 for " + this.source.player.id + " on " + e );
e.traits.supply.dropsitecount[this.source.player.id]--;
}
};
}
// ====================================================================
function InfidelityAura ( source )
{
// Defines the effects of the Infidelity Aura. Changes ownership of entity when only one player's units surrounds them.
@ -749,7 +823,7 @@ function InfidelityAura ( source )
{
if( this.affects( e ) )
{
console.write( "Infidelity aura: adding +1 count to " + e.player.id );
//console.write( "Infidelity aura: adding +1 count to " + e.player.id );
this.count[e.player.id]++;
this.changePlayerIfNeeded();
}
@ -759,7 +833,7 @@ function InfidelityAura ( source )
{
if( this.affects( e ) )
{
console.write( "Infidelity aura: adding -1 count to " + e.player.id );
//console.write( "Infidelity aura: adding -1 count to " + e.player.id );
this.count[e.player.id]--;
this.changePlayerIfNeeded();
}
@ -782,7 +856,7 @@ function InfidelityAura ( source )
}
if( bestCount > 0 )
{
console.write( "Infidelity aura: changing ownership to " + bestPlayer );
//console.write( "Infidelity aura: changing ownership to " + bestPlayer );
this.source.player = players[bestPlayer];
}
}

View File

@ -20,10 +20,6 @@
</Id>
<Health>
<Max>100</Max>
</Health>
<MiniMap>
<Type>Food</Type>
<Red>205</Red>

View File

@ -19,10 +19,6 @@
</Id>
<Health>
<Max>100</Max>
</Health>
<MiniMap>
<Type>Wood</Type>
<Red>0</Red>

View File

@ -37,6 +37,18 @@
<Add>10</Add>
</Population>
<Auras>
<Dropsite>
<Radius>50</Radius>
<Types>
<Food/>
<Wood/>
<Stone/>
<Ore/>
</Types>
</Dropsite>
</Auras>
</Traits>
<Actions>

View File

@ -31,5 +31,14 @@
<Max>50</Max>
</Health>
<Auras>
<Dropsite>
<Radius>50</Radius>
<Types>
<Food/>
</Types>
</Dropsite>
</Auras>
</Traits>
</Entity>

View File

@ -29,6 +29,17 @@
<Max>50</Max>
</Health>
<Auras>
<Dropsite>
<Radius>50</Radius>
<Types>
<Wood/>
<Stone/>
<Ore/>
</Types>
</Dropsite>
</Auras>
</Traits>
</Entity>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<Entity
Parent="template_structure_special"
Parent="template_structure"
>
<Traits>

View File

@ -36,6 +36,7 @@
<Max>100</Max>
<Type>food</Type>
<SubType>meat</SubType>
<Forageable />
</Supply>
</Traits>