2023-11-16 00:44:12 +08:00

126 lines
2.8 KiB
C++

#ifndef TEXTADV_ROOM_H
#define TEXTADV_ROOM_H
#include <string>
#include <forward_list>
#include <list>
#include <map>
#include "GameObject.h"
#include "Serializable.h"
using std::string;
/**
* Represents a room (accessible location in the game).
*/
class Room : public Serializable {
/**
* Short name used as a header.
*/
const string* name;
/**
* Full description of the room.
*/
const string* description;
/**
* Room ID
*/
int room_id;
/**
* Pointer to room that is north of this one.
*/
int north_id;
int south_id;
int east_id;
int west_id;
// int: game object id
std::list<int> objects;
public:
/**
* for serialization
*/
Room();
/**
* Constructs a new Room.
* @param _name Name of the room.
* @param _desc Description of the room.
*/
Room(const string *_name, const string *_desc);
/**
* Removes a destroyed room from the global list if it's there.
*/
~Room();
/**
* Outputs the name and description of the room
* in standard format.
*/
void describe() const;
/**
* List storing all rooms that have been registered via addRoom().
*/
// static std::list<Room*> rooms;
static int room_id_counter;
/**
* Map storing all rooms that have been registered via addRoom().
*/
static std::map<int, Room *> room_map;
/**
* Returns a pointer to the room with the given ID.
* @param room_id
* @return
*/
static Room* getRoomById(int room_id);
/**
* Creates a new Room with the given parameters and register it with the static list.
* @param _name Name of the room.
* @param _desc Description of the room.
*/
static Room* addRoom(const string* _name, const string* _desc);
static void addRoom(Room* room);
int getRoomId() const;
void setRoomId(int _room_id);
Room* getNorth() const;
int getNorthId() const;
void setNorthId(int _north_id);
Room* getSouth() const;
int getSouthId() const;
void setSouthId(int _south_id);
Room* getEast() const;
int getEastId() const;
void setEastId(int _east_id);
Room* getWest() const;
int getWestId() const;
void setWestId(int _west_id);
void AddGameObject(int object_id);
void RemoveGameObject(int object_id);
bool IsInRoom(int object_id) const;
/**
* Find a game object in this room by keyword.
* @param keyword
* @return game object id, or -1 if not found
*/
int FindGameObject(const std::string &keyword) const;
string ToString() const override;
void FromString(const string &str) override;
};
#endif //TEXTADV_ROOM_H