Ticket #118: variations.2_rebased.diff

File variations.2_rebased.diff, 5.3 KB (added by elexis, 8 years ago)

Rebased.

  • source/graphics/MapReader.cpp

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    1818#include "precompiled.h"
    1919
     20#include <boost/algorithm/string/predicate.hpp>
     21#include <boost/algorithm/string/split.hpp>
     22#include <boost/algorithm/string/classification.hpp>
     23
    2024#include "MapReader.h"
    2125
    2226#include "graphics/Camera.h"
    2327#include "graphics/CinemaManager.h"
    2428#include "graphics/Entity.h"
     
    2630#include "graphics/MapGenerator.h"
    2731#include "graphics/Patch.h"
    2832#include "graphics/Terrain.h"
    2933#include "graphics/TerrainTextureEntry.h"
    3034#include "graphics/TerrainTextureManager.h"
     35#include "graphics/Unit.h"
    3136#include "lib/timer.h"
    3237#include "lib/external_libraries/libsdl.h"
    3338#include "maths/MathUtil.h"
    3439#include "ps/CLogger.h"
    3540#include "ps/Loader.h"
     
    4752#include "simulation2/components/ICmpPosition.h"
    4853#include "simulation2/components/ICmpTerrain.h"
    4954#include "simulation2/components/ICmpVisual.h"
    5055#include "simulation2/components/ICmpWaterManager.h"
    5156
    52 #include <boost/algorithm/string/predicate.hpp>
    53 
    54 
    5557CMapReader::CMapReader()
    5658    : xml_reader(0), m_PatchesPerSide(0), m_MapGen(0)
    5759{
    5860    cur_terrain_tex = 0;    // important - resets generator state
    5961
    private:  
    436438    int at_x, at_y, at_z;
    437439    int at_group, at_group2;
    438440    int at_angle;
    439441    int at_uid;
    440442    int at_seed;
     443    int at_variation;
    441444
    442445    XMBElementList nodes; // children of root
    443446
    444447    // loop counters
    445448    size_t node_idx;
    void CXMLReader::Init(const VfsPath& xml  
    487490    AT(x); AT(y); AT(z);
    488491    AT(group); AT(group2);
    489492    AT(angle);
    490493    AT(uid);
    491494    AT(seed);
     495    AT(variation);
    492496#undef AT
    493497#undef EL
    494498
    495499    XMBElement root = xmb_file.GetRoot();
    496500    ENSURE(xmb_file.GetElementString(root.GetNodeName()) == "Scenario");
    int CXMLReader::ReadEntities(XMBElement  
    978982        CStrW TemplateName;
    979983        int PlayerID = 0;
    980984        CFixedVector3D Position;
    981985        CFixedVector3D Orientation;
    982986        long Seed = -1;
     987        std::set<CStr> actorSelections;
    983988
    984989        // Obstruction control groups.
    985990        entity_id_t ControlGroup = INVALID_ENTITY;
    986991        entity_id_t ControlGroup2 = INVALID_ENTITY;
    987992
    int CXMLReader::ReadEntities(XMBElement  
    10271032            }
    10281033            // <actor>
    10291034            else if (element_name == el_actor)
    10301035            {
    10311036                XMBAttributeList attrs = setting.GetAttributes();
    1032                 CStr seedStr = attrs.GetNamedItem(at_seed);
    1033                 if (!seedStr.empty())
     1037                CStr variationStr = attrs.GetNamedItem(at_variation);
     1038
     1039                if (!variationStr.empty())
    10341040                {
    1035                     Seed = seedStr.ToLong();
    1036                     ENSURE(Seed >= 0);
     1041                    boost::algorithm::split(actorSelections, variationStr, boost::is_any_of("|"));
     1042                }
     1043                else
     1044                {
     1045                    CStr seedStr = attrs.GetNamedItem(at_seed);
     1046                    if (!seedStr.empty())
     1047                    {
     1048                        Seed = seedStr.ToLong();
     1049                        ENSURE(Seed >= 0);
     1050                    }
    10371051                }
    10381052            }
    10391053            else
    10401054                debug_warn(L"Invalid map XML data");
    10411055        }
    int CXMLReader::ReadEntities(XMBElement  
    10721086            }
    10731087
    10741088            CmpPtr<ICmpVisual> cmpVisual(sim, ent);
    10751089            if (cmpVisual)
    10761090            {
    1077                 if (Seed != -1)
     1091                if (!actorSelections.empty())
     1092                {
     1093                    CUnit* unit = cmpVisual->GetUnit();
     1094                    if (unit)
     1095                        unit->SetActorSelections(actorSelections);
     1096                }
     1097                else if (Seed != -1)
    10781098                    cmpVisual->SetActorSeed((u32)Seed);
    1079                 // TODO: variation/selection strings
    10801099            }
    10811100
    10821101            if (PlayerID == m_MapReader.m_PlayerID && (boost::algorithm::ends_with(TemplateName, L"civil_centre") || m_MapReader.m_StartingCameraTarget == INVALID_ENTITY))
    10831102            {
    10841103                // Focus on civil centre or first entity owned by player
  • source/graphics/MapWriter.cpp

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    1818#include "precompiled.h"
    1919
     20#include <boost/algorithm/string/join.hpp>
     21
    2022#include "Camera.h"
    2123#include "CinemaManager.h"
    2224#include "GameView.h"
    2325#include "LightEnv.h"
    2426#include "MapReader.h"
    2527#include "MapWriter.h"
    2628#include "Patch.h"
    2729#include "Terrain.h"
    2830#include "TerrainTextureEntry.h"
    2931#include "TerrainTextureManager.h"
     32#include "Unit.h"
    3033
    3134#include "maths/MathUtil.h"
    3235#include "maths/NUSpline.h"
    3336#include "ps/CLogger.h"
    3437#include "ps/Loader.h"
    void CMapWriter::WriteXML(const VfsPath&  
    385388                            XML_Attribute("group2", group2);
    386389                    }
    387390                }
    388391
    389392                CmpPtr<ICmpVisual> cmpVisual(sim, ent);
     393                CUnit* unit = cmpVisual->GetUnit();
    390394                if (cmpVisual)
    391395                {
    392396                    u32 seed = cmpVisual->GetActorSeed();
    393                     if (seed != (u32)ent)
     397                    bool variationsAdded = false;
     398                    XML_Element("Actor");
     399                    if (unit)
    394400                    {
    395                         XML_Element("Actor");
    396                         XML_Attribute("seed", seed);
     401                        const std::set<CStr>& actorSelections = unit->GetActorSelections();
     402
     403                        if (!actorSelections.empty())
     404                        {
     405                            CStr actorSelectionsStr = boost::algorithm::join(unit->GetActorSelections(), "|");
     406                            XML_Attribute("variation", actorSelectionsStr.c_str());
     407                            variationsAdded = true;
     408                        }
    397409                    }
    398                     // TODO: variation/selection strings
     410                    if (!variationsAdded && seed != (u32)ent)
     411                        XML_Attribute("seed", seed);
    399412                }
    400413            }
    401414        }
    402415
    403416        const std::map<CStrW, CCinemaPath>& paths = pCinema->GetAllPaths();