Added RoomData::[Pop/Push]Character()
This commit is contained in:
@@ -257,6 +257,37 @@ int RoomData::GetRoomIndex() {
|
||||
return roomIndex;
|
||||
}
|
||||
|
||||
void RoomData::PushCharacter(CharacterData* const character) {
|
||||
if (!character) {
|
||||
throw(std::logic_error("Failed to push a null character to RoomData"));
|
||||
}
|
||||
|
||||
//check to see if the character is already here
|
||||
for (auto& it : characterList) {
|
||||
if (it == character) {
|
||||
throw(std::logic_error("double insertion of CharacterData in RoomData"));
|
||||
}
|
||||
}
|
||||
|
||||
characterList.push_back(character);
|
||||
}
|
||||
|
||||
void RoomData::PopCharacter(CharacterData const * const character) {
|
||||
if (!character) {
|
||||
throw(std::logic_error("Failed to pop a null character to RoomData"));
|
||||
}
|
||||
|
||||
//check to see if the character isn't here
|
||||
for (auto& it : characterList) {
|
||||
if (it == character) {
|
||||
characterList.remove(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw(std::logic_error("cannot remove a non-existant instance of CharacterData in RoomData"));
|
||||
}
|
||||
|
||||
BarrierManager* RoomData::GetBarrierMgr() {
|
||||
return &barrierMgr;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,9 @@ public:
|
||||
int SetRoomIndex(int i);
|
||||
int GetRoomIndex();
|
||||
|
||||
void PushCharacter(CharacterData* const character);
|
||||
void PopCharacter(CharacterData const * const character);
|
||||
|
||||
BarrierManager* GetBarrierMgr();
|
||||
std::list<CharacterData*>* GetCharacterList();
|
||||
CreatureManager* GetCreatureMgr();
|
||||
@@ -86,7 +89,7 @@ private:
|
||||
std::string tilesetName;
|
||||
|
||||
//members
|
||||
int roomIndex = 0;
|
||||
int roomIndex = 0; //NOTE: What's this doing here?
|
||||
BarrierManager barrierMgr;
|
||||
std::list<CharacterData*> characterList;
|
||||
BattleManager battleMgr;
|
||||
|
||||
@@ -111,7 +111,7 @@ void RoomManager::UnloadIf(std::function<bool(std::pair<const int, RoomData cons
|
||||
lua_pop(lua, 1);
|
||||
}
|
||||
|
||||
void RoomManager::PushCharacter(CharacterData* character) {
|
||||
void RoomManager::PushCharacter(CharacterData* const character) {
|
||||
if (!character) {
|
||||
throw(std::runtime_error("Failed to push a null character to a room"));
|
||||
}
|
||||
@@ -119,27 +119,25 @@ void RoomManager::PushCharacter(CharacterData* character) {
|
||||
RoomData* room = Find(character->GetRoomIndex());
|
||||
|
||||
if (!room) {
|
||||
throw(std::runtime_error("Failed to push an character to a non-existant room"));
|
||||
throw(std::runtime_error("Failed to push a character to a non-existant room"));
|
||||
}
|
||||
|
||||
room->GetCharacterList()->push_back(character);
|
||||
room->PushCharacter(character);
|
||||
}
|
||||
|
||||
void RoomManager::PopCharacter(CharacterData const* character) {
|
||||
void RoomManager::PopCharacter(CharacterData const * const character) {
|
||||
//NOTE: to pop an character from a room, the character must first exist
|
||||
if (!character) {
|
||||
throw(std::runtime_error("Failed to pop a null character to a room"));
|
||||
throw(std::runtime_error("Failed to pop a null character from a room"));
|
||||
}
|
||||
|
||||
RoomData* room = Find(character->GetRoomIndex());
|
||||
|
||||
if (!room) {
|
||||
throw(std::runtime_error("Failed to pop an character to a non-existant room"));
|
||||
throw(std::runtime_error("Failed to pop a character to a non-existant room"));
|
||||
}
|
||||
|
||||
room->GetCharacterList()->remove_if([character](CharacterData* ptr) {
|
||||
return character == ptr;
|
||||
});
|
||||
room->PopCharacter(character);
|
||||
}
|
||||
|
||||
//TODO: rename these functions from Get to Find
|
||||
|
||||
@@ -39,8 +39,8 @@ public:
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
||||
|
||||
void PushCharacter(CharacterData* character);
|
||||
void PopCharacter(CharacterData const* character);
|
||||
void PushCharacter(CharacterData* const character);
|
||||
void PopCharacter(CharacterData const * const character);
|
||||
|
||||
//accessors and mutators
|
||||
RoomData* Find(int uid);
|
||||
|
||||
@@ -195,7 +195,7 @@ void pumpAndChangeRooms(int characterIndex, int newRoomIndex) {
|
||||
pumpAndChangeRooms(character, newRoomIndex, characterIndex);
|
||||
}
|
||||
|
||||
//TODO: (0) refactor this
|
||||
//NOTE: This is one of those ugly things that you just need to put up with
|
||||
void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex) {
|
||||
//delete the character from the old room
|
||||
CharacterPacket newPacket;
|
||||
|
||||
Reference in New Issue
Block a user