1
0
forked from 0ad/0ad

Add battle detection support to the simulation. Refs #1425 (Patch by Zoot)

The audio code does not yet support actually playing battle music.

This was SVN commit r13091.
This commit is contained in:
Jonathan Waller 2013-01-20 22:47:59 +00:00
parent 2d6e3f8ca4
commit 3715985f1a
6 changed files with 17 additions and 2 deletions

View File

@ -376,6 +376,11 @@ function onSimulationUpdate()
updateResearchDisplay(); updateResearchDisplay();
updateBuildingPlacementPreview(); updateBuildingPlacementPreview();
updateTimeElapsedCounter(simState); updateTimeElapsedCounter(simState);
// Update music state on basis of battle state.
var battleState = Engine.GuiInterfaceCall("GetBattleState", Engine.GetPlayerID());
if (battleState)
global.music.setState(global.music.states[battleState]);
} }
function updateGroups() function updateGroups()

View File

@ -698,7 +698,7 @@ Attack.prototype.CauseDamage = function(data)
} }
Engine.PostMessage(data.target, MT_Attacked, Engine.PostMessage(data.target, MT_Attacked,
{ "attacker": this.entity, "target": data.target, "type": data.type }); { "attacker": this.entity, "target": data.target, "type": data.type, "damage": -targetState.change });
PlaySound("attack_impact", this.entity); PlaySound("attack_impact", this.entity);
}; };

View File

@ -605,6 +605,13 @@ GuiInterface.prototype.GetStartedResearch = function(player)
return ret; return ret;
} }
// Returns the battle state of the player.
GuiInterface.prototype.GetBattleState = function(player)
{
var cmpBattleDetection = QueryPlayerIDInterface(player, IID_BattleDetection);
return cmpBattleDetection.GetState();
};
// Used to show a red square over GUI elements you can't yet afford. // Used to show a red square over GUI elements you can't yet afford.
GuiInterface.prototype.GetNeededResources = function(player, amounts) GuiInterface.prototype.GetNeededResources = function(player, amounts)
{ {
@ -1697,6 +1704,7 @@ var exposedFunctions = {
"IsTechnologyResearched": 1, "IsTechnologyResearched": 1,
"CheckTechnologyRequirements": 1, "CheckTechnologyRequirements": 1,
"GetStartedResearch": 1, "GetStartedResearch": 1,
"GetBattleState": 1,
"GetNeededResources": 1, "GetNeededResources": 1,
"GetNextNotification": 1, "GetNextNotification": 1,

View File

@ -155,6 +155,7 @@ Health.prototype.Reduce = function(amount)
Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints }); Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints });
} }
state.change = this.hitpoints - old;
return state; return state;
}; };

View File

@ -2,5 +2,5 @@ Engine.RegisterInterface("Attack");
// Message sent from Attack to the target entity, each // Message sent from Attack to the target entity, each
// time the target is damaged. // time the target is damaged.
// Data: { attacker: 123, target: 234 } // Data: { attacker: 123, target: 234, type: "Melee", damage: 123 }
Engine.RegisterMessageType("Attacked"); Engine.RegisterMessageType("Attacked");

View File

@ -12,4 +12,5 @@
<Player/> <Player/>
<StatisticsTracker/> <StatisticsTracker/>
<TechnologyManager/> <TechnologyManager/>
<BattleDetection/>
</Entity> </Entity>