mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-20 07:13:56 -07:00
Added the ability to disable training/building of entities by triggers. Changes survival of the fittest random map to work with this. Refs #52
This was SVN commit r15614.
This commit is contained in:
parent
f7e591c9f2
commit
016d4599e1
6 changed files with 84 additions and 14 deletions
|
|
@ -117,6 +117,12 @@ var g_NotificationsTypes =
|
|||
if (player == Engine.GetPlayerID())
|
||||
openDialog(notification.dialogName, notification.data, player);
|
||||
},
|
||||
"resetselectionpannel": function(notification, player)
|
||||
{
|
||||
if (player != Engine.GetPlayerID())
|
||||
return;
|
||||
g_Selection.rebuildSelection([]);
|
||||
}
|
||||
};
|
||||
|
||||
// Notifications
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
"BaseTerrain" : ["medit_sea_depths"],
|
||||
"BaseHeight" : 30,
|
||||
"CircularMap" : true,
|
||||
"Keywords": ["demo"],
|
||||
"TriggerScripts": [
|
||||
"scripts/TriggerHelper.js",
|
||||
"random/survivalofthefittest_triggers.js"
|
||||
|
|
|
|||
|
|
@ -100,6 +100,16 @@ Trigger.prototype.InitGame = function()
|
|||
}
|
||||
}
|
||||
|
||||
// Fix alliances
|
||||
for (var i = 1; i < numberOfPlayers; ++i)
|
||||
{
|
||||
var cmpPlayer = TriggerHelper.GetPlayerComponent(i);
|
||||
for (var j = 1; j < numberOfPlayers; ++j)
|
||||
if (i != j)
|
||||
cmpPlayer.SetAlly(j);
|
||||
cmpPlayer.SetLockTeams(true);
|
||||
}
|
||||
|
||||
// make gaia black
|
||||
TriggerHelper.GetPlayerComponent(0).SetColour(0, 0, 0);
|
||||
|
||||
|
|
@ -133,22 +143,24 @@ Trigger.prototype.DefeatPlayerOnceCCIsDestroyed = function(data)
|
|||
{
|
||||
// Defeat a player that has lost his civic center
|
||||
if (data.entity == cmpTrigger.playerCivicCenter[data.from] && data.to == -1)
|
||||
{
|
||||
TriggerHelper.DefeatPlayer(data.from);
|
||||
|
||||
// Check if only one player remains. He will be the winner.
|
||||
var lastPlayerStanding = 0;
|
||||
var numPlayersStanding = 0;
|
||||
var numberOfPlayers = TriggerHelper.GetNumberOfPlayers();
|
||||
for (var i = 1; i < numberOfPlayers; ++i)
|
||||
{
|
||||
if (TriggerHelper.GetPlayerComponent(i).GetState() == "active")
|
||||
// Check if only one player remains. He will be the winner.
|
||||
var lastPlayerStanding = 0;
|
||||
var numPlayersStanding = 0;
|
||||
var numberOfPlayers = TriggerHelper.GetNumberOfPlayers();
|
||||
for (var i = 1; i < numberOfPlayers; ++i)
|
||||
{
|
||||
lastPlayerStanding = i;
|
||||
++numPlayersStanding;
|
||||
if (TriggerHelper.GetPlayerComponent(i).GetState() == "active")
|
||||
{
|
||||
lastPlayerStanding = i;
|
||||
++numPlayersStanding;
|
||||
}
|
||||
}
|
||||
if (numPlayersStanding == 1)
|
||||
TriggerHelper.SetPlayerWon(lastPlayerStanding);
|
||||
}
|
||||
if (numPlayersStanding == 1)
|
||||
TriggerHelper.SetPlayerWon(lastPlayerStanding);
|
||||
}
|
||||
|
||||
var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,14 @@ Builder.prototype.GetEntitiesList = function()
|
|||
if (cmpIdentity)
|
||||
string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv());
|
||||
entities = string.split(/\s+/);
|
||||
|
||||
// Remove disabled entities
|
||||
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player)
|
||||
var disabledEntities = cmpPlayer.GetDisabledTemplates();
|
||||
|
||||
for (var i = entities.length - 1; i >= 0; --i)
|
||||
if (disabledEntities[entities[i]])
|
||||
entities.splice(i, 1);
|
||||
}
|
||||
return entities;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ Player.prototype.Init = function()
|
|||
"metal": markForTranslation("Metal"),
|
||||
"stone": markForTranslation("Stone"),
|
||||
}
|
||||
this.disabledTemplates = {};
|
||||
};
|
||||
|
||||
Player.prototype.SetPlayerID = function(id)
|
||||
|
|
@ -699,4 +700,33 @@ Player.prototype.TributeResource = function(player, amounts)
|
|||
cmpGUIInterface.PushNotification(notification);
|
||||
};
|
||||
|
||||
Player.prototype.AddDisabledTemplate = function(template)
|
||||
{
|
||||
this.disabledTemplates[template] = true;
|
||||
Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {});
|
||||
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]});
|
||||
};
|
||||
|
||||
Player.prototype.RemoveDisabledTemplate = function(template)
|
||||
{
|
||||
this.disabledTemplates[template] = false;
|
||||
Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {});
|
||||
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]});
|
||||
};
|
||||
|
||||
Player.prototype.SetDisabledTemplates = function(templates)
|
||||
{
|
||||
this.disabledTemplates = templates;
|
||||
Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {});
|
||||
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]});
|
||||
};
|
||||
|
||||
Player.prototype.GetDisabledTemplates = function(templates)
|
||||
{
|
||||
return this.disabledTemplates;
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_Player, "Player", Player);
|
||||
|
|
|
|||
|
|
@ -103,7 +103,15 @@ ProductionQueue.prototype.CalculateEntitiesList = function()
|
|||
string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv());
|
||||
|
||||
var entitiesList = string.split(/\s+/);
|
||||
|
||||
|
||||
// Remove disabled entities
|
||||
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player)
|
||||
var disabledEntities = cmpPlayer.GetDisabledTemplates();
|
||||
|
||||
for (var i = entitiesList.length - 1; i >= 0; --i)
|
||||
if (disabledEntities[entitiesList[i]])
|
||||
entitiesList.splice(i, 1);
|
||||
|
||||
// check if some templates need to show their advanced or elite version
|
||||
var upgradeTemplate = function(templateName)
|
||||
{
|
||||
|
|
@ -120,7 +128,7 @@ ProductionQueue.prototype.CalculateEntitiesList = function()
|
|||
};
|
||||
|
||||
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
|
||||
var playerID = QueryOwnerInterface(this.entity, IID_Player).GetPlayerID();
|
||||
var playerID = cmpPlayer.GetPlayerID();
|
||||
for each (var templateName in entitiesList)
|
||||
this.entitiesList.push(upgradeTemplate(templateName));
|
||||
for each (var item in this.queue)
|
||||
|
|
@ -785,4 +793,11 @@ ProductionQueue.prototype.OnValueModification = function(msg)
|
|||
this.CalculateEntitiesList();
|
||||
};
|
||||
|
||||
ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg)
|
||||
{
|
||||
// if the disabled templates of the player is changed,
|
||||
// update the entities list so that this is reflected there
|
||||
this.CalculateEntitiesList();
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue);
|
||||
|
|
|
|||
Loading…
Reference in a new issue