0ad/binaries/data/mods/public/simulation/helpers/Player.js
Ykkrosh b38e032c7e # Population limits.
Fix #531 (Enforce Population Limit), based on patch from evans.
Empty training queue and refund resources when buildings are destroyed
or captured.
Specify Cost defaults in XML instead of JS, to simplify some code.

This was SVN commit r8014.
2010-08-21 20:43:55 +00:00

39 lines
1.0 KiB
JavaScript

/**
* Similar to Engine.QueryInterface but applies to the player entity
* that owns the given entity.
* iid is typically IID_Player.
*/
function QueryOwnerInterface(ent, iid)
{
var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
if (!cmpOwnership)
return null;
var playerEnt = cmpPlayerMan.GetPlayerByID(cmpOwnership.GetOwner());
if (!playerEnt)
return null;
return Engine.QueryInterface(playerEnt, iid);
}
/**
* Similar to Engine.QueryInterface but applies to the player entity
* with the given ID number.
* iid is typically IID_Player.
*/
function QueryPlayerIDInterface(id, iid)
{
var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
var playerEnt = cmpPlayerMan.GetPlayerByID(id);
if (!playerEnt)
return null;
return Engine.QueryInterface(playerEnt, iid);
}
Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface);
Engine.RegisterGlobal("QueryPlayerIDInterface", QueryPlayerIDInterface);