game/mario/mapobject.cpp
zv0n 6ac2726a94
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Editor: slightly less hardcoded teleport map
2022-11-13 20:56:20 +01:00

112 lines
2.8 KiB
C++

#include "mapobject.hpp"
MapObject::MapObject(uint16_t terrain_id, LandType::Value terrain_type,
uint8_t character_id, LandType::Value character_type,
uint32_t modifier_id, uint8_t modifier_data, const std::string &modifier_text) {
setTerrain(terrain_id, terrain_type);
if (character_id != 0)
setCharacter(character_id, character_type);
if (modifier_id != 0) {
if(!modifier_text.empty()) {
setModifier(modifier_id, modifier_text);
} else {
setModifier(modifier_id, modifier_data);
}
}
}
MapObject::MapObject(uint16_t terrain_id, uint8_t terrain_type,
uint8_t character_id, uint8_t character_type,
uint32_t modifier_id, uint8_t modifier_data, const std::string &modifier_text)
: MapObject(terrain_id, static_cast<LandType::Value>(terrain_type),
character_id, static_cast<LandType::Value>(character_type),
modifier_id, modifier_data, modifier_text) {}
void MapObject::setTerrain(uint16_t id, LandType::Value land_type) {
terrain_id = id;
terrain_type = land_type;
}
void MapObject::setTerrain(uint16_t id, uint8_t land_type) {
setTerrain(id, static_cast<LandType::Value>(land_type));
}
void MapObject::setCharacter(uint8_t id, LandType::Value land_type) {
character_id = id;
character_type = land_type;
if (hasModifier()) {
modifier_id = 0;
modifier_data = 0;
}
}
void MapObject::setCharacter(uint8_t id, uint8_t land_type) {
setCharacter(id, static_cast<LandType::Value>(land_type));
}
void MapObject::setModifier(uint32_t id, uint8_t data) {
modifier_id = id;
modifier_data = data;
if (hasCharacter()) {
character_id = 0;
character_type = LandType::OVERWORLD;
}
}
void MapObject::setModifier(uint32_t id, const std::string &text) {
setModifier(id, 0);
modifier_text = text;
}
const std::string &MapObject::getModifierText() {
return modifier_text;
}
void MapObject::unsetTerrain() {
setTerrain(0, 0);
}
void MapObject::unsetModifier() {
if (hasModifier()) {
setModifier(0, 0);
}
}
void MapObject::unsetCharacter() {
if (hasCharacter()) {
setCharacter(0, 0);
}
}
bool MapObject::hasCharacter() {
return character_id != 0;
}
bool MapObject::hasModifier() {
return modifier_id != 0;
}
uint16_t MapObject::getTerrainId() {
return terrain_id;
}
uint8_t MapObject::getCharacterId() {
return character_id;
}
uint32_t MapObject::getModifierId() {
return modifier_id;
}
LandType::Value MapObject::getTerrainType() {
return terrain_type;
}
LandType::Value MapObject::getCharacterType() {
return character_type;
}
uint8_t MapObject::getModifierData() {
return modifier_data;
}