OpenXcom  1.0
Open-source clone of the original X-Com
MapScript.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <vector>
21 #include <string>
22 #include <yaml-cpp/yaml.h>
23 #include <SDL_video.h>
24 #include "MapBlock.h"
25 
26 namespace OpenXcom
27 {
28 
29 enum MapDirection {MD_NONE, MD_VERTICAL, MD_HORIZONTAL, MD_BOTH};
30 struct MCDReplacement { int set, entry;};
31 struct TunnelData
32  {
33  std::map<std::string, MCDReplacement> replacements;
34  int level;
35  MCDReplacement *getMCDReplacement(const std::string& type)
36  {
37  if (replacements.find(type) == replacements.end())
38  {
39  return 0;
40  }
41 
42  return &replacements[type];
43  }
44  };
45 enum MapScriptCommand {MSC_UNDEFINED = -1, MSC_ADDBLOCK, MSC_ADDLINE, MSC_ADDCRAFT, MSC_ADDUFO, MSC_DIGTUNNEL, MSC_FILLAREA, MSC_CHECKBLOCK, MSC_REMOVE, MSC_RESIZE};
46 
47 class MapBlock;
48 class RuleTerrain;
49 
50 class MapScript
51 {
52 private:
53  MapScriptCommand _type;
54  std::vector<SDL_Rect*> _rects;
55  std::vector<int> _groups, _blocks, _frequencies, _maxUses, _conditionals;
56  std::vector<int> _groupsTemp, _blocksTemp, _frequenciesTemp, _maxUsesTemp;
57  int _sizeX, _sizeY, _sizeZ, _executionChances, _executions, _cumulativeFrequency, _label;
58  MapDirection _direction;
59  TunnelData *_tunnelData;
60  std::string _ufoName;
61 
63  int getGroupNumber();
65  int getBlockNumber();
66 public:
67  MapScript();
68  ~MapScript();
70  void load(const YAML::Node& node);
72  void init();
74  MapScriptCommand getType() const {return _type;};
76  const std::vector<SDL_Rect*> *getRects() const {return &_rects;};
78  int getSizeX() const {return _sizeX;};
80  int getSizeY() const {return _sizeY;};
82  int getSizeZ() const {return _sizeZ;};
84  int getChancesOfExecution() const {return _executionChances;};
86  int getLabel() const {return _label;};
88  int getExecutions() const {return _executions;};
90  const std::vector<int> *getConditionals() const {return &_conditionals;};
92  const std::vector<int> *getGroups() const {return &_groups;};
94  const std::vector<int> *getBlocks() const {return &_blocks;};
96  MapDirection getDirection() const {return _direction;};
98  TunnelData *getTunnelData() {return _tunnelData;};
100  MapBlock *getNextBlock(RuleTerrain *terrain);
102  std::string getUFOName() const;
103 };
104 
105 }
int getExecutions() const
Gets how many times this command repeats (1 repeat means 2 executions)
Definition: MapScript.h:88
MapBlock * getNextBlock(RuleTerrain *terrain)
Randomly generate a block from within either the array of groups or blocks.
Definition: MapScript.cpp:363
Represents a Terrain Map Block.
Definition: MapBlock.h:37
const std::vector< SDL_Rect * > * getRects() const
Gets the rects, describing the areas this command applies to.
Definition: MapScript.h:76
MapScriptCommand getType() const
Gets what type of command this is.
Definition: MapScript.h:74
int getSizeX() const
Gets the X size for this command.
Definition: MapScript.h:78
TunnelData * getTunnelData()
Gets the mcd replacement data for tunnel replacements.
Definition: MapScript.h:98
const std::vector< int > * getBlocks() const
Gets the blocks vector for iteration.
Definition: MapScript.h:94
int getSizeY() const
Gets the Y size for this command.
Definition: MapScript.h:80
int getSizeZ() const
Gets the Z size for this command.
Definition: MapScript.h:82
const std::vector< int > * getGroups() const
Gets the groups vector for iteration.
Definition: MapScript.h:92
std::string getUFOName() const
Gets the UFO&#39;s name (for setUFO)
Definition: MapScript.cpp:381
const std::vector< int > * getConditionals() const
Gets what conditions apply to this command.
Definition: MapScript.h:90
Definition: MapScript.h:30
MapDirection getDirection() const
Gets the direction this command goes (for lines and tunnels).
Definition: MapScript.h:96
Definition: MapScript.h:31
int getLabel() const
Gets the label for this command.
Definition: MapScript.h:86
Definition: MapScript.h:50
void load(const YAML::Node &node)
Loads information from a ruleset file.
Definition: MapScript.cpp:47
int getChancesOfExecution() const
Get the chances of this command executing.
Definition: MapScript.h:84
Represents a specific type of Battlescape Terrain.
Definition: RuleTerrain.h:39
Definition: BaseInfoState.cpp:40
void init()
Initializes all the variables and junk for a mapscript command.
Definition: MapScript.cpp:267