Ticket #1649: wonderVictory.3.diff

File wonderVictory.3.diff, 10.5 KB (added by sanderd17, 10 years ago)
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    44const DEFAULT_OFFLINE_MAP = "Acropolis 01";
    55
    66// TODO: Move these somewhere like simulation\data\game_types.json, Atlas needs them too
    7 const VICTORY_TEXT = ["Conquest", "None"];
    8 const VICTORY_DATA = ["conquest", "endless"];
     7const VICTORY_TEXT = ["Conquest", "Wonder", "None"];
     8const VICTORY_DATA = ["conquest", "wonder", "endless"];
    99const VICTORY_DEFAULTIDX = 0;
    1010const POPULATION_CAP = ["50", "100", "150", "200", "250", "300", "Unlimited"];
    1111const POPULATION_CAP_DATA = [50, 100, 150, 200, 250, 300, 10000];
  • binaries/data/mods/public/gui/session/messages.js

     
    136136    var messages = [];
    137137    for each (var n in notifications)
    138138        messages.push(n.message);
    139     getGUIObjectByName("notificationText").caption = messages.join("\n");
    140 }
    141 
    142 // Returns [username, playercolor] for the given player
    143 function getUsernameAndColor(player)
    144 {
     139    getGUIObjectByName("notificationText").caption = messages.join("\n");
     140}
     141
     142function updateTimeNotifications()
     143{
     144    getGUIObjectByName("timeNotificationText").caption = Engine.GuiInterfaceCall("GetTimeNotificationText");
     145}
     146
     147// Returns [username, playercolor] for the given player
     148function getUsernameAndColor(player)
     149{
    145150    // This case is hit for AIs, whose names don't exist in playerAssignments.
    146151    var color = g_Players[player].color;
    147152    return [
  • binaries/data/mods/public/gui/session/session.js

     
    440440    updateResearchDisplay();
    441441    updateBuildingPlacementPreview();
    442442    updateTimeElapsedCounter();
     443    updateTimeNotifications(); 
    443444
    444445    // Update music state on basis of battle state.
    445446    var battleState = Engine.GuiInterfaceCall("GetBattleState", Engine.GetPlayerID());
  • binaries/data/mods/public/gui/session/session.xml

     
    346346    <object name="notificationPanel" type="image" size="50%-300 60 50%+300 120" ghost="true">
    347347        <object name="notificationText" size="0 0 100% 100%" type="text" style="notificationPanel" ghost="true"/>
    348348    </object>
     349    <object name="timeNotificationPanel" type="image" size="100%-600 60 100%-20 120" ghost="true">
     350        <object name="timeNotificationText" size="0 0 100% 100%" type="text" style="notificationPanel" ghost="true"/>
     351    </object>
    349352
     353
    350354    <!-- ================================  ================================ -->
    351355    <!-- Chat -->
    352356    <!-- ================================  ================================ -->
  • binaries/data/mods/public/simulation/components/EndGameManager.js

     
    3131    this.alliedVictory = flag;
    3232};
    3333
     34EndGameManager.prototype.RegisterWonder = function(entity)
     35{
     36    if (this.gameType != "wonder")
     37        return;
     38
     39    var cmpWon = QueryOwnerInterface(entity, IID_Player);
     40    cmpWon.SetState("won");
     41   
     42    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     43    var numPlayers = cmpPlayerManager.GetNumPlayers();
     44    for (var i = 1; i < numPlayers; i++)
     45    {
     46        var playerEntityId = cmpPlayerManager.GetPlayerByID(i);
     47        var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
     48        if (cmpPlayer.GetState() != "active")
     49            continue;
     50        if (this.alliedVictory && cmpPlayer.IsMutualAlly(cmpWon.GetPlayerID()))
     51            cmpPlayer.SetState("won")
     52        else
     53            Engine.PostMessage(playerEntityId, MT_PlayerDefeated, { "playerId": i } );
     54    }
     55};
     56
    3457EndGameManager.prototype.PlayerLostAllConquestCriticalEntities = function(playerID)
    3558{
    3659    if (this.gameType == "endless")
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    2222    this.placementWallLastAngle = 0;
    2323    this.notifications = [];
    2424    this.renamedEntities = [];
     25    this.timeNotificationID = 1;
     26    this.timeNotifications = [];
    2527};
    2628
    2729/*
     
    691693    return cmpPlayer.GetNeededResources(amounts);
    692694};
    693695
     696GuiInterface.prototype.AddTimeNotification = function(notification)
     697{
     698    var time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime();
     699    notification.endTime = notification.time + time;
     700    notification.id = ++this.timeNotificationID;
     701    this.timeNotifications.push(notification);
     702    this.timeNotifications.sort(function (n1, n2){return n2.endTime - n1.endTime});
     703    return this.timeNotificationID;
     704};
    694705
     706GuiInterface.prototype.DeleteTimeNotification = function(notificationID)
     707{
     708    for (var i in this.timeNotifications)
     709    {
     710        if (this.timeNotifications[i].id == notificationID)
     711        {
     712            this.timeNotifications.splice(i);
     713            return;
     714        }
     715    }
     716};
     717
     718GuiInterface.prototype.GetTimeNotificationText = function(playerID)
     719{   
     720    var formatTime = function(time)
     721        {
     722            // add 1000 ms to get ceiled instead of floored millisecons
     723            // displaying 00:00 for a full second isn't nice
     724            time += 1000;
     725            var hours   = Math.floor(time / 1000 / 60 / 60);
     726            var minutes = Math.floor(time / 1000 / 60) % 60;
     727            var seconds = Math.floor(time / 1000) % 60;
     728            return (hours ? hours + ':' : "") + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds);
     729        };
     730    var time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime();
     731    var text = "";
     732    for each (var n in this.timeNotifications)
     733    {
     734        if (time >= n.endTime)
     735        {
     736            // delete the notification and start over
     737            this.DeleteTimeNotification(n.id);
     738            return this.GetTimeNotificationText(playerID);
     739        }
     740        if (n.players.indexOf(playerID) >= 0)
     741            text += n.message.replace("%T",formatTime(n.endTime - time))+"\n";
     742    }
     743    return text;
     744};
     745
    695746GuiInterface.prototype.PushNotification = function(notification)
    696747{
    697748    this.notifications.push(notification);
     
    17931844    "GetIncomingAttacks": 1,
    17941845    "GetNeededResources": 1,
    17951846    "GetNextNotification": 1,
     1847    "GetTimeNotificationText": 1,
    17961848
    17971849    "GetAvailableFormations": 1,
    17981850    "GetFormationRequirements": 1,
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

     
    203203            var buildTime = ApplyValueModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, cmpPlayer.GetPlayerID(), template);
    204204            var time = timeMult * buildTime;
    205205
     206            var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     207            cmpGuiInterface.AddTimeNotification(
     208                {
     209                    "message" : "Unit will be spawned in %T",
     210                    "time" : time*1000,
     211                    "players" : [cmpPlayer.GetPlayerID()],
     212                });
     213
    206214            for (var r in template.Cost.Resources)
    207215            {
    208216                costs[r] = ApplyValueModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], cmpPlayer.GetPlayerID(), template);
  • binaries/data/mods/public/simulation/components/Wonder.js

     
     1function Wonder() {}
     2
     3Wonder.prototype.Schema =
     4    "<element name='TimeTillVictory'>" +
     5        "<data type='nonNegativeInteger'/>" +
     6    "</element>";
     7
     8Wonder.prototype.Init = function()
     9{
     10};
     11
     12Wonder.prototype.OnOwnershipChanged = function(msg)
     13{
     14    var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     15    var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     16    if (this.timer)
     17    {
     18        cmpTimer.CancelTimer(this.timer);
     19        cmpGuiInterface.DeleteTimeNotification(this.ownMessage);
     20        cmpGuiInterface.DeleteTimeNotification(this.otherMessage);
     21    }
     22    if (msg.to == -1)
     23        return;
     24   
     25    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     26    var numPlayers = cmpPlayerManager.GetNumPlayers();
     27    var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
     28    var players = [];
     29    for (var i = 1; i < numPlayers; i++)
     30    {
     31        if (i != msg.to)
     32            players.push(i);
     33    }
     34    this.otherMessage = cmpGuiInterface.AddTimeNotification(
     35        {
     36            "message": cmpPlayer.GetName() + " will have won in %T",
     37            "players": players,
     38            "time": +this.template.TimeTillVictory*1000
     39        });
     40    this.ownMessage = cmpGuiInterface.AddTimeNotification(
     41        {
     42            "message": "You will have won in %T",
     43            "players": [msg.to],
     44            "time": +this.template.TimeTillVictory*1000
     45        });
     46    this.timer = cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_EndGameManager, "RegisterWonder", +this.template.TimeTillVictory*1000, this.entity);
     47};
     48
     49Engine.RegisterComponentType(IID_Wonder, "Wonder", Wonder);
  • binaries/data/mods/public/simulation/components/interfaces/Wonder.js

     
     1Engine.RegisterInterface("Wonder");
  • binaries/data/mods/public/simulation/templates/template_structure_wonder.xml

     
    7676  <VisualActor>
    7777    <FoundationActor>structures/fndn_6x6.xml</FoundationActor>
    7878  </VisualActor>
     79  <Wonder>
     80    <TimeTillVictory>300</TimeTillVictory>
     81  </Wonder>
    7982</Entity>