1
0
forked from mirrors/0ad

Cleaning of GetEntityState part 2

Reviewed By: elexis
Differential Revision: https://code.wildfiregames.com/D1227
This was SVN commit r20965.
This commit is contained in:
mimo
2018-01-22 18:02:38 +00:00
parent dd12d3b8e1
commit d8ed8b1462
4 changed files with 16 additions and 106 deletions
@@ -364,7 +364,7 @@ function displayMultiple(entStates)
}
let carrying = calculateCarriedResources(
entState.resourceCarrying,
entState.resourceCarrying || null,
entState.trader && entState.trader.goods
);
@@ -1098,7 +1098,7 @@ var g_EntityCommands =
"garrison": {
"getInfo": function(entStates)
{
if (entStates.every(entState => !entState.unitAI || entState.turretParent))
if (entStates.every(entState => !entState.unitAI || entState.turretParent || false))
return false;
return {
@@ -1407,7 +1407,7 @@ function someUnitAI(entities)
{
return entities.some(ent => {
let entState = GetEntityState(ent);
return entState && entState.unitAI;
return entState && entState.unitAI || false;
});
}
@@ -1415,7 +1415,7 @@ function someRallyPoints(entities)
{
return entities.some(ent => {
let entState = GetEntityState(ent);
return entState && entState.rallyPoint;
return entState && entState.rallyPoint || false;
});
}
@@ -226,47 +226,8 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
let ret = {
"id": ent,
"template": template,
"alertRaiser": null,
"armour": null,
"attack": null,
"builder": null,
"buildingAI": null,
"buildRate": null,
"buildTime": null,
"canGarrison": null,
"deathDamage": null,
"heal": null,
"identity": null,
"isBarterMarket": null,
"fogging": null,
"foundation": null,
"garrisonHolder": null,
"gate": null,
"guard": null,
"loot": null,
"market": null,
"mirage": null,
"pack": null,
"promotion": null,
"upgrade" : null,
"player": -1,
"position": null,
"production": null,
"rallyPoint": null,
"repairRate": null,
"resourceCarrying": null,
"resourceDropsite": null,
"resourceGatherRates": null,
"resourceSupply": null,
"resourceTrickle": null,
"rotation": null,
"speed": null,
"trader": null,
"turretParent":null,
"unitAI": null,
"visibility": null,
"player": INVALID_PLAYER,
"template": template
};
let cmpMirage = Engine.QueryInterface(ent, IID_Mirage);
@@ -285,10 +246,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
let cmpPosition = Engine.QueryInterface(ent, IID_Position);
if (cmpPosition && cmpPosition.IsInWorld())
{
ret.position = cmpPosition.GetPosition();
ret.rotation = cmpPosition.GetRotation();
}
let cmpHealth = QueryMiragedInterface(ent, IID_Health);
if (cmpHealth)
@@ -347,12 +305,6 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
"goods": cmpTrader.GetGoods()
};
let cmpFogging = Engine.QueryInterface(ent, IID_Fogging);
if (cmpFogging)
ret.fogging = {
"mirage": cmpFogging.IsMiraged(player) ? cmpFogging.GetMirage(player) : null
};
let cmpFoundation = QueryMiragedInterface(ent, IID_Foundation);
if (cmpFoundation)
{
@@ -492,10 +444,6 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
if (cmpArmour)
ret.armour = cmpArmour.GetArmourStrengths();
let cmpAuras = Engine.QueryInterface(ent, IID_Auras);
if (cmpAuras)
ret.auras = cmpAuras.GetDescriptions();
let cmpBuildingAI = Engine.QueryInterface(ent, IID_BuildingAI);
if (cmpBuildingAI)
ret.buildingAI = {
@@ -506,10 +454,6 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
"arrowCount": cmpBuildingAI.GetArrowCount()
};
let cmpDeathDamage = Engine.QueryInterface(ent, IID_DeathDamage);
if (cmpDeathDamage)
ret.deathDamage = cmpDeathDamage.GetDeathDamageStrengths();
if (cmpPosition && cmpPosition.GetTurretParent() != INVALID_ENTITY)
ret.turretParent = cmpPosition.GetTurretParent();
@@ -551,9 +551,6 @@ AddMock(10, IID_Position, {
GetPosition: function() {
return {x:1, y:2, z:3};
},
GetRotation: function() {
return {x:4, y:5, z:6};
},
IsInWorld: function() {
return true;
}
@@ -569,17 +566,8 @@ AddMock(10, IID_ResourceTrickle, {
// matches the ordering in GuiInterface.
TS_ASSERT_UNEVAL_EQUALS(cmp.GetEntityState(-1, 10), {
"id": 10,
"player": INVALID_PLAYER,
"template": "example",
"alertRaiser": null,
"armour": null,
"attack": null,
"builder": true,
"buildingAI": null,
"buildRate": null,
"buildTime": null,
"canGarrison": false,
"deathDamage": null,
"heal": null,
"identity": {
"rank": "foo",
"classes": ["class1", "class2"],
@@ -587,39 +575,17 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetEntityState(-1, 10), {
"selectionGroupName": "Selection Group Name",
"canDelete": true
},
"isBarterMarket": true,
"fogging": null,
"foundation": null,
"garrisonHolder": null,
"gate": null,
"guard": null,
"loot": null,
"market": null,
"mirage": null,
"pack": null,
"promotion": null,
"upgrade" : null,
"player": INVALID_PLAYER,
"position": {x:1, y:2, z:3},
"production": null,
"rallyPoint": null,
"repairRate": null,
"resourceCarrying": null,
"resourceDropsite": null,
"resourceGatherRates": null,
"resourceSupply": null,
"resourceTrickle": {
"interval": 1250,
"rates": { "food": 2, "wood": 3, "stone": 5, "metal": 9 }
},
"rotation": {x:4, y:5, z:6},
"speed": null,
"trader": null,
"turretParent":null,
"unitAI": null,
"visibility": "visible",
"hitpoints": 50,
"maxHitpoints": 60,
"needsRepair": false,
"needsHeal": true
"needsHeal": true,
"builder": true,
"canGarrison": false,
"visibility": "visible",
"isBarterMarket":true,
"resourceTrickle": {
"interval": 1250,
"rates": { "food": 2, "wood": 3, "stone": 5, "metal": 9 }
}
});