Ticket #1649: wonderVictory.5.diff

File wonderVictory.5.diff, 11.4 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

     
    481481    updateResearchDisplay();
    482482    updateBuildingPlacementPreview();
    483483    updateTimeElapsedCounter();
     484    updateTimeNotifications(); 
    484485
    485486    // Update music state on basis of battle state.
    486487    var battleState = Engine.GuiInterfaceCall("GetBattleState", Engine.GetPlayerID());
  • binaries/data/mods/public/gui/session/session.xml

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

     
    2424EndGameManager.prototype.SetGameType = function(newGameType)
    2525{
    2626    this.gameType = newGameType;
     27    Engine.BroadcastMessage(MT_GameTypeChanged, {});
    2728};
    2829
     30EndGameManager.prototype.CheckGameType = function(type)
     31{
     32    return this.gameType == type;
     33};
     34
     35EndGameManager.prototype.RegisterWonder = function(entity)
     36{
     37    if (!this.CheckGameType("wonder"))
     38        return;
     39
     40    var cmpWon = QueryOwnerInterface(entity, IID_Player);
     41    cmpWon.SetState("won");
     42   
     43    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     44    var numPlayers = cmpPlayerManager.GetNumPlayers();
     45    for (var i = 1; i < numPlayers; i++)
     46    {
     47        var playerEntityId = cmpPlayerManager.GetPlayerByID(i);
     48        var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
     49        if (cmpPlayer.GetState() != "active")
     50            continue;
     51        if (this.alliedVictory && cmpPlayer.IsMutualAlly(cmpWon.GetPlayerID()))
     52            cmpPlayer.SetState("won")
     53        else
     54            Engine.PostMessage(playerEntityId, MT_PlayerDefeated, { "playerId": i } );
     55    }
     56
     57    // Reveal the map to all players
     58    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     59    cmpRangeManager.SetLosRevealAll(-1, true);
     60};
     61
    2962EndGameManager.prototype.SetAlliedVictory = function(flag)
    3063{
    3164    this.alliedVictory = flag;
  • 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/*
     
    728730    return cmpPlayer.GetNeededResources(amounts);
    729731};
    730732
     733GuiInterface.prototype.AddTimeNotification = function(notification)
     734{
     735    var time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime();
     736    notification.endTime = notification.time + time;
     737    notification.id = ++this.timeNotificationID;
     738    this.timeNotifications.push(notification);
     739    this.timeNotifications.sort(function (n1, n2){return n2.endTime - n1.endTime});
     740    return this.timeNotificationID;
     741};
    731742
     743GuiInterface.prototype.DeleteTimeNotification = function(notificationID)
     744{
     745    for (var i in this.timeNotifications)
     746    {
     747        if (this.timeNotifications[i].id == notificationID)
     748        {
     749            this.timeNotifications.splice(i);
     750            return;
     751        }
     752    }
     753};
     754
     755GuiInterface.prototype.GetTimeNotificationText = function(playerID)
     756{   
     757    var formatTime = function(time)
     758        {
     759            // add 1000 ms to get ceiled instead of floored millisecons
     760            // displaying 00:00 for a full second isn't nice
     761            time += 1000;
     762            var hours   = Math.floor(time / 1000 / 60 / 60);
     763            var minutes = Math.floor(time / 1000 / 60) % 60;
     764            var seconds = Math.floor(time / 1000) % 60;
     765            return (hours ? hours + ':' : "") + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds);
     766        };
     767    var time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime();
     768    var text = "";
     769    for each (var n in this.timeNotifications)
     770    {
     771        if (time >= n.endTime)
     772        {
     773            // delete the notification and start over
     774            this.DeleteTimeNotification(n.id);
     775            return this.GetTimeNotificationText(playerID);
     776        }
     777        if (n.players.indexOf(playerID) >= 0)
     778            text += n.message.replace("%T",formatTime(n.endTime - time))+"\n";
     779    }
     780    return text;
     781};
     782
    732783GuiInterface.prototype.PushNotification = function(notification)
    733784{
    734785    this.notifications.push(notification);
     
    18371888    "GetIncomingAttacks": 1,
    18381889    "GetNeededResources": 1,
    18391890    "GetNextNotification": 1,
     1891    "GetTimeNotificationText": 1,
    18401892
    18411893    "GetAvailableFormations": 1,
    18421894    "GetFormationRequirements": 1,
  • 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    this.ResetTimer(msg.to);
     15};
     16
     17Wonder.prototype.OnGameTypeChanged = function()
     18{
     19    var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
     20    if (!cmpPlayer)
     21        return;
     22    this.ResetTimer(cmpPlayer.GetPlayerID());
     23};
     24
     25Wonder.prototype.ResetTimer = function(ownerID)
     26{
     27    var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     28    var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     29    // remove existing messages if any
     30    if (this.timer)
     31    {
     32        cmpTimer.CancelTimer(this.timer);
     33        cmpGuiInterface.DeleteTimeNotification(this.ownMessage);
     34        cmpGuiInterface.DeleteTimeNotification(this.otherMessage);
     35    }
     36    if (ownerID <= 0)
     37        return;
     38
     39    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
     40    if (!cmpEndGameManager.CheckGameType("wonder"))
     41        return;
     42
     43    // create new messages, and start timer to register defeat.
     44    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     45    var numPlayers = cmpPlayerManager.GetNumPlayers();
     46    var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
     47    var players = [];
     48    for (var i = 1; i < numPlayers; i++)
     49        if (i != ownerID)
     50            players.push(i);
     51
     52    this.otherMessage = cmpGuiInterface.AddTimeNotification(
     53        {
     54            "message": cmpPlayer.GetName() + " will have won in %T",
     55            "players": players,
     56            "time": +this.template.TimeTillVictory*1000
     57        });
     58    this.ownMessage = cmpGuiInterface.AddTimeNotification(
     59        {
     60            "message": "You will have won in %T",
     61            "players": [ownerID],
     62            "time": +this.template.TimeTillVictory*1000
     63        });
     64    this.timer = cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_EndGameManager, "RegisterWonder", +this.template.TimeTillVictory*1000, this.entity);
     65};
     66
     67Engine.RegisterComponentType(IID_Wonder, "Wonder", Wonder);
  • binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js

     
    11Engine.RegisterInterface("EndGameManager");
    22Engine.RegisterMessageType("PlayerDefeated");
     3Engine.RegisterMessageType("GameTypeChanged");
  • 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>
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp

     
    145145
    146146    wxArrayString gameTypes;
    147147    gameTypes.Add(_T("conquest"));
     148    gameTypes.Add(_T("wonder"));
    148149    gameTypes.Add(_T("endless"));
    149150
    150151    wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5);