Differential D2426 Diff 12871 ps/trunk/binaries/data/mods/public/simulation/components/PlayerManager.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/PlayerManager.js
function PlayerManager() {} | function PlayerManager() {} | ||||
PlayerManager.prototype.Schema = | PlayerManager.prototype.Schema = | ||||
"<a:component type='system'/><empty/>"; | "<a:component type='system'/><empty/>"; | ||||
PlayerManager.prototype.Init = function() | PlayerManager.prototype.Init = function() | ||||
{ | { | ||||
this.playerEntities = []; // list of player entity IDs | // List of player entity IDs. | ||||
this.playerEntities = []; | |||||
// Maximum world population (if applicable will be distributed amongst living players). | |||||
this.maxWorldPopulation = undefined; | |||||
}; | }; | ||||
PlayerManager.prototype.AddPlayer = function(ent) | PlayerManager.prototype.AddPlayer = function(ent) | ||||
{ | { | ||||
var id = this.playerEntities.length; | var id = this.playerEntities.length; | ||||
var cmpPlayer = Engine.QueryInterface(ent, IID_Player); | var cmpPlayer = Engine.QueryInterface(ent, IID_Player); | ||||
cmpPlayer.SetPlayerID(id); | cmpPlayer.SetPlayerID(id); | ||||
this.playerEntities.push(ent); | this.playerEntities.push(ent); | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | PlayerManager.prototype.RemoveLastPlayer = function() | ||||
Engine.BroadcastMessage(MT_PlayerEntityChanged, { | Engine.BroadcastMessage(MT_PlayerEntityChanged, { | ||||
"player": this.playerEntities.length + 1, | "player": this.playerEntities.length + 1, | ||||
"from": lastId, | "from": lastId, | ||||
"to": INVALID_ENTITY | "to": INVALID_ENTITY | ||||
}); | }); | ||||
Engine.DestroyEntity(lastId); | Engine.DestroyEntity(lastId); | ||||
}; | }; | ||||
PlayerManager.prototype.SetMaxWorldPopulation = function(max) | |||||
{ | |||||
this.maxWorldPopulation = max; | |||||
this.RedistributeWorldPopulation(); | |||||
}; | |||||
PlayerManager.prototype.GetMaxWorldPopulation = function() | |||||
{ | |||||
return this.maxWorldPopulation; | |||||
}; | |||||
PlayerManager.prototype.RedistributeWorldPopulation = function() | |||||
{ | |||||
let worldPopulation = this.GetMaxWorldPopulation(); | |||||
if (!worldPopulation) | |||||
return; | |||||
let activePlayers = this.GetActivePlayers(); | |||||
if (!activePlayers.length) | |||||
return; | |||||
let newMaxPopulation = worldPopulation / activePlayers.length; | |||||
for (let playerID of activePlayers) | |||||
QueryPlayerIDInterface(playerID).SetMaxPopulation(newMaxPopulation); | |||||
}; | |||||
PlayerManager.prototype.OnGlobalPlayerDefeated = function(msg) | |||||
{ | |||||
this.RedistributeWorldPopulation(); | |||||
}; | |||||
Engine.RegisterSystemComponentType(IID_PlayerManager, "PlayerManager", PlayerManager); | Engine.RegisterSystemComponentType(IID_PlayerManager, "PlayerManager", PlayerManager); |
Wildfire Games · Phabricator