75 void MapSaver::save(
const Map& map,
const std::string& filename,
const std::vector<std::string>& importFiles) {
79 TiXmlDeclaration* decl =
new TiXmlDeclaration(
"1.0",
"ascii",
"");
80 doc.LinkEndChild(decl);
83 TiXmlElement* mapElement =
new TiXmlElement(
"map");
84 mapElement->SetAttribute(
"id", map.
getId());
85 mapElement->SetAttribute(
"format",
"1.0");
86 doc.LinkEndChild(mapElement);
88 for (std::vector<std::string>::const_iterator iter = importFiles.begin(); iter != importFiles.end(); ++iter)
90 TiXmlElement* importElement =
new TiXmlElement(
"import");
91 importElement->SetAttribute(
"file", *iter);
94 mapElement->LinkEndChild(importElement);
97 typedef std::list<Layer*> LayerList;
99 for (LayerList::iterator iter = layers.begin(); iter != layers.end(); ++iter)
101 TiXmlElement* layerElement =
new TiXmlElement(
"layer");
102 CellGrid* grid = (*iter)->getCellGrid();
103 layerElement->SetAttribute(
"id", (*iter)->getId());
104 layerElement->SetDoubleAttribute(
"x_offset", grid->
getXShift());
105 layerElement->SetDoubleAttribute(
"y_offset", grid->
getYShift());
106 layerElement->SetDoubleAttribute(
"z_offset", grid->
getZShift());
107 layerElement->SetDoubleAttribute(
"x_scale", grid->
getXScale());
108 layerElement->SetDoubleAttribute(
"y_scale", grid->
getYScale());
109 layerElement->SetDoubleAttribute(
"rotation", grid->
getRotation());
110 layerElement->SetAttribute(
"grid_type", grid->
getType());
111 layerElement->SetAttribute(
"transparency", (*iter)->getLayerTransparency());
113 std::string pathingStrategy;
114 switch ((*iter)->getPathingStrategy())
118 pathingStrategy =
"cell_edges_only";
123 pathingStrategy =
"cell_edges_and_diagonals";
128 pathingStrategy =
"cell_edges_only";
132 layerElement->SetAttribute(
"pathing", pathingStrategy);
134 std::string sortingStrategy;
135 switch ((*iter)->getSortingStrategy()) {
138 sortingStrategy =
"camera";
143 sortingStrategy =
"location";
148 sortingStrategy =
"camera_and_location";
153 sortingStrategy =
"camera";
157 layerElement->SetAttribute(
"sorting", sortingStrategy);
159 if ((*iter)->isWalkable()) {
160 layerElement->SetAttribute(
"layer_type",
"walkable");
161 }
else if ((*iter)->isInteract()) {
162 layerElement->SetAttribute(
"layer_type",
"interact");
163 layerElement->SetAttribute(
"layer_type_id", (*iter)->getWalkableId());
167 mapElement->LinkEndChild(layerElement);
170 TiXmlElement* instancesElement =
new TiXmlElement(
"instances");
171 layerElement->LinkEndChild(instancesElement);
173 std::string currentNamespace =
"";
174 typedef std::vector<Instance*> InstancesContainer;
175 InstancesContainer instances = (*iter)->getInstances();
176 for (InstancesContainer::iterator iter = instances.begin(); iter != instances.end(); ++iter)
178 Object* obj = (*iter)->getObject();
185 TiXmlElement* instanceElement =
new TiXmlElement(
"i");
189 instanceElement->SetAttribute(
"ns", obj->
getNamespace());
195 if (!(*iter)->getId().empty())
197 instanceElement->SetAttribute(
"id", (*iter)->getId());
200 instanceElement->SetAttribute(
"o", obj->
getId());
203 instanceElement->SetDoubleAttribute(
"x", position.
x);
204 instanceElement->SetDoubleAttribute(
"y", position.
y);
205 instanceElement->SetDoubleAttribute(
"z", position.
z);
206 instanceElement->SetAttribute(
"r", (*iter)->getRotation());
208 if ((*iter)->isBlocking())
210 instanceElement->SetAttribute(
"blocking", (*iter)->isBlocking());
214 instanceElement->SetAttribute(
"cellstack", (*iter)->getCellStackPosition());
217 if ((*iter)->isSpecialCost()) {
219 instanceElement->SetAttribute(
"cost_id", (*iter)->getCostId());
220 instanceElement->SetDoubleAttribute(
"cost", (*iter)->getCost());
221 }
else if ((*iter)->getCostId() != obj->
getCostId() ||
223 instanceElement->SetAttribute(
"cost_id", (*iter)->getCostId());
224 instanceElement->SetDoubleAttribute(
"cost", (*iter)->getCost());
229 instanceElement->SetAttribute(
"stackpos", instanceVisual->
getStackPosition());
231 instancesElement->LinkEndChild(instanceElement);
235 TiXmlElement* cellcachesElement =
new TiXmlElement(
"cellcaches");
236 mapElement->LinkEndChild(cellcachesElement);
237 for (LayerList::iterator iter = layers.begin(); iter != layers.end(); ++iter) {
238 CellCache* cache = (*iter)->getCellCache();
243 TiXmlElement* cellcacheElement =
new TiXmlElement(
"cellcache");
244 cellcacheElement->SetAttribute(
"id", (*iter)->getId());
252 const std::vector<std::vector<Cell*> >& cells = cache->
getCells();
253 std::vector<std::vector<Cell*> >::const_iterator it = cells.begin();
254 for (; it != cells.end(); ++it) {
255 std::vector<Cell*>::const_iterator cit = (*it).begin();
256 for (; cit != (*it).end(); ++cit) {
258 std::list<std::string> costIds = cache->
getCosts();
259 bool costsEmpty = costIds.empty();
264 std::vector<std::string> areaIds = cache->
getCellAreas(cell);
265 std::vector<std::string> cellAreaIds;
266 bool areasEmpty = areaIds.empty();
268 const std::set<Instance*>& cellInstances = cell->
getInstances();
269 if (!cellInstances.empty()) {
270 std::vector<std::string>::iterator area_it = areaIds.begin();
271 for (; area_it != areaIds.end(); ++area_it) {
272 bool objectArea =
false;
273 std::set<Instance*>::const_iterator instance_it = cellInstances.begin();
274 for (; instance_it != cellInstances.end(); ++instance_it) {
275 if ((*instance_it)->getObject()->getArea() == *area_it) {
281 cellAreaIds.push_back(*area_it);
285 cellAreaIds = areaIds;
287 areasEmpty = cellAreaIds.empty();
293 bool isNarrow =
false;
295 std::set<Cell*>::const_iterator narrow_it = narrowCells.find(cell);
296 if (narrow_it != narrowCells.end()) {
300 if (costsEmpty && defaultCost && defaultSpeed && areasEmpty &&
301 cellBlocker && !transition && !isNarrow) {
306 TiXmlElement* cellElement =
new TiXmlElement(
"cell");
307 cellElement->SetAttribute(
"x", cellCoord.
x);
308 cellElement->SetAttribute(
"y", cellCoord.
y);
318 cellElement->SetAttribute(
"blocker_type",
"no_blocker");
320 cellElement->SetAttribute(
"blocker_type",
"blocker");
324 cellElement->SetAttribute(
"narrow",
true);
328 std::list<std::string>::iterator cost_it = costIds.begin();
329 for (; cost_it != costIds.end(); ++cost_it) {
331 TiXmlElement* costElement =
new TiXmlElement(
"cost");
332 costElement->SetAttribute(
"id", *cost_it);
333 costElement->SetDoubleAttribute(
"value", cache->
getCost(*cost_it));
334 cellElement->LinkEndChild(costElement);
340 std::vector<std::string>::iterator area_it = cellAreaIds.begin();
341 for (; area_it != cellAreaIds.end(); ++area_it) {
342 TiXmlElement* areaElement =
new TiXmlElement(
"area");
343 areaElement->SetAttribute(
"id", *area_it);
344 areaElement->LinkEndChild(areaElement);
349 TiXmlElement* transitionElement =
new TiXmlElement(
"transition");
350 transitionElement->SetAttribute(
"id", transition->
m_layer->
getId());
351 transitionElement->SetAttribute(
"x", transition->
m_mc.
x);
352 transitionElement->SetAttribute(
"y", transition->
m_mc.
y);
353 if (transition->
m_mc.
z != 0) {
354 transitionElement->SetAttribute(
"z", transition->
m_mc.
z);
357 transitionElement->SetAttribute(
"immediate",
true);
359 transitionElement->SetAttribute(
"immediate",
false);
361 cellElement->LinkEndChild(transitionElement);
363 cellcacheElement->LinkEndChild(cellElement);
366 cellcachesElement->LinkEndChild(cellcacheElement);
370 std::vector<Trigger*> triggers = triggerController->
getAllTriggers();
371 if (!triggers.empty()) {
373 TiXmlElement* triggersElement =
new TiXmlElement(
"triggers");
374 mapElement->LinkEndChild(triggersElement);
375 for (std::vector<Trigger*>::iterator iter = triggers.begin(); iter != triggers.end(); ++iter) {
377 TiXmlElement* triggerElement =
new TiXmlElement(
"trigger");
378 triggerElement->SetAttribute(
"name", (*iter)->getName());
379 triggerElement->SetAttribute(
"triggered", (*iter)->isTriggered());
380 triggerElement->SetAttribute(
"all_instances", (*iter)->isEnabledForAllInstances());
381 if ((*iter)->getAttached()) {
382 triggerElement->SetAttribute(
"attached_instance", (*iter)->getAttached()->getId());
383 triggerElement->SetAttribute(
"attached_layer", (*iter)->getAttached()->getLocationRef().getLayer()->getId());
385 const std::vector<Cell*>& cells = (*iter)->getAssignedCells();
386 if (!cells.empty()) {
387 for (std::vector<Cell*>::const_iterator citer = cells.begin(); citer != cells.end(); ++citer) {
388 TiXmlElement* cellElement =
new TiXmlElement(
"assign");
389 cellElement->SetAttribute(
"layer_id", (*citer)->getLayer()->getId());
390 cellElement->SetAttribute(
"x", (*citer)->getLayerCoordinates().x);
391 cellElement->SetAttribute(
"y", (*citer)->getLayerCoordinates().y);
392 triggerElement->LinkEndChild(cellElement);
395 const std::vector<Instance*>& instances = (*iter)->getEnabledInstances();
396 if (!instances.empty()) {
397 for (std::vector<Instance*>::const_iterator citer = instances.begin(); citer != instances.end(); ++citer) {
398 TiXmlElement* instanceElement =
new TiXmlElement(
"enabled");
399 instanceElement->SetAttribute(
"layer_id", (*citer)->getLocationRef().getLayer()->getId());
400 instanceElement->SetAttribute(
"instance_id", (*citer)->getId());
401 triggerElement->LinkEndChild(instanceElement);
404 const std::vector<TriggerCondition>& conditions = (*iter)->getTriggerConditions();
405 if (!conditions.empty()) {
406 for (std::vector<TriggerCondition>::const_iterator citer = conditions.begin(); citer != conditions.end(); ++citer) {
407 TiXmlElement* conditionElement =
new TiXmlElement(
"condition");
408 conditionElement->SetAttribute(
"id", (*citer));
409 triggerElement->LinkEndChild(conditionElement);
412 triggersElement->LinkEndChild(triggerElement);
416 typedef std::vector<Camera*> CameraContainer;
418 for (CameraContainer::iterator iter = cameras.begin(); iter != cameras.end(); ++iter)
420 if ((*iter)->getMap()->getId() == map.
getId())
422 TiXmlElement* cameraElement =
new TiXmlElement(
"camera");
424 cameraElement->SetAttribute(
"id", (*iter)->getId());
425 cameraElement->SetDoubleAttribute(
"zoom", (*iter)->getZoom());
426 cameraElement->SetDoubleAttribute(
"tilt", (*iter)->getTilt());
427 cameraElement->SetDoubleAttribute(
"rotation", (*iter)->getRotation());
428 if ((*iter)->isZToYEnabled()) {
429 cameraElement->SetDoubleAttribute(
"ztoy", (*iter)->getZToY());
432 Rect viewport = (*iter)->getViewPort();
433 std::ostringstream viewportString;
434 viewportString << viewport.
x <<
"," 439 cameraElement->SetAttribute(
"viewport", viewportString.str());
441 Point p = (*iter)->getCellImageDimensions();
442 cameraElement->SetAttribute(
"ref_cell_width", p.
x);
443 cameraElement->SetAttribute(
"ref_cell_height", p.
y);
445 std::vector<float> lightingColor = (*iter)->getLightingColor();
446 bool writeLightingColor =
false;
447 for (
uint32_t i=0; i < lightingColor.size(); ++i)
449 if (lightingColor[i] < 1.0)
451 writeLightingColor =
true;
456 if (writeLightingColor)
458 std::ostringstream lightingColorString;
459 for (
uint32_t i=0; i < lightingColor.size(); ++i)
463 lightingColorString <<
",";
466 lightingColorString << lightingColor[i];
468 cameraElement->SetAttribute(
"light_color", lightingColorString.str());
472 mapElement->LinkEndChild(cameraElement);
477 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) 478 fp = _fsopen( filename.c_str(),
"w", _SH_DENYNO );
480 fp = fopen( filename.c_str(),
"w" );
const std::vector< Camera * > & getCameras() const
Get a list containing all cameras.
std::string getCostId() const
Returns the cost id.
double getCostMultiplier()
Returns the current cell cost.
virtual void setAnimationSaver(const FIFE::AnimationSaverPtr &animationSaver)
allows setting which animation saver will be used to save animation files
Layer * m_layer
target layer
const std::string & getId() const
Get the identifier for this map.
const double getYShift() const
Get the cellgrid y shift.
int32_t getStackPosition()
Gets current stack position of instance.
T h
Height of the rectangle.
Instance visual contains data that is needed to visualize the instance on screen. ...
double getSpeedMultiplier()
Returns the current cell speed.
AtlasSaverPtr m_atlasSaver
A CellCache is an abstract depiction of one or a few layers and contains additional information...
const std::string & getId() const
Get the id of this layer.
const std::list< Layer * > & getLayers() const
Get the layers on this map.
ObjectSaverPtr m_objectSaver
virtual const std::string & getType() const =0
Type of cellgrid.
static Logger _log(LM_AUDIO)
bool defaultCost()
Returns if cell use default cost.
virtual void setObjectSaver(const FIFE::ObjectSaverPtr &objectSaver)
allows setting which object saver will be used to save object files
const double getZShift() const
Get the cellgrid z shift.
const std::string & getId() const
std::vector< Trigger * > getAllTriggers()
Returns a vector with all trigger pointers.
const double getRotation() const
Get the cellgrid rotation.
double getCost() const
Returns the cost.
uint8_t getCellStackPosition() const
Returns cell stack position.
Simple class to hold the data for transistions.
virtual void setAtlasSaver(const FIFE::AtlasSaverPtr &atlasSaver)
allows setting which atlas saver will be used to save atlas files
static bool Equal(T _val1, T _val2)
double getDefaultSpeedMultiplier()
Gets default speed for this CellCache.
const std::set< Instance * > & getInstances()
Returns all instances on this cell.
const std::string & getNamespace() const
std::list< std::string > getCosts()
Returns all registered cost ids.
CellTypeInfo getCellType()
Returns blocker type.
bool existsCostForCell(const std::string &costId, Cell *cell)
Gets if cell is assigned to cost identifier.
const ModelCoordinate getLayerCoordinates() const
Returns the layer coordinates of this cell.
const double getXShift() const
Get the cellgrid x shift.
std::vector< std::string > getCellAreas(Cell *cell)
Returns all areas of a cell.
A basic cell on a CellCache.
const double getXScale() const
Get the cellgrid x-scaling.
const double getYScale() const
Get the cellgrid y-scaling.
const std::vector< std::vector< Cell * > > & getCells()
Returns all cells of this CellCache.
double getCost(const std::string &costId)
Returns the cost value for the given id.
virtual void save(const Map &map, const std::string &filename, const std::vector< std::string > &importFiles)
responsible for saving the map resource used to save map files
TransitionInfo * getTransition()
Returns the transition.
This class serves as a central place to manage triggers for a Map.
const std::set< Cell * > & getNarrowCells()
Returns narrow cells.
double getDefaultCostMultiplier()
Gets default cost for this CellCache.
TriggerController * getTriggerController() const
bool isSpecialCost() const
Gets if object uses special cost.
bool defaultSpeed()
Returns if cell use default speed.
T w
Width of the rectangle.
bool m_immediate
use immediate
bool isSearchNarrowCells()
Gets if narrow cells should be searched automatic.
bool isMultiPart() const
Gets if object is a part of a multi object.
AnimationSaverPtr m_animationSaver
ModelCoordinate m_mc
target coordinates