Made garrisoning based on the quantity of units, not the population cost of those units.

This was SVN commit r8453.
This commit is contained in:
WhiteTreePaladin 2010-10-24 01:14:34 +00:00
parent 7f52ca875b
commit 3521c8f51e
3 changed files with 19 additions and 10 deletions

View File

@ -552,6 +552,7 @@
<repeat count="6"> <repeat count="6">
<object name="unitCommandButton[n]" hidden="true" style="iconButton" type="button" size="0 0 32 32" tooltip_style="snToolTipBottom"> <object name="unitCommandButton[n]" hidden="true" style="iconButton" type="button" size="0 0 32 32" tooltip_style="snToolTipBottom">
<object name="unitCommandIcon[n]" ghost="true" type="image" size="0 0 100% 100%" style="commandIcon"/> <object name="unitCommandIcon[n]" ghost="true" type="image" size="0 0 100% 100%" style="commandIcon"/>
<object name="unitCommandCount[n]" ghost="true" style="groupIconsText" type="text" size="0 0 100% 100%"/>
</object> </object>
</repeat> </repeat>
</object> </object>

View File

@ -218,6 +218,12 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
break; break;
case COMMAND: case COMMAND:
if (item == "unload-all")
{
var count = unitEntState.garrisonHolder.entities.length;
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : "");
}
tooltip = toTitleCase(item); tooltip = toTitleCase(item);
break; break;

View File

@ -27,7 +27,6 @@ GarrisonHolder.prototype.Init = function()
this.spaceOccupied = 0; this.spaceOccupied = 0;
this.timer = undefined; this.timer = undefined;
this.healRate = this.template.BuffHeal; this.healRate = this.template.BuffHeal;
}; };
/** /**
@ -67,10 +66,11 @@ GarrisonHolder.prototype.Garrison = function(entity)
var entityClasses = (Engine.QueryInterface(entity, IID_Identity)).GetClassesList(); var entityClasses = (Engine.QueryInterface(entity, IID_Identity)).GetClassesList();
var allowedClasses = this.GetAllowedClassesList(); var allowedClasses = this.GetAllowedClassesList();
var classNotAllowed = true; var classNotAllowed = true;
if (!this.HasEnoughHealth()) if (!this.HasEnoughHealth())
return false; return false;
//Check if the unit is allowed to be garrisoned inside the building
// Check if the unit is allowed to be garrisoned inside the building
for each (var allowedClass in allowedClasses) for each (var allowedClass in allowedClasses)
{ {
if (entityClasses.indexOf(allowedClass) != -1) if (entityClasses.indexOf(allowedClass) != -1)
@ -79,21 +79,25 @@ GarrisonHolder.prototype.Garrison = function(entity)
break; break;
} }
} }
if (classNotAllowed) if (classNotAllowed)
return false; return false;
if (this.GetCapacity() < (this.spaceOccupied + entityPopCost))
if (this.GetCapacity() < this.spaceOccupied + 1)
return false; return false;
var cmpPosition = Engine.QueryInterface(entity, IID_Position);
if (!this.timer) if (!this.timer)
{ {
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {});
} }
var cmpPosition = Engine.QueryInterface(entity, IID_Position);
if (cmpPosition) if (cmpPosition)
{ {
//Actual garrisoning happens here // Actual garrisoning happens here
this.entities.push(entity); this.entities.push(entity);
this.spaceOccupied += entityPopCost; this.spaceOccupied += 1;
cmpPosition.MoveOutOfWorld(); cmpPosition.MoveOutOfWorld();
return true; return true;
} }
@ -110,7 +114,7 @@ GarrisonHolder.prototype.Unload = function(entity)
{ {
var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint); var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint);
var entityIndex = this.entities.indexOf(entity); var entityIndex = this.entities.indexOf(entity);
this.spaceOccupied -= (Engine.QueryInterface(entity, IID_Cost)).GetPopCost(); this.spaceOccupied -= 1;
this.entities.splice(entityIndex, 1); this.entities.splice(entityIndex, 1);
var cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint); var cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint);
var pos = cmpFootprint.PickSpawnPoint(entity); var pos = cmpFootprint.PickSpawnPoint(entity);
@ -154,7 +158,6 @@ GarrisonHolder.prototype.OnHealthChanged = function(msg)
{ {
this.UnloadAll(); this.UnloadAll();
} }
}; };
/** /**
@ -167,7 +170,6 @@ GarrisonHolder.prototype.HasEnoughHealth = function()
var maxHitpoints = cmpHealth.GetMaxHitpoints(); var maxHitpoints = cmpHealth.GetMaxHitpoints();
var ejectHitpoints = parseInt(parseFloat(this.template.EjectHealth) * maxHitpoints); var ejectHitpoints = parseInt(parseFloat(this.template.EjectHealth) * maxHitpoints);
return hitpoints > ejectHitpoints; return hitpoints > ejectHitpoints;
}; };
/** /**