Skip to content

Commit

Permalink
Added snow and ice flags, made the map field flags into an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed Dec 23, 2018
1 parent 94261eb commit 9b6f78f
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 104 deletions.
3 changes: 2 additions & 1 deletion src/include/map/terrain_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CTerrainType
static CTerrainType *GetOrAddTerrainType(const std::string &ident);
static void LoadTerrainTypeGraphics();
static void ClearTerrainTypes();
static unsigned long GetTerrainFlagByName(const std::string &flag_name);

static std::vector<CTerrainType *> TerrainTypes;
static std::map<std::string, CTerrainType *> TerrainTypesByIdent;
Expand All @@ -90,7 +91,7 @@ class CTerrainType
int ID;
int SolidAnimationFrames;
int Resource;
unsigned int Flags;
unsigned long Flags;
bool Overlay; /// Whether this terrain type belongs to the overlay layer
bool Buildable;
bool AllowSingle; /// Whether this terrain type has transitions for single tiles
Expand Down
2 changes: 1 addition & 1 deletion src/include/map/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class CMapField
int GetResource() const;

unsigned char getCost() const { return cost; }
unsigned int getFlag() const { return Flags; }
unsigned long getFlag() const { return Flags; }
//Wyrmgus start
// void setGraphicTile(unsigned int tile) { this->tile = tile; }
//Wyrmgus end
Expand Down
90 changes: 36 additions & 54 deletions src/include/map/tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,60 +52,42 @@ class CPlayerColorGraphic;
class CUnitType;
//Wyrmgus end

//Wyrmgus start
/*
// Not used until now:
#define MapFieldSpeedMask 0x0007 /// Move faster on this tile
#define MapFieldLandAllowed 0x0010 /// Land units allowed
#define MapFieldCoastAllowed 0x0020 /// Coast (transporter) units allowed
#define MapFieldWaterAllowed 0x0040 /// Water units allowed
#define MapFieldNoBuilding 0x0080 /// No buildings allowed
#define MapFieldUnpassable 0x0100 /// Field is movement blocked
#define MapFieldWall 0x0200 /// Field contains wall
#define MapFieldRocks 0x0400 /// Field contains rocks
#define MapFieldForest 0x0800 /// Field contains forest
#define MapFieldLandUnit 0x1000 /// Land unit on field
#define MapFieldAirUnit 0x2000 /// Air unit on field
#define MapFieldSeaUnit 0x4000 /// Water unit on field
#define MapFieldBuilding 0x8000 /// Building on field
*/
#define MapFieldItem 0x00000004 /// Item on field

#define MapFieldSpeedMask 0x00000008 /// Move faster on this tile

#define MapFieldLandAllowed 0x00000010 /// Land units allowed
#define MapFieldCoastAllowed 0x00000020 /// Coast (transporter) units allowed
#define MapFieldWaterAllowed 0x00000040 /// Water units allowed
#define MapFieldNoBuilding 0x00000080 /// No buildings allowed

#define MapFieldUnpassable 0x00000100 /// Field is movement blocked
#define MapFieldWall 0x00000200 /// Field contains wall
#define MapFieldRocks 0x00000400 /// Field contains rocks
#define MapFieldForest 0x00000800 /// Field contains forest

#define MapFieldLandUnit 0x00001000 /// Land unit on field
#define MapFieldAirUnit 0x00002000 /// Air unit on field
#define MapFieldSeaUnit 0x00004000 /// Water unit on field
#define MapFieldBuilding 0x00008000 /// Building on field

#define MapFieldAirUnpassable 0x00010000 /// Field is movement blocked
#define MapFieldGrass 0x00020000 /// Used for playing grass step sounds
#define MapFieldMud 0x00040000 /// Used for playing mud step sounds
#define MapFieldStoneFloor 0x00080000 /// Used for playing stone step sounds

#define MapFieldDirt 0x00100000 /// Used for playing dirt step sounds
#define MapFieldGravel 0x00200000 /// Used for playing gravel step sounds
#define MapFieldStumps 0x00400000 /// Used for playing stumps step sounds
#define MapFieldBridge 0x00800000 /// Bridge or raft

