Ticket #4256: 4256_atlas_settings_v1.patch

File 4256_atlas_settings_v1.patch, 11.8 KB (added by Sandarac, 7 years ago)

Add wonder victory timeout, last man standing option, fix a TODO, rename ID_MapTeams to ID_MapLockTeams.

  • binaries/data/mods/_test.sim/simulation/data/settings/map_sizes.json

     
     1{
     2    "TranslatedKeys": ["Name"],
     3    "Data":
     4    [
     5        {
     6            "Name": "Tiny",
     7            "Tiles": 128
     8        },
     9        {
     10            "Name": "Small",
     11            "Tiles": 192
     12        },
     13        {
     14            "Name": "Medium",
     15            "Tiles": 256,
     16            "Default": true
     17        },
     18        {
     19            "Name": "Normal",
     20            "Tiles": 320
     21        },
     22        {
     23            "Name": "Large",
     24            "Tiles": 384
     25        },
     26        {
     27            "Name": "Very Large",
     28            "Tiles": 448
     29        },
     30        {
     31            "Name": "Giant",
     32            "Tiles": 512
     33        }
     34    ]
     35}
  • binaries/data/mods/_test.sim/simulation/data/settings/wonder_times.json

    Property changes on: binaries/data/mods/_test.sim/simulation/data/settings/map_sizes.json
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1{
     2    "Times": [0, 1, 3, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 75, 90, 105, 120],
     3    "Default": 20
     4}
  • source/simulation2/Simulation2.cpp

    Property changes on: binaries/data/mods/_test.sim/simulation/data/settings/wonder_times.json
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    1 /* Copyright (C) 2016 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    946946    return ReadJSON(L"simulation/data/settings/map_sizes.json");
    947947}
    948948
     949std::string CSimulation2::GetWonderDurations()
     950{
     951    return ReadJSON(L"simulation/data/settings/wonder_times.json");
     952}
     953
    949954std::string CSimulation2::GetAIData()
    950955{
    951956    ScriptInterface& scriptInterface = GetScriptInterface();
  • source/simulation2/Simulation2.h

     
    1 /* Copyright (C) 2016 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    263263    std::string GetMapSizes();
    264264
    265265    /**
     266    * Get wonder duration data
     267    *
     268    * @return string containing JSON format data
     269    */
     270    std::string GetWonderDurations();
     271
     272    /**
    266273     * Get AI data
    267274     *
    268275     * @return string containing JSON format data
  • source/simulation2/tests/test_Simulation2.h

     
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    164164
    165165        TS_ASSERT_OK(sim.ReloadChangedFile(L"simulation/components/hotload/hotload.js"));
    166166    }
     167
     168    void test_read_JSON()
     169    {
     170        CSimulation2 sim(NULL, g_ScriptRuntime, &m_Terrain);
     171
     172        std::string wonderDurations = sim.GetWonderDurations();
     173
     174        TS_ASSERT(!wonderDurations.empty());
     175        TS_ASSERT(wonderDurations.c_str()[0] == '{');
     176        TS_ASSERT(wonderDurations.find("Times") != std::string::npos);
     177        TS_ASSERT(wonderDurations.find("55") != std::string::npos);
     178        TS_ASSERT(wonderDurations.find("Default") != std::string::npos);
     179
     180        std::string mapSizes = sim.GetMapSizes();
     181
     182        TS_ASSERT(!mapSizes.empty());
     183        TS_ASSERT(mapSizes.c_str()[0] == '{');
     184        TS_ASSERT(mapSizes.find("Data") != std::string::npos);
     185        TS_ASSERT(mapSizes.find("384") != std::string::npos);
     186        TS_ASSERT(mapSizes.find("Default") != std::string::npos);
     187    }
    167188};
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp

     
    1 /* Copyright (C) 2016 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2121
    2222#include "AtlasObject/AtlasObject.h"
    2323#include "GameInterface/Messages.h"
     24#include "General/Datafile.h"
    2425#include "ScenarioEditor/ScenarioEditor.h"
    2526#include "ScenarioEditor/Tools/Common/Tools.h"
    2627
     
    3334    ID_MapDescription,
    3435    ID_MapReveal,
    3536    ID_MapType,
     37    ID_WonderVictoryTimes,
    3638    ID_MapPreview,
    37     ID_MapTeams,
     39    ID_MapLockTeams,
     40    ID_MapLastManStanding,
    3841    ID_MapKW_Demo,
    3942    ID_MapKW_Naval,
    4043    ID_RandomScript,
     
    141144
    142145    sizer->AddSpacer(5);
    143146
    144     // TODO: replace by filenames in binaries/data/mods/public/simulation/data/settings/victory_conditions/
    145     wxArrayString gameTypes;
    146     gameTypes.Add(_T("conquest"));
    147     gameTypes.Add(_T("conquest_structures"));
    148     gameTypes.Add(_T("conquest_units"));
    149     gameTypes.Add(_T("wonder"));
    150     gameTypes.Add(_T("endless"));
    151     gameTypes.Add(_T("regicide"));
     147    wxArrayString gameTypes = Datafile::EnumerateDataFiles(_T("mods/public/simulation/data/settings/victory_conditions/"), _T("*.json"));
     148    // discard path and extension of game types
     149    for (size_t i = 0; i < gameTypes.Count(); ++i)
     150        gameTypes[i] = wxFileName(gameTypes[i]).GetName();
    152151
     152    wxArrayString wonderDurations;
     153    AtlasMessage::qGetWonderDurations qrySizes;
     154    qrySizes.Post();
     155    AtObj sizes = AtlasObject::LoadFromJSON(*qrySizes.data);
     156
    153157    wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5);
    154158    gridSizer->AddGrowableCol(1);
    155159    // TODO: have preview selector tool?
     
    162166    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Game type")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    163167    gridSizer->Add(Tooltipped(new wxChoice(this, ID_MapType, wxDefaultPosition, wxDefaultSize, gameTypes),
    164168        _("Select the game type (or victory condition)")), wxSizerFlags().Expand());
     169    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Wonder Victory")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
     170    gridSizer->Add(Tooltipped(new wxChoice(this, ID_WonderVictoryTimes, wxDefaultPosition, wxDefaultSize, wonderDurations),
     171        _("Number of minutes that the player has to keep the wonder in order to win.")), wxSizerFlags().Expand());
     172
     173    // get wonder victory times
     174    wxChoice* durationChoice = wxDynamicCast(FindWindow(ID_WonderVictoryTimes), wxChoice);
     175    for (AtIter s = sizes["Times"]["item"]; s.defined(); ++s)
     176    {
     177        long time = 0;
     178        wxString(s).ToLong(&time);
     179        durationChoice->Append(wxString(s), (void*)(intptr_t)time);
     180    }
     181    durationChoice->SetSelection(0);
     182
    165183    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Lock teams")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    166     gridSizer->Add(Tooltipped(new wxCheckBox(this, ID_MapTeams, wxEmptyString),
     184    gridSizer->Add(Tooltipped(new wxCheckBox(this, ID_MapLockTeams, wxEmptyString),
    167185        _("If checked, teams will be locked")));
     186    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Last Man Standing")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
     187    gridSizer->Add(Tooltipped(new wxCheckBox(this, ID_MapLastManStanding, wxEmptyString),
     188        _("If checked, the last remaining player will win (not the last remaining set of allies)")));
    168189    sizer->Add(gridSizer, wxSizerFlags().Expand());
    169190
    170191    sizer->AddSpacer(5);
     
    209230    else
    210231        wxDynamicCast(FindWindow(ID_MapType), wxChoice)->SetSelection(0);
    211232
     233    if (wxString(m_MapSettings["GameType"]) == L"wonder")
     234        wxDynamicCast(FindWindow(ID_WonderVictoryTimes), wxChoice)->SetStringSelection(wxString(m_MapSettings["WonderDuration"]));
     235    else
     236        wxDynamicCast(FindWindow(ID_WonderVictoryTimes), wxChoice)->SetSelection(0);
     237
     238    wxDynamicCast(FindWindow(ID_WonderVictoryTimes), wxChoice)->Enable(wxDynamicCast(FindWindow(ID_MapType), wxChoice)->GetStringSelection() == L"wonder");
     239
    212240    // lock teams
    213     wxDynamicCast(FindWindow(ID_MapTeams), wxCheckBox)->SetValue(wxString(m_MapSettings["LockTeams"]) == L"true");
     241    wxDynamicCast(FindWindow(ID_MapLockTeams), wxCheckBox)->SetValue(wxString(m_MapSettings["LockTeams"]) == L"true");
    214242
     243    // Last Man Standing
     244    wxDynamicCast(FindWindow(ID_MapLastManStanding), wxCheckBox)->SetValue(wxString(m_MapSettings["LastManStanding"]) == L"true" &&
     245        wxString(m_MapSettings["LockTeams"]) != L"true");
     246    wxDynamicCast(FindWindow(ID_MapLastManStanding), wxCheckBox)->Enable(!wxDynamicCast(FindWindow(ID_MapLockTeams), wxCheckBox)->GetValue());
     247
    215248    // keywords
    216249    {
    217250        m_MapSettingsKeywords.clear();
     
    248281    // game type / victory conditions
    249282    m_MapSettings.set("GameType", wxDynamicCast(FindWindow(ID_MapType), wxChoice)->GetStringSelection());
    250283
     284    if (wxDynamicCast(FindWindow(ID_MapType), wxChoice)->GetStringSelection() == L"wonder")
     285        m_MapSettings.setInt("WonderDuration", wxAtoi(wxDynamicCast(FindWindow(ID_WonderVictoryTimes), wxChoice)->GetStringSelection()));
     286    else
     287        wxDynamicCast(FindWindow(ID_WonderVictoryTimes), wxChoice)->SetSelection(0);
     288
     289    wxDynamicCast(FindWindow(ID_WonderVictoryTimes), wxChoice)->Enable(wxDynamicCast(FindWindow(ID_MapType), wxChoice)->GetStringSelection() == L"wonder");
     290
    251291    // keywords
    252292    {
    253293        if (wxDynamicCast(FindWindow(ID_MapKW_Demo), wxCheckBox)->GetValue())
     
    268308    }
    269309
    270310    // teams locked
    271     m_MapSettings.setBool("LockTeams", wxDynamicCast(FindWindow(ID_MapTeams), wxCheckBox)->GetValue());
     311    m_MapSettings.setBool("LockTeams", wxDynamicCast(FindWindow(ID_MapLockTeams), wxCheckBox)->GetValue());
    272312
     313    // Last Man Standing (can't be enabled if teams are locked)
     314    if (wxDynamicCast(FindWindow(ID_MapLockTeams), wxCheckBox)->GetValue())
     315        wxDynamicCast(FindWindow(ID_MapLastManStanding), wxCheckBox)->SetValue(false);
     316
     317    wxDynamicCast(FindWindow(ID_MapLastManStanding), wxCheckBox)->Enable(!wxDynamicCast(FindWindow(ID_MapLockTeams), wxCheckBox)->GetValue());
     318    m_MapSettings.setBool("LastManStanding", wxDynamicCast(FindWindow(ID_MapLastManStanding), wxCheckBox)->GetValue());
     319
    273320    return m_MapSettings;
    274321}
    275322
  • source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp

     
    1 /* Copyright (C) 2016 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    312312    msg->data = g_Game->GetSimulation2()->GetRMSData();
    313313}
    314314
     315QUERYHANDLER(GetWonderDurations)
     316{
     317    msg->data = g_Game->GetSimulation2()->GetWonderDurations();
     318}
     319
    315320BEGIN_COMMAND(ResizeMap)
    316321{
    317322    int m_OldTiles, m_NewTiles;
  • source/tools/atlas/GameInterface/Messages.h

     
    1 /* Copyright (C) 2016 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    198198        ((std::vector<std::string>, data))
    199199        );
    200200
     201QUERY(GetWonderDurations,
     202        ,
     203        ((std::string, data))
     204        );
     205
    201206COMMAND(ResizeMap, NOMERGE,
    202207        ((int, tiles))
    203208        );