let entities change entity limits. Fixes #2076
This was SVN commit r13850.
This commit is contained in:
parent
de68973191
commit
f213761912
@ -1615,7 +1615,7 @@ function getEntityLimitAndCount(playerState, entType)
|
||||
var entLimit = undefined;
|
||||
var entCount = undefined;
|
||||
var canBeAddedCount = undefined;
|
||||
if (entCategory && playerState.entityLimits[entCategory])
|
||||
if (entCategory && playerState.entityLimits[entCategory] != null)
|
||||
{
|
||||
entLimit = playerState.entityLimits[entCategory];
|
||||
entCount = playerState.entityCounts[entCategory];
|
||||
|
@ -23,12 +23,7 @@ EntityLimits.prototype.Schema =
|
||||
"<zeroOrMore>" +
|
||||
"<element a:help='Specifies a category of building/unit on which to apply this limit. See BuildRestrictions/TrainingRestrictions for list of categories.'>" +
|
||||
"<anyName />" +
|
||||
"<choice>" +
|
||||
"<text />" +
|
||||
"<element name='LimitPerCivCentre' a:help='Specifies that this limit is per number of civil centres.'>" +
|
||||
"<data type='nonNegativeInteger'/>" +
|
||||
"</element>" +
|
||||
"</choice>" +
|
||||
"<data type='integer'/>" +
|
||||
"</element>" +
|
||||
"</zeroOrMore>" +
|
||||
"</element>";
|
||||
@ -46,11 +41,26 @@ EntityLimits.prototype.Init = function()
|
||||
this.count = {};
|
||||
for (var category in this.template.Limits)
|
||||
{
|
||||
this.limit[category] = this.template.Limits[category];
|
||||
this.limit[category] = +this.template.Limits[category];
|
||||
this.count[category] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
EntityLimits.prototype.IncreaseLimit = function(category, value)
|
||||
{
|
||||
if (!this.limit[category])
|
||||
this.limit[category] = 0;
|
||||
this.limit[category] += value;
|
||||
};
|
||||
|
||||
EntityLimits.prototype.DecreaseLimit = function(category, value)
|
||||
{
|
||||
if (!this.limit[category])
|
||||
this.limit[category] = 0;
|
||||
this.limit[category] -= value;
|
||||
|
||||
};
|
||||
|
||||
EntityLimits.prototype.IncreaseCount = function(category, value)
|
||||
{
|
||||
if (this.count[category] !== undefined)
|
||||
@ -92,24 +102,7 @@ EntityLimits.prototype.AllowedToCreate = function(limitType, category, count)
|
||||
if (this.count[category] === undefined || this.limit[category] === undefined)
|
||||
return true;
|
||||
|
||||
// Rather than complicating the schema unecessarily, just handle special cases here
|
||||
if (this.limit[category].LimitPerCivCentre !== undefined)
|
||||
{
|
||||
if (this.count[category] >= this.count["CivilCentre"] * this.limit[category].LimitPerCivCentre)
|
||||
{
|
||||
var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
|
||||
var notification = {
|
||||
"player": cmpPlayer.GetPlayerID(),
|
||||
"message": category + " " + limitType + " limit of " +
|
||||
this.limit[category].LimitPerCivCentre + " per civil centre reached"
|
||||
};
|
||||
var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
cmpGUIInterface.PushNotification(notification);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (this.count[category] + count > this.limit[category])
|
||||
if (this.count[category] + count > this.limit[category])
|
||||
{
|
||||
var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
|
||||
var notification = {
|
||||
|
@ -0,0 +1,58 @@
|
||||
function EntityLimitsChanger() {}
|
||||
|
||||
EntityLimitsChanger.prototype.Schema =
|
||||
"<oneOrMore>" +
|
||||
"<element a:help='Take as name the name of the category, and as value the number you want to increase the limit with.'>" +
|
||||
"<anyName/>" +
|
||||
"<data type='integer'/>" +
|
||||
"</element>" +
|
||||
"</oneOrMore>";
|
||||
|
||||
EntityLimitsChanger.prototype.init = function()
|
||||
{
|
||||
};
|
||||
|
||||
EntityLimitsChanger.prototype.OnOwnershipChanged = function(msg)
|
||||
{
|
||||
if (!this.changes)
|
||||
{
|
||||
this.changes = {};
|
||||
for (var cat in this.template)
|
||||
this.changes[cat] = ApplyTechModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
|
||||
}
|
||||
|
||||
if (msg.from > -1)
|
||||
{
|
||||
var cmpEntityLimits = QueryPlayerIDInterface(msg.from, IID_EntityLimits);
|
||||
if (cmpEntityLimits)
|
||||
for (var cat in this.changes)
|
||||
cmpEntityLimits.DecreaseLimit(cat, this.changes[cat]);
|
||||
}
|
||||
|
||||
if (msg.to > -1)
|
||||
{
|
||||
var cmpEntityLimits = QueryPlayerIDInterface(msg.to, IID_EntityLimits);
|
||||
if (cmpEntityLimits)
|
||||
for (var cat in this.changes)
|
||||
cmpEntityLimits.IncreaseLimit(cat, this.changes[cat]);
|
||||
}
|
||||
}
|
||||
|
||||
EntityLimitsChanger.prototype.OnTechnologyModification = function(msg)
|
||||
{
|
||||
if (msg.component != "EntityLimitsChanger")
|
||||
return;
|
||||
|
||||
var cmpEntityLimits = Engine.QueryOwnerInterface(this.entity, IID_EntityLimits);
|
||||
if (!cmpEntityLimits)
|
||||
return;
|
||||
|
||||
for (var cat in this.changes)
|
||||
{
|
||||
cmpEntityLimits.DecreaseLimit(cat, this.changes[cat]);
|
||||
this.changes[cat] = ApplyTechModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
|
||||
cmpEntityLimits.IncreaseLimit(cat, this.changes[cat]);
|
||||
}
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_EntityLimitsChanger, "EntityLimitsChanger", EntityLimitsChanger);
|
@ -11,6 +11,7 @@ TrainingRestrictions.prototype.Schema =
|
||||
"<choice>" +
|
||||
"<value>Hero</value>" +
|
||||
"<value>FemaleCitizen</value>" +
|
||||
"<value>WarDog</value>" +
|
||||
"</choice>" +
|
||||
"</element>";
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
Engine.RegisterInterface("EntityLimitsChanger");
|
@ -3,7 +3,6 @@
|
||||
<EntityLimits>
|
||||
<LimitMultiplier>1.0</LimitMultiplier>
|
||||
<Limits>
|
||||
<CivilCentre/>
|
||||
<DefenseTower>25</DefenseTower>
|
||||
<Fortress>10</Fortress>
|
||||
<Wonder>1</Wonder>
|
||||
@ -11,6 +10,8 @@
|
||||
<Apadana>1</Apadana>
|
||||
<Embassy>2</Embassy>
|
||||
<Monument>5</Monument>
|
||||
<Pillar>0</Pillar>
|
||||
<WarDog>0</WarDog>
|
||||
</Limits>
|
||||
</EntityLimits>
|
||||
<Player/>
|
||||
|
@ -18,6 +18,9 @@
|
||||
<stone>50</stone>
|
||||
</Resources>
|
||||
</Cost>
|
||||
<EntityLimitsChanger>
|
||||
<WarDog>10</WarDog>
|
||||
</EntityLimitsChanger>
|
||||
<Footprint>
|
||||
<Square width="8.0" depth="7.0"/>
|
||||
<Height>5.0</Height>
|
||||
@ -31,7 +34,7 @@
|
||||
<Civ>brit</Civ>
|
||||
<GenericName>Special Building</GenericName>
|
||||
<SpecificName>Kennel</SpecificName>
|
||||
<Tooltip>Train Celtic war dogs.</Tooltip>
|
||||
<Tooltip>Train Celtic war dogs. One kennel can only house 10 dogs.</Tooltip>
|
||||
<Icon>structures/kennel.png</Icon>
|
||||
<RequiredTechnology>phase_town</RequiredTechnology>
|
||||
</Identity>
|
||||
|
@ -18,6 +18,9 @@
|
||||
<stone>50</stone>
|
||||
</Resources>
|
||||
</Cost>
|
||||
<EntityLimitsChanger>
|
||||
<WarDog>10</WarDog>
|
||||
</EntityLimitsChanger>
|
||||
<Footprint>
|
||||
<Square width="8.0" depth="7.0"/>
|
||||
<Height>5.0</Height>
|
||||
@ -31,7 +34,7 @@
|
||||
<Civ>celt</Civ>
|
||||
<GenericName>Special Building</GenericName>
|
||||
<SpecificName>Kennel</SpecificName>
|
||||
<Tooltip>Train Celtic war dogs.</Tooltip>
|
||||
<Tooltip>Train Celtic war dogs. One kennel can only house 10 dogs.</Tooltip>
|
||||
<Icon>structures/kennel.png</Icon>
|
||||
<RequiredTechnology>phase_town</RequiredTechnology>
|
||||
</Identity>
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Entity parent="template_structure_special">
|
||||
<Cost>
|
||||
<BuildTime>80</BuildTime>
|
||||
<Resources>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Entity parent="template_structure_special">
|
||||
<BuildRestrictions>
|
||||
<Category>Pillar</Category>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
<BuildTime>80</BuildTime>
|
||||
<Resources>
|
||||
<food>0</food>
|
||||
<wood>0</wood>
|
||||
<stone>100</stone>
|
||||
@ -20,13 +23,13 @@
|
||||
</Health>
|
||||
<Identity>
|
||||
<Civ>maur</Civ>
|
||||
<GenericName>Edict Pillar of Ashoka</GenericName>
|
||||
<SpecificName>Śāsana Stambha Aśokā</SpecificName>
|
||||
<Icon>structures/monument.png</Icon>
|
||||
<Tooltip>.</Tooltip>
|
||||
<History>.</History>
|
||||
</Identity>
|
||||
<Obstruction>
|
||||
<GenericName>Edict Pillar of Ashoka</GenericName>
|
||||
<SpecificName>Śāsana Stambha Aśokā</SpecificName>
|
||||
<Icon>structures/monument.png</Icon>
|
||||
<Tooltip>The famous pillar of Ashoka. Can only be build when the hero Ashoka is alive. Currently a useless structure.</Tooltip>
|
||||
<History>.</History>
|
||||
</Identity>
|
||||
<Obstruction>
|
||||
<Static width="4" depth="4"/>
|
||||
</Obstruction>
|
||||
<RallyPoint disable=""/>
|
||||
|
@ -59,7 +59,7 @@
|
||||
</Attack>
|
||||
<Cost>
|
||||
<BuildTime>10</BuildTime>
|
||||
<Population>1</Population>
|
||||
<Population>0</Population>
|
||||
<Resources>
|
||||
<food>100</food>
|
||||
<wood>0</wood>
|
||||
@ -119,6 +119,9 @@
|
||||
<StatusBars>
|
||||
<HeightOffset>6.5</HeightOffset>
|
||||
</StatusBars>
|
||||
<TrainingRestrictions>
|
||||
<Category>WarDog</Category>
|
||||
</TrainingRestrictions>
|
||||
<UnitMotion>
|
||||
<WalkSpeed>13.0</WalkSpeed>
|
||||
<Run>
|
||||
|
@ -12,12 +12,6 @@
|
||||
<MinRange>12.0</MinRange>
|
||||
</Ranged>
|
||||
</Attack>
|
||||
<Builder>
|
||||
<Rate>1.0</Rate>
|
||||
<Entities datatype="tokens">
|
||||
structures/maur_pillar_ashoka
|
||||
</Entities>
|
||||
</Builder>
|
||||
<Cost>
|
||||
<Population>4</Population>
|
||||
<BuildTime>50</BuildTime>
|
||||
@ -27,6 +21,9 @@
|
||||
<metal>100</metal>
|
||||
</Resources>
|
||||
</Cost>
|
||||
<EntityLimitsChanger>
|
||||
<Pillar>5</Pillar>
|
||||
</EntityLimitsChanger>
|
||||
<Footprint replace="">
|
||||
<Square width="6.0" depth="12.0"/>
|
||||
<Height>5.0</Height>
|
||||
|
@ -9,6 +9,7 @@
|
||||
<Builder>
|
||||
<Entities datatype="tokens">
|
||||
structures/maur_elephant_stables
|
||||
structures/maur_pillar_ashoka
|
||||
structures/{civ}_wonder
|
||||
</Entities>
|
||||
</Builder>
|
||||
|
@ -4,6 +4,7 @@
|
||||
<Rate>1.0</Rate>
|
||||
<Entities datatype="tokens">
|
||||
structures/maur_elephant_stables
|
||||
structures/maur_pillar_ashoka
|
||||
structures/{civ}_wonder
|
||||
</Entities>
|
||||
</Builder>
|
||||
|
@ -11,6 +11,7 @@
|
||||
<Builder>
|
||||
<Entities datatype="tokens">
|
||||
structures/maur_elephant_stables
|
||||
structures/maur_pillar_ashoka
|
||||
structures/{civ}_wonder
|
||||
</Entities>
|
||||
</Builder>
|
||||
|
Loading…
Reference in New Issue
Block a user