#define MapFieldRoad 0x01000000 /// Road (moves faster)
#define MapFieldRailroad 0x02000000 /// Railroad (moves faster, even faster than with the road)
#define MapFieldNoRail 0x04000000 /// Marker that there's no railroad, used for rail movemasks
#define MapFieldDesert 0x08000000 /// Used for identifying desert tiles for desertstalk
//Wyrmgus end
enum MapFieldFlag : unsigned long long {
MapFieldSpeedMask = 1 << 0, /// Move faster on this tile

MapFieldLandAllowed = 1 << 1, /// Land units allowed
MapFieldCoastAllowed = 1 << 2, /// Coast (e.g. transporter) units allowed
MapFieldWaterAllowed = 1 << 3, /// Water units allowed
MapFieldNoBuilding = 1 << 4, /// No buildings allowed

MapFieldUnpassable = 1 << 5, /// Field is movement blocked
MapFieldAirUnpassable = 1 << 6, /// Field is movement blocked for air units and missiles
MapFieldWall = 1 << 7, /// Field contains wall
MapFieldRocks = 1 << 8, /// Field contains rocks
MapFieldForest = 1 << 9, /// Field contains forest

MapFieldLandUnit = 1 << 10, /// Land unit on field
MapFieldSeaUnit = 1 << 11, /// Water unit on field
MapFieldAirUnit = 1 << 12, /// Air unit on field
MapFieldBuilding = 1 << 13, /// Building on field
MapFieldItem = 1 << 14, /// Item on field

MapFieldRoad = 1 << 15, /// Road (moves faster)
MapFieldRailroad = 1 << 16, /// Railroad (moves faster)
MapFieldNoRail = 1 << 17, /// Marker that there's no railroad, used for rail movemasks
MapFieldBridge = 1 << 18, /// Bridge or raft

MapFieldGrass = 1 << 19, /// Used for playing grass step sounds
MapFieldMud = 1 << 20, /// Used for playing mud step sounds
MapFieldStoneFloor = 1 << 21, /// Used for playing stone step sounds
MapFieldDirt = 1 << 22, /// Used for playing dirt step sounds
MapFieldDesert = 1 << 23, /// Used for identifying desert tiles for desertstalk and dehydration
MapFieldSnow = 1 << 24, /// Used for playing snow step sounds
MapFieldIce = 1 << 25, /// Used for playing ice step sounds

MapFieldGravel = 1 << 26, /// Used for playing gravel step sounds
MapFieldStumps = 1 << 27, /// Used for playing stumps step sounds and identifying removed forests
};

/**
** These are used for lookup tiles types
Expand Down
12 changes: 12 additions & 0 deletions src/map/mapfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void CMapField::SetTerrain(CTerrainType *terrain_type)
}
if (this->OverlayTerrain) {
this->Flags &= ~(this->OverlayTerrain->Flags);

if (this->OverlayTerrainDestroyed) {
if (this->OverlayTerrain->Flags & MapFieldForest) {
this->Flags &= ~(MapFieldStumps);
Expand Down Expand Up @@ -268,6 +269,7 @@ void CMapField::RemoveOverlayTerrain()

this->Value = 0;
this->Flags &= ~(this->OverlayTerrain->Flags);

this->Flags &= ~(MapFieldCoastAllowed); // need to do this manually, since MapFieldCoast is added dynamically
this->OverlayTerrain = nullptr;
this->OverlayTransitionTiles.clear();
Expand Down Expand Up @@ -464,6 +466,9 @@ void CMapField::Save(CFile &file) const
if (Flags & MapFieldDirt) {
file.printf(", \"dirt\"");
}
if (Flags & MapFieldIce) {
file.printf(", \"ice\"");
}
if (Flags & MapFieldGrass) {
file.printf(", \"grass\"");
}
Expand All @@ -482,6 +487,9 @@ void CMapField::Save(CFile &file) const
if (Flags & MapFieldNoRail) {
file.printf(", \"no-rail\"");
}
if (Flags & MapFieldSnow) {
file.printf(", \"snow\"");
}
if (Flags & MapFieldStoneFloor) {
file.printf(", \"stone-floor\"");
}
Expand Down Expand Up @@ -661,6 +669,8 @@ void CMapField::parse(lua_State *l)
this->Flags |= MapFieldGrass;
} else if (!strcmp(value, "gravel")) {
this->Flags |= MapFieldGravel;
} else if (!strcmp(value, "ice")) {
this->Flags |= MapFieldIce;
} else if (!strcmp(value, "mud")) {
this->Flags |= MapFieldMud;
} else if (!strcmp(value, "railroad")) {
Expand All @@ -669,6 +679,8 @@ void CMapField::parse(lua_State *l)
this->Flags |= MapFieldRoad;
} else if (!strcmp(value, "no-rail")) {
this->Flags |= MapFieldNoRail;
} else if (!strcmp(value, "snow")) {
this->Flags |= MapFieldSnow;
} else if (!strcmp(value, "stone-floor")) {
this->Flags |= MapFieldStoneFloor;
} else if (!strcmp(value, "stumps")) {
Expand Down
8 changes: 8 additions & 0 deletions src/map/script_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,8 @@ static int CclGetTileTerrainHasFlag(lua_State *l)
flag = MapFieldGrass;
} else if (!strcmp(flag_name, "gravel")) {
flag = MapFieldGravel;
} else if (!strcmp(flag_name, "ice")) {
flag = MapFieldIce;
} else if (!strcmp(flag_name, "mud")) {
flag = MapFieldMud;
} else if (!strcmp(flag_name, "railroad")) {
Expand All @@ -1298,6 +1300,8 @@ static int CclGetTileTerrainHasFlag(lua_State *l)
flag = MapFieldRoad;
} else if (!strcmp(flag_name, "no-rail")) {
flag = MapFieldNoRail;
} else if (!strcmp(flag_name, "snow")) {
flag = MapFieldSnow;
} else if (!strcmp(flag_name, "stone-floor")) {
flag = MapFieldStoneFloor;
} else if (!strcmp(flag_name, "stumps")) {
Expand Down Expand Up @@ -1478,6 +1482,8 @@ static int CclDefineTerrainType(lua_State *l)
terrain->Flags |= MapFieldGrass;
} else if (tile_flag == "gravel") {
terrain->Flags |= MapFieldGravel;
} else if (tile_flag == "ice") {
terrain->Flags |= MapFieldIce;
} else if (tile_flag == "mud") {
terrain->Flags |= MapFieldMud;
} else if (tile_flag == "railroad") {
Expand All @@ -1486,6 +1492,8 @@ static int CclDefineTerrainType(lua_State *l)
terrain->Flags |= MapFieldRoad;
} else if (tile_flag == "no-rail") {
terrain->Flags |= MapFieldNoRail;
} else if (tile_flag == "snow") {
terrain->Flags |= MapFieldSnow;
} else if (tile_flag == "stone-floor") {
terrain->Flags |= MapFieldStoneFloor;
} else if (tile_flag == "stumps") {
Expand Down
2 changes: 2 additions & 0 deletions src/map/script_tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ static bool ModifyFlag(const char *flagName, unsigned int *flag)
{"dirt", MapFieldDirt},
{"grass", MapFieldGrass},
{"gravel", MapFieldGravel},
{"ice", MapFieldIce},
{"mud", MapFieldMud},
{"railroad", MapFieldRailroad},
{"road", MapFieldRoad},
{"no-rail", MapFieldNoRail},
{"snow", MapFieldSnow},
{"stone-floor", MapFieldStoneFloor},
{"stumps", MapFieldStumps},
//Wyrmgus end
Expand Down
104 changes: 61 additions & 43 deletions src/map/terrain_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,63 @@ void CTerrainType::ClearTerrainTypes()
TerrainTypesByColor.clear();
}

/**
** @brief Get a terrain flag by name
**
** @param flag_name The name of the terrain flag
**
** @return The terrain flag if it exists, or 0 otherwise
*/
unsigned long CTerrainType::GetTerrainFlagByName(const std::string &flag_name)
{
if (flag_name == "land") {
return MapFieldLandAllowed;
} else if (flag_name == "coast") {
return MapFieldCoastAllowed;
} else if (flag_name == "water") {
return MapFieldWaterAllowed;
} else if (flag_name == "no-building") {
return MapFieldNoBuilding;
} else if (flag_name == "unpassable") {
return MapFieldUnpassable;
} else if (flag_name == "wall") {
return MapFieldWall;
} else if (flag_name == "rock") {
return MapFieldRocks;
} else if (flag_name == "forest") {
return MapFieldForest;
} else if (flag_name == "air-unpassable") {
return MapFieldAirUnpassable;
} else if (flag_name == "desert") {
return MapFieldDesert;
} else if (flag_name == "dirt") {
return MapFieldDirt;
} else if (flag_name == "grass") {
return MapFieldGrass;
} else if (flag_name == "gravel") {
return MapFieldGravel;
} else if (flag_name == "ice") {
return MapFieldIce;
} else if (flag_name == "mud") {
return MapFieldMud;
} else if (flag_name == "railroad") {
return MapFieldRailroad;
} else if (flag_name == "road") {
return MapFieldRoad;
} else if (flag_name == "no-rail") {
return MapFieldNoRail;
} else if (flag_name == "snow") {
return MapFieldSnow;
} else if (flag_name == "stone-floor") {
return MapFieldStoneFloor;
} else if (flag_name == "stumps") {
return MapFieldStumps;
} else {
fprintf(stderr, "Flag \"%s\" doesn't exist.\n", flag_name.c_str());
return 0;
}
}

/**
** @brief Destructor
*/
Expand Down Expand Up @@ -200,46 +257,9 @@ void CTerrainType::ProcessConfigData(const CConfigData *config_data)
this->Resource = GetResourceIdByName(value.c_str());
} else if (key == "flag") {
value = FindAndReplaceString(value, "_", "-");
if (value == "land") {
this->Flags |= MapFieldLandAllowed;
} else if (value == "coast") {
this->Flags |= MapFieldCoastAllowed;
} else if (value == "water") {
this->Flags |= MapFieldWaterAllowed;
} else if (value == "no-building") {
this->Flags |= MapFieldNoBuilding;
} else if (value == "unpassable") {
this->Flags |= MapFieldUnpassable;
} else if (value == "wall") {
this->Flags |= MapFieldWall;
} else if (value == "rock") {
this->Flags |= MapFieldRocks;
} else if (value == "forest") {
this->Flags |= MapFieldForest;
} else if (value == "air-unpassable") {
this->Flags |= MapFieldAirUnpassable;
} else if (value == "desert") {
this->Flags |= MapFieldDesert;
} else if (value == "dirt") {
this->Flags |= MapFieldDirt;
} else if (value == "grass") {
this->Flags |= MapFieldGrass;
} else if (value == "gravel") {
this->Flags |= MapFieldGravel;
} else if (value == "mud") {
this->Flags |= MapFieldMud;
} else if (value == "railroad") {
this->Flags |= MapFieldRailroad;
} else if (value == "road") {
this->Flags |= MapFieldRoad;
} else if (value == "no-rail") {
this->Flags |= MapFieldNoRail;
} else if (value == "stone-floor") {
this->Flags |= MapFieldStoneFloor;
} else if (value == "stumps") {
this->Flags |= MapFieldStumps;
} else {
fprintf(stderr, "Flag \"%s\" doesn't exist.\n", value.c_str());
unsigned long flag = CTerrainType::GetTerrainFlagByName(value);
if (flag) {
this->Flags |= flag;
}
} else if (key == "graphics") {
graphics_file = value;
Expand Down Expand Up @@ -289,9 +309,7 @@ void CTerrainType::ProcessConfigData(const CConfigData *config_data)
}
}

for (size_t i = 0; i < config_data->Children.size(); ++i) {
const CConfigData *child_config_data = config_data->Children[i];

for (const CConfigData *child_config_data : config_data->Children) {
if (child_config_data->Tag == "season_graphics") {
std::string season_graphics_file;
CSeason *season = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions src/sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ static CSound *ChooseUnitVoiceSound(const CUnit &unit, UnitVoiceGroup voice)
case VoiceFireMissile:
return unit.Type->MapSound.FireMissile.Sound;
case VoiceStep:
if (unit.Type->MapSound.StepGravel.Sound && mf.getFlag() & MapFieldGravel) {
if (unit.Type->MapSound.StepMud.Sound && ((mf.getFlag() & MapFieldMud) || (mf.getFlag() & MapFieldSnow))) {
return unit.Type->MapSound.StepMud.Sound;
} else if (unit.Type->MapSound.StepDirt.Sound && ((mf.getFlag() & MapFieldDirt) || (mf.getFlag() & MapFieldIce))) {
return unit.Type->MapSound.StepDirt.Sound;
} else if (unit.Type->MapSound.StepGravel.Sound && mf.getFlag() & MapFieldGravel) {
return unit.Type->MapSound.StepGravel.Sound;
} else if (unit.Type->MapSound.StepGrass.Sound && ((mf.getFlag() & MapFieldGrass) || (mf.getFlag() & MapFieldStumps))) {
return unit.Type->MapSound.StepGrass.Sound;
} else if (unit.Type->MapSound.StepDirt.Sound && mf.getFlag() & MapFieldDirt) {
return unit.Type->MapSound.StepDirt.Sound;
} else if (unit.Type->MapSound.StepMud.Sound && mf.getFlag() & MapFieldMud) {
return unit.Type->MapSound.StepMud.Sound;
} else if (unit.Type->MapSound.StepStone.Sound && mf.getFlag() & MapFieldStoneFloor) {
return unit.Type->MapSound.StepStone.Sound;
} else {
Expand Down

0 comments on commit 9b6f78f

Please sign in to comment.