Ticket #118: variations.2_rebased.diff
File variations.2_rebased.diff, 5.3 KB (added by , 8 years ago) |
---|
-
source/graphics/MapReader.cpp
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 18 #include "precompiled.h" 19 19 20 #include <boost/algorithm/string/predicate.hpp> 21 #include <boost/algorithm/string/split.hpp> 22 #include <boost/algorithm/string/classification.hpp> 23 20 24 #include "MapReader.h" 21 25 22 26 #include "graphics/Camera.h" 23 27 #include "graphics/CinemaManager.h" 24 28 #include "graphics/Entity.h" … … 26 30 #include "graphics/MapGenerator.h" 27 31 #include "graphics/Patch.h" 28 32 #include "graphics/Terrain.h" 29 33 #include "graphics/TerrainTextureEntry.h" 30 34 #include "graphics/TerrainTextureManager.h" 35 #include "graphics/Unit.h" 31 36 #include "lib/timer.h" 32 37 #include "lib/external_libraries/libsdl.h" 33 38 #include "maths/MathUtil.h" 34 39 #include "ps/CLogger.h" 35 40 #include "ps/Loader.h" … … 47 52 #include "simulation2/components/ICmpPosition.h" 48 53 #include "simulation2/components/ICmpTerrain.h" 49 54 #include "simulation2/components/ICmpVisual.h" 50 55 #include "simulation2/components/ICmpWaterManager.h" 51 56 52 #include <boost/algorithm/string/predicate.hpp>53 54 55 57 CMapReader::CMapReader() 56 58 : xml_reader(0), m_PatchesPerSide(0), m_MapGen(0) 57 59 { 58 60 cur_terrain_tex = 0; // important - resets generator state 59 61 … … private: 436 438 int at_x, at_y, at_z; 437 439 int at_group, at_group2; 438 440 int at_angle; 439 441 int at_uid; 440 442 int at_seed; 443 int at_variation; 441 444 442 445 XMBElementList nodes; // children of root 443 446 444 447 // loop counters 445 448 size_t node_idx; … … void CXMLReader::Init(const VfsPath& xml 487 490 AT(x); AT(y); AT(z); 488 491 AT(group); AT(group2); 489 492 AT(angle); 490 493 AT(uid); 491 494 AT(seed); 495 AT(variation); 492 496 #undef AT 493 497 #undef EL 494 498 495 499 XMBElement root = xmb_file.GetRoot(); 496 500 ENSURE(xmb_file.GetElementString(root.GetNodeName()) == "Scenario"); … … int CXMLReader::ReadEntities(XMBElement 978 982 CStrW TemplateName; 979 983 int PlayerID = 0; 980 984 CFixedVector3D Position; 981 985 CFixedVector3D Orientation; 982 986 long Seed = -1; 987 std::set<CStr> actorSelections; 983 988 984 989 // Obstruction control groups. 985 990 entity_id_t ControlGroup = INVALID_ENTITY; 986 991 entity_id_t ControlGroup2 = INVALID_ENTITY; 987 992 … … int CXMLReader::ReadEntities(XMBElement 1027 1032 } 1028 1033 // <actor> 1029 1034 else if (element_name == el_actor) 1030 1035 { 1031 1036 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()) 1034 1040 { 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 } 1037 1051 } 1038 1052 } 1039 1053 else 1040 1054 debug_warn(L"Invalid map XML data"); 1041 1055 } … … int CXMLReader::ReadEntities(XMBElement 1072 1086 } 1073 1087 1074 1088 CmpPtr<ICmpVisual> cmpVisual(sim, ent); 1075 1089 if (cmpVisual) 1076 1090 { 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) 1078 1098 cmpVisual->SetActorSeed((u32)Seed); 1079 // TODO: variation/selection strings1080 1099 } 1081 1100 1082 1101 if (PlayerID == m_MapReader.m_PlayerID && (boost::algorithm::ends_with(TemplateName, L"civil_centre") || m_MapReader.m_StartingCameraTarget == INVALID_ENTITY)) 1083 1102 { 1084 1103 // Focus on civil centre or first entity owned by player -
source/graphics/MapWriter.cpp
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 18 #include "precompiled.h" 19 19 20 #include <boost/algorithm/string/join.hpp> 21 20 22 #include "Camera.h" 21 23 #include "CinemaManager.h" 22 24 #include "GameView.h" 23 25 #include "LightEnv.h" 24 26 #include "MapReader.h" 25 27 #include "MapWriter.h" 26 28 #include "Patch.h" 27 29 #include "Terrain.h" 28 30 #include "TerrainTextureEntry.h" 29 31 #include "TerrainTextureManager.h" 32 #include "Unit.h" 30 33 31 34 #include "maths/MathUtil.h" 32 35 #include "maths/NUSpline.h" 33 36 #include "ps/CLogger.h" 34 37 #include "ps/Loader.h" … … void CMapWriter::WriteXML(const VfsPath& 385 388 XML_Attribute("group2", group2); 386 389 } 387 390 } 388 391 389 392 CmpPtr<ICmpVisual> cmpVisual(sim, ent); 393 CUnit* unit = cmpVisual->GetUnit(); 390 394 if (cmpVisual) 391 395 { 392 396 u32 seed = cmpVisual->GetActorSeed(); 393 if (seed != (u32)ent) 397 bool variationsAdded = false; 398 XML_Element("Actor"); 399 if (unit) 394 400 { 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 } 397 409 } 398 // TODO: variation/selection strings 410 if (!variationsAdded && seed != (u32)ent) 411 XML_Attribute("seed", seed); 399 412 } 400 413 } 401 414 } 402 415 403 416 const std::map<CStrW, CCinemaPath>& paths = pCinema->GetAllPaths();