From cb408a63a0f03ccb0b0ce7c338527a3b4964aff9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 20 Oct 2016 08:44:58 -0400 Subject: removed all old entity stuff --- include/entities.hpp | 541 ---------------------------------------------- include/entities.hpp.bak | 541 ++++++++++++++++++++++++++++++++++++++++++++++ include/inventory.hpp | 284 ------------------------ include/inventory.hpp.bak | 284 ++++++++++++++++++++++++ include/mob.hpp | 140 ------------ include/mob.hpp.bak | 140 ++++++++++++ include/quest.hpp | 66 ------ include/quest.hpp.bak | 66 ++++++ include/ui.hpp | 8 +- include/ui_action.hpp | 21 -- include/ui_action.hpp.bak | 21 ++ include/ui_quest.hpp | 4 +- include/world.hpp | 390 ++++----------------------------- 13 files changed, 1101 insertions(+), 1405 deletions(-) delete mode 100644 include/entities.hpp create mode 100644 include/entities.hpp.bak delete mode 100644 include/inventory.hpp create mode 100644 include/inventory.hpp.bak delete mode 100644 include/mob.hpp create mode 100644 include/mob.hpp.bak delete mode 100644 include/quest.hpp create mode 100644 include/quest.hpp.bak delete mode 100644 include/ui_action.hpp create mode 100644 include/ui_action.hpp.bak (limited to 'include') diff --git a/include/entities.hpp b/include/entities.hpp deleted file mode 100644 index 945e8c8..0000000 --- a/include/entities.hpp +++ /dev/null @@ -1,541 +0,0 @@ -/* ---------------------------------------------------------------------------- -** The entity stuffs. -** -** Entities. -** --------------------------------------------------------------------------*/ -#ifndef ENTITIES_H -#define ENTITIES_H -#define DEBUG - -/* ---------------------------------------------------------------------------- -** Includes section -** --------------------------------------------------------------------------*/ - -// local game includes -#include -#include -#include -#include -#include -#include - -// local library includes -#include -using namespace tinyxml2; - -/* ---------------------------------------------------------------------------- -** Structures section -** --------------------------------------------------------------------------*/ - -/** - * An entity type enumerator for identifying entities. - */ -enum _TYPE { - UNKNOWNT = -999, /**< who knows? */ - OBJECTT = -2, /**< an object (Object) */ - STRUCTURET, /**< a structure (Structures *) */ - PLAYERT, /**< the player (Player *) */ - NPCT, /**< an NPC (NPC *) */ - MERCHT, /**< a merchant (Merchant *) */ - MOBT /**< A mob (Mob *) */ -}; - -/** - * An enumerator for entity gender. - */ -enum GENDER{ - MALE, /**< male */ - FEMALE /**< female */ -}; - -/** - * An enumerator for strcture types. - * The subtype of a structure will affect how it is drawn and how it functions. - */ -enum BUILD_SUB{ - TOWN_HALL = 0, /**< a town hall */ - HOUSE, /**< a generic house */ - HOUSE2, /**< a generic house of a different style */ - HOUSE3, /**< a generic house of a different style */ - HOUSE4, /**< a generic house of a different style */ - FOUNTAIN, /**< a fountain, creates water particles */ - LAMP_POST, /**< a lamppost, creates light */ - FIRE_PIT, /**< a firepit, creates fire particles / light */ - STALL_MARKET = 70, /**< a stall for a merchant */ - STALL_TRADER -}; - -/** - * A structure for tracking potential trades between the player and a merchant. - */ -struct Trade { - // the names of the items up for trade - std::string item[2]; - // how much of each item to trade - int quantity[2]; - - // constructs a trade with the given values - Trade(int qo, std::string o, int qt, std::string t) { - item[0] = o; - item[1] = t; - quantity[0] = qo; - quantity[1] = qt; - } - - // creates an empty trade item - Trade(void) { - item[0] = ""; - item[1] = ""; - quantity[0] = 0; - quantity[1] = 0; - } -}; -typedef struct Trade Trade; - -/* ---------------------------------------------------------------------------- -** Variables section -** --------------------------------------------------------------------------*/ - -// the size of the player's inventory -extern const unsigned int PLAYER_INV_SIZE; -// the size of an NPC's inventory -extern const unsigned int NPC_INV_SIZE; - -/* ---------------------------------------------------------------------------- -** Classes / function prototypes section -** --------------------------------------------------------------------------*/ - -// a prototype of the world class, necessary for some function prototypes -class World; -class IndoorWorld; - -/** - * The light structure, used to store light coordinates and color. - */ - -class Light{ -public: - vec2 loc; /**< Light location */ - Color color; /**< Light color */ - float radius; /**< Light radius */ - - bool belongsTo; - Entity *following; - - bool flame; - float fireFlicker; - vec2 fireLoc; - Light() - { - loc = vec2(0,0); - color = Color(1.0, 1.0, 1.0); - radius = 0; - - belongsTo = false; - following = nullptr; - - flame = false; - } - - Light(vec2 l, float r, Color c) - { - loc = l; - color = c; - radius = r; - - belongsTo = false; - following = nullptr; - - flame = false; - } - - void follow(Entity *f) - { - following = f; - belongsTo = true; - } - - void makeFlame(void) - { - flame = true; - } - - void createFromXML(XMLElement *e); -}; - -/** - * The entity class. - * This class contains common functions and variables for all types of - * entities, i.e. a common structure. - */ -class Entity{ -protected: - // an incrementer for invincibility after a hit - unsigned int hitCooldown; - - // an incrementer for triggering change of movement with wander() - int ticksToUse; - - // entity handles an applied hit (sword) if set true - bool forcedMove; - - // if set false, entity will be destroyed - bool alive; - - // TODO - float targetx; - - // the cooldown display (red overlay) - float hitDuration; - - // the max cooldown display - float maxHitDuration; - - // the entity's XML element, for saving/loading stuff - XMLElement *xmle; - -public: - // contains the entity's coordinates, in pixels - vec2 loc; - float z; - - // contains the entity's velocity, in pixels - vec2 vel; - - // the entity's width, in pixels - float width; - - // the entity's height, in pixels - float height; - - // a speed multiplier, applied to velocity - float speed; - - // when true player may interact, and the entity's name will be drawn - bool near; - - // when true, the entity can move - int canMove; - - // tells direction entity is facing - bool right, left; - - // tells if the entity is from another world - char outnabout; - - // set to 1 if entity is on the ground, 0 if in the air - unsigned char ground; - - // the entity's inventory - Inventory *inv; - - // the entity's light - Light light; - - // the entity's health - float health; - - // the most health the entity can have - float maxHealth; - - // the type of the entity - _TYPE type; - - // the entity's subtype, if applicable - int subtype; - - // the entity's name, randomly generated on spawn - std::string name; - - // the entity's gender - GENDER gender; - - // a texture handler for the entity - TextureIterator tex; - - // draws the entity to the screen - void draw(void); - - // spawns the entity at the given coordinates - void spawn(float, float); - - // allows the entity to wander, according to what class is deriving this. - virtual void wander(int){} - virtual void wander(void){} - - // allows the entity to interact with the player - virtual void interact(void){} - - // causes the entity to move to the given x coordinate - void moveTo(float dest_x); - - // causes the entity to follow the one provided - void follow(Entity *e); - - // causes the entity to take a player-inflicted hit - void takeHit(unsigned int _health, unsigned int cooldown); - - // returns the amount of cool down before next hit - unsigned int coolDown(); - - // set the cool down - void setCooldown(unsigned int c); - - // handles hits if they've been taken - void handleHits(void); - - // insures that the entity is dead - void die(void); - - // checks if the entity is alive - bool isAlive(void) const; - - // checks if the entity is hit in some way - bool isHit(void) const; - - // returns true if this entity is near the one provided - bool isNear(const Entity *e); - - // returns true if the coordinate is within the entity - bool isInside(vec2 coord) const; - - // constructs the entity with an XML thing-thang - virtual void createFromXML(XMLElement *e, World *w=nullptr) =0; - virtual void saveToXML(void) =0; - -/* Entity - - ** - * Forces the given entity to follow this one. - * - void lead(Entity *e, unsigned int how); - - ** - * Attempts to break free from any following. - * - void unfollow(void);*/ - - // a common constructor, clears variables - Entity(void); - - // frees memory taken by the entity - virtual ~Entity(){} -}; - -class Player : public Entity { -public: - Entity *ride; - QuestHandler qh; - - Player(); - ~Player(); - void save(void); - void sspawn(float x,float y); - void createFromXML(XMLElement *e, World *w); - void saveToXML(void); -}; - -class Structures : public Entity { -public: - BUILD_SUB bsubtype; - World *inWorld; - World *insideWorld; - std::string inside; - std::string textureLoc; - - GLuint insideTex; - - Structures(); - ~Structures(); - - unsigned int spawn(BUILD_SUB, float, float); - void createFromXML(XMLElement *e, World *w); - void saveToXML(void); -}; - - -class NPC : public Entity { -private: - // the number of the random dialog to use - unsigned int randDialog; - - unsigned int dialogCount; - -public: - int dialogIndex; - - NPC(); - ~NPC(); - - void drawThingy(void) const; - - void addAIFunc(bool preload); - - void interact(); - void wander(int); - void createFromXML(XMLElement *e, World *w); - void saveToXML(void); -}; - -class Merchant : public NPC { -public: - std::vectortrade; - uint currTrade; - - std::string text[4]; - std::string *toSay; - //greeting - //accept - //deny - //farewell - - void interact(); - Structures *inside; - - Merchant(); - ~Merchant(); - - void wander(int); - void saveToXML(void); -}; - -class Object : public Entity{ -public: - std::string iname; - std::string pickupDialog; - bool questObject = false; - - Object(); - Object(std::string in,std::string pd); - ~Object(); - - void reloadTexture(void); - - void interact(void); - - bool operator==(const Object &o) { - return (name == o.name) && (loc == o.loc); - } - void createFromXML(XMLElement *e, World *w); - void saveToXML(void); -}; - -/** - * The particle class, handles a single particle. - */ -class Particles{ -public: - // the location of the particle - vec2 loc; - float zOffset; - - // the width of the particle, in pixels - float width; - - // the height of the particle, in pixels - float height; - - // the velocity of the particle, in pixels - vec2 vel; - - // the color of the particle - Color color; - - // TODO - vec2 index; - - // the amount of milliseconds left for the particle to live - float duration; - - // when true, the particle will move - bool canMove; - - // TODO - bool fountain; - - // when true, the particle will be affected by gravity - bool gravity; - - // when true, draws the particle behind structures - bool behind; - - // when true, the particle will bounce on impact with ground - bool bounce; - - Structures *stu; - - Particles(void){} - - // creates a particle with the desired characteristics - Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d); - - // allows the particle to be destroyed - ~Particles(void){} - - // draws the particle - void draw(GLfloat*& p) const; - - // updates a particle - void update(float _gravity, float ground_y); - - // returns true if the particle should be killed - bool timeUp(void); -}; - -#include - -constexpr Object *Objectp(Entity *e) { - return (Object *)e; -} - -constexpr NPC *NPCp(Entity *e) { - return (NPC *)e; -} - -constexpr Structures *Structurep(Entity *e) { - return (Structures *)e; -} - -constexpr Merchant *Merchantp(Entity *e) { - return (Merchant *)e; -} - -#include -#include - -class PlayerSystem : public entityx::System, public entityx::Receiver { -private: - Player **m_Player; - bool m_MoveLeft, m_MoveRight; - -public: - PlayerSystem(Player **p) - : m_Player(p), m_MoveLeft(false), m_MoveRight(false) {} - - void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; - - void configure(entityx::EventManager &ev); - void receive(const KeyDownEvent &kde); - void receive(const KeyUpEvent &kue); -}; - - -#endif // ENTITIES_H - -/** -ENTITY TYPES --1 STRUCTURES -|->1 Village -|->2 Castle -| -0 PLAYERS -|->Player -| -1 NPCS -|->0 Base -|->1 Merchant -| -2 MOBS -|->1 Rabbit -|->2 Bird -**/ diff --git a/include/entities.hpp.bak b/include/entities.hpp.bak new file mode 100644 index 0000000..945e8c8 --- /dev/null +++ b/include/entities.hpp.bak @@ -0,0 +1,541 @@ +/* ---------------------------------------------------------------------------- +** The entity stuffs. +** +** Entities. +** --------------------------------------------------------------------------*/ +#ifndef ENTITIES_H +#define ENTITIES_H +#define DEBUG + +/* ---------------------------------------------------------------------------- +** Includes section +** --------------------------------------------------------------------------*/ + +// local game includes +#include +#include +#include +#include +#include +#include + +// local library includes +#include +using namespace tinyxml2; + +/* ---------------------------------------------------------------------------- +** Structures section +** --------------------------------------------------------------------------*/ + +/** + * An entity type enumerator for identifying entities. + */ +enum _TYPE { + UNKNOWNT = -999, /**< who knows? */ + OBJECTT = -2, /**< an object (Object) */ + STRUCTURET, /**< a structure (Structures *) */ + PLAYERT, /**< the player (Player *) */ + NPCT, /**< an NPC (NPC *) */ + MERCHT, /**< a merchant (Merchant *) */ + MOBT /**< A mob (Mob *) */ +}; + +/** + * An enumerator for entity gender. + */ +enum GENDER{ + MALE, /**< male */ + FEMALE /**< female */ +}; + +/** + * An enumerator for strcture types. + * The subtype of a structure will affect how it is drawn and how it functions. + */ +enum BUILD_SUB{ + TOWN_HALL = 0, /**< a town hall */ + HOUSE, /**< a generic house */ + HOUSE2, /**< a generic house of a different style */ + HOUSE3, /**< a generic house of a different style */ + HOUSE4, /**< a generic house of a different style */ + FOUNTAIN, /**< a fountain, creates water particles */ + LAMP_POST, /**< a lamppost, creates light */ + FIRE_PIT, /**< a firepit, creates fire particles / light */ + STALL_MARKET = 70, /**< a stall for a merchant */ + STALL_TRADER +}; + +/** + * A structure for tracking potential trades between the player and a merchant. + */ +struct Trade { + // the names of the items up for trade + std::string item[2]; + // how much of each item to trade + int quantity[2]; + + // constructs a trade with the given values + Trade(int qo, std::string o, int qt, std::string t) { + item[0] = o; + item[1] = t; + quantity[0] = qo; + quantity[1] = qt; + } + + // creates an empty trade item + Trade(void) { + item[0] = ""; + item[1] = ""; + quantity[0] = 0; + quantity[1] = 0; + } +}; +typedef struct Trade Trade; + +/* ---------------------------------------------------------------------------- +** Variables section +** --------------------------------------------------------------------------*/ + +// the size of the player's inventory +extern const unsigned int PLAYER_INV_SIZE; +// the size of an NPC's inventory +extern const unsigned int NPC_INV_SIZE; + +/* ---------------------------------------------------------------------------- +** Classes / function prototypes section +** --------------------------------------------------------------------------*/ + +// a prototype of the world class, necessary for some function prototypes +class World; +class IndoorWorld; + +/** + * The light structure, used to store light coordinates and color. + */ + +class Light{ +public: + vec2 loc; /**< Light location */ + Color color; /**< Light color */ + float radius; /**< Light radius */ + + bool belongsTo; + Entity *following; + + bool flame; + float fireFlicker; + vec2 fireLoc; + Light() + { + loc = vec2(0,0); + color = Color(1.0, 1.0, 1.0); + radius = 0; + + belongsTo = false; + following = nullptr; + + flame = false; + } + + Light(vec2 l, float r, Color c) + { + loc = l; + color = c; + radius = r; + + belongsTo = false; + following = nullptr; + + flame = false; + } + + void follow(Entity *f) + { + following = f; + belongsTo = true; + } + + void makeFlame(void) + { + flame = true; + } + + void createFromXML(XMLElement *e); +}; + +/** + * The entity class. + * This class contains common functions and variables for all types of + * entities, i.e. a common structure. + */ +class Entity{ +protected: + // an incrementer for invincibility after a hit + unsigned int hitCooldown; + + // an incrementer for triggering change of movement with wander() + int ticksToUse; + + // entity handles an applied hit (sword) if set true + bool forcedMove; + + // if set false, entity will be destroyed + bool alive; + + // TODO + float targetx; + + // the cooldown display (red overlay) + float hitDuration; + + // the max cooldown display + float maxHitDuration; + + // the entity's XML element, for saving/loading stuff + XMLElement *xmle; + +public: + // contains the entity's coordinates, in pixels + vec2 loc; + float z; + + // contains the entity's velocity, in pixels + vec2 vel; + + // the entity's width, in pixels + float width; + + // the entity's height, in pixels + float height; + + // a speed multiplier, applied to velocity + float speed; + + // when true player may interact, and the entity's name will be drawn + bool near; + + // when true, the entity can move + int canMove; + + // tells direction entity is facing + bool right, left; + + // tells if the entity is from another world + char outnabout; + + // set to 1 if entity is on the ground, 0 if in the air + unsigned char ground; + + // the entity's inventory + Inventory *inv; + + // the entity's light + Light light; + + // the entity's health + float health; + + // the most health the entity can have + float maxHealth; + + // the type of the entity + _TYPE type; + + // the entity's subtype, if applicable + int subtype; + + // the entity's name, randomly generated on spawn + std::string name; + + // the entity's gender + GENDER gender; + + // a texture handler for the entity + TextureIterator tex; + + // draws the entity to the screen + void draw(void); + + // spawns the entity at the given coordinates + void spawn(float, float); + + // allows the entity to wander, according to what class is deriving this. + virtual void wander(int){} + virtual void wander(void){} + + // allows the entity to interact with the player + virtual void interact(void){} + + // causes the entity to move to the given x coordinate + void moveTo(float dest_x); + + // causes the entity to follow the one provided + void follow(Entity *e); + + // causes the entity to take a player-inflicted hit + void takeHit(unsigned int _health, unsigned int cooldown); + + // returns the amount of cool down before next hit + unsigned int coolDown(); + + // set the cool down + void setCooldown(unsigned int c); + + // handles hits if they've been taken + void handleHits(void); + + // insures that the entity is dead + void die(void); + + // checks if the entity is alive + bool isAlive(void) const; + + // checks if the entity is hit in some way + bool isHit(void) const; + + // returns true if this entity is near the one provided + bool isNear(const Entity *e); + + // returns true if the coordinate is within the entity + bool isInside(vec2 coord) const; + + // constructs the entity with an XML thing-thang + virtual void createFromXML(XMLElement *e, World *w=nullptr) =0; + virtual void saveToXML(void) =0; + +/* Entity + + ** + * Forces the given entity to follow this one. + * + void lead(Entity *e, unsigned int how); + + ** + * Attempts to break free from any following. + * + void unfollow(void);*/ + + // a common constructor, clears variables + Entity(void); + + // frees memory taken by the entity + virtual ~Entity(){} +}; + +class Player : public Entity { +public: + Entity *ride; + QuestHandler qh; + + Player(); + ~Player(); + void save(void); + void sspawn(float x,float y); + void createFromXML(XMLElement *e, World *w); + void saveToXML(void); +}; + +class Structures : public Entity { +public: + BUILD_SUB bsubtype; + World *inWorld; + World *insideWorld; + std::string inside; + std::string textureLoc; + + GLuint insideTex; + + Structures(); + ~Structures(); + + unsigned int spawn(BUILD_SUB, float, float); + void createFromXML(XMLElement *e, World *w); + void saveToXML(void); +}; + + +class NPC : public Entity { +private: + // the number of the random dialog to use + unsigned int randDialog; + + unsigned int dialogCount; + +public: + int dialogIndex; + + NPC(); + ~NPC(); + + void drawThingy(void) const; + + void addAIFunc(bool preload); + + void interact(); + void wander(int); + void createFromXML(XMLElement *e, World *w); + void saveToXML(void); +}; + +class Merchant : public NPC { +public: + std::vectortrade; + uint currTrade; + + std::string text[4]; + std::string *toSay; + //greeting + //accept + //deny + //farewell + + void interact(); + Structures *inside; + + Merchant(); + ~Merchant(); + + void wander(int); + void saveToXML(void); +}; + +class Object : public Entity{ +public: + std::string iname; + std::string pickupDialog; + bool questObject = false; + + Object(); + Object(std::string in,std::string pd); + ~Object(); + + void reloadTexture(void); + + void interact(void); + + bool operator==(const Object &o) { + return (name == o.name) && (loc == o.loc); + } + void createFromXML(XMLElement *e, World *w); + void saveToXML(void); +}; + +/** + * The particle class, handles a single particle. + */ +class Particles{ +public: + // the location of the particle + vec2 loc; + float zOffset; + + // the width of the particle, in pixels + float width; + + // the height of the particle, in pixels + float height; + + // the velocity of the particle, in pixels + vec2 vel; + + // the color of the particle + Color color; + + // TODO + vec2 index; + + // the amount of milliseconds left for the particle to live + float duration; + + // when true, the particle will move + bool canMove; + + // TODO + bool fountain; + + // when true, the particle will be affected by gravity + bool gravity; + + // when true, draws the particle behind structures + bool behind; + + // when true, the particle will bounce on impact with ground + bool bounce; + + Structures *stu; + + Particles(void){} + + // creates a particle with the desired characteristics + Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d); + + // allows the particle to be destroyed + ~Particles(void){} + + // draws the particle + void draw(GLfloat*& p) const; + + // updates a particle + void update(float _gravity, float ground_y); + + // returns true if the particle should be killed + bool timeUp(void); +}; + +#include + +constexpr Object *Objectp(Entity *e) { + return (Object *)e; +} + +constexpr NPC *NPCp(Entity *e) { + return (NPC *)e; +} + +constexpr Structures *Structurep(Entity *e) { + return (Structures *)e; +} + +constexpr Merchant *Merchantp(Entity *e) { + return (Merchant *)e; +} + +#include +#include + +class PlayerSystem : public entityx::System, public entityx::Receiver { +private: + Player **m_Player; + bool m_MoveLeft, m_MoveRight; + +public: + PlayerSystem(Player **p) + : m_Player(p), m_MoveLeft(false), m_MoveRight(false) {} + + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; + + void configure(entityx::EventManager &ev); + void receive(const KeyDownEvent &kde); + void receive(const KeyUpEvent &kue); +}; + + +#endif // ENTITIES_H + +/** +ENTITY TYPES +-1 STRUCTURES +|->1 Village +|->2 Castle +| +0 PLAYERS +|->Player +| +1 NPCS +|->0 Base +|->1 Merchant +| +2 MOBS +|->1 Rabbit +|->2 Bird +**/ diff --git a/include/inventory.hpp b/include/inventory.hpp deleted file mode 100644 index 533318c..0000000 --- a/include/inventory.hpp +++ /dev/null @@ -1,284 +0,0 @@ -#ifndef INVENTORY_H -#define INVENTORY_H - -#include -#include - -#include -#include - -#define DEBUG - -class Entity; - -/** - * The base item class - * This stores the name, width, height, and texture(s) - */ -class Item { -private: - bool beingUsed; - -protected: - std::vector interact; - -public: - - // what we want to call each item - std::string name; - - // how many pixel tall and white each thing is - dim2 dim; - - // the total amount of this item each slot can have - uint maxStackSize; - - // the array of textures for each frame of animation - Texturec *tex; - - // how much the item is rotated in the hand - float rotation = 0.0f; - - // return if the item is currently in use - virtual bool inUse(); - - // set the state of the item - virtual void setUse(bool use); - - // add entities to the list of those being interacted - virtual void addInteract(Entity* e); - virtual void addInteract(std::vector e); - - /** - * The function we use to call the child classes ability - * Note: Since this function is abstract, we HAVE to create one for each - * child class/type of item. - */ - virtual int useItem()=0; - - virtual Item* clone()=0; - - // destructor - virtual ~Item(); - // return the first texture for the item - GLuint rtex(); - - // return the nth texture for the item - GLuint rtex(int n); -}; - -/** - * Class for blank items, we use this for items that do not have an ability - * Like Quest or Debug items - */ -class BaseItem : public Item { -public: - // since the items don't have a use, we don't make one for it - int useItem(); - - BaseItem* clone(); - - //~BaseItem(){} -}; - -/** - * Sword class. This is for swords, y'know. Pretty basic stuff - */ -class Sword : public Item { -// can't touch this -private: - /** - * How much damage our sword will do - * notice that it's private to avoid a change - */ - float damage; - - Ray hitbox; - -//can touch this -public: - /** - * Lets us return the amount of damage the sword has - * TODO takes into account enchants and/or buffs/nerfs - */ - //TODO move - float getDamage(); - - // set the damage of the sword - void setDamage(float d); - - /** - * handles the swinging of the sword - */ - //TODO move - int useItem(); - - Sword* clone(); -}; - -class Arrow : public Item { -private: - // same as sword - float damage; -public: - - // see sword - float getDamage(); - - // sets amount of damage - void setDamage(float d); - - // uses item - int useItem(); - - Arrow *clone(); -}; - -/** - * Bow class. We use this for shooting bow and arrows - */ -class Bow : public Item { -private: - // same as sword - float damage; -public: - // returns the amount of damage, see sword - float getDamage(); - - // sets the amount of damages - void setDamage(float d); - - // handles shooting and arrow curving - int useItem(); - - Bow* clone(); -}; - -/** - * Raw food class, this will be used for uncooked meats... - * TODO Eating this may cause health loss, salmonela, mad cow diese - */ -class RawFood : public Item { -private: - // the amount of the health the food heals - float health; - -public: - // since the health is private, we get how much it is here - float getHealth(); - - // TODO chance to hurt - virtual int useItem(); - - RawFood* clone(); -}; - -/** - * Cooked/Naturale food class - * When this food is consumed, higher stats are gained than Raw Food and - * there is no chance of damage/de-buffs - */ -class Food : public RawFood { -private: -public: - - // consume food in hand, no chance for de-buff; - int useItem(); - - Food* clone(); -}; - -class ItemLight : public Item { -private: - // the color of the light - Color color; -public: - // turn on/off the light - // TODO - int useItem(); - - ItemLight* clone(); -}; - -/** - * Currency class. Well, it's used for currency - */ -class NewCurrency : public Item { -private: - // how much the coin is "worth" so to say - int value; -public: - // get the value of the coin - int getValue(); - - // TODO maybe play a jingling noise - // probably won't have a use - int useItem(); - - NewCurrency(){} - ~NewCurrency(){} -}; - -/*********************************************************************************** - * OLD STUFF THAT NEEDS TO GET UPDATED * - **********************************************************************************/ - -using InventorySlot = std::pair; - -class Inventory { -private: - unsigned int size; //how many slots our inventory has - unsigned int sel; //what item is currently selected - int os = 0; -public: - std::vector Items; - - bool invOpen = false; //is the inventory open - bool invOpening = false; //is the opening animation playing - bool invHover = false; //are we using the fancy hover inventory - bool selected = false; //used in hover inventory to show which item has been selected - bool mouseSel = false; //the location of the temperary selection for the hover inv - bool usingi = false; //bool used to tell if inventory owner is using selected item - - Inventory(unsigned int s); // Creates an inventory of size 's' - ~Inventory(void); // Free's allocated memory - - int useCurrent(); - void currentAddInteract(Entity* e); - void currentAddInteract(std::vector e); - - int addItem(std::string name,uint count); - int takeItem(std::string name,uint count); - int hasItem(std::string name); - - int useItem(void); - bool detectCollision(vec2,vec2); - - void setSelection(unsigned int s); - void setSelectionUp(); - void setSelectionDown(); - - void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now) - - const Item* getCurrentItem(void); -}; - -void initInventorySprites(void); -void destroyInventory(void); - -const char *getItemTexturePath(std::string name); -GLuint getItemTexture(std::string name); -float getItemWidth(std::string name); -float getItemHeight(std::string name); - -#include - -class InventorySystem : public entityx::System, public entityx::Receiver { -public: - void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; - - void configure(entityx::EventManager &em); - void receive(const MouseScrollEvent &mse); -}; - -#endif // INVENTORY_H diff --git a/include/inventory.hpp.bak b/include/inventory.hpp.bak new file mode 100644 index 0000000..533318c --- /dev/null +++ b/include/inventory.hpp.bak @@ -0,0 +1,284 @@ +#ifndef INVENTORY_H +#define INVENTORY_H + +#include +#include + +#include +#include + +#define DEBUG + +class Entity; + +/** + * The base item class + * This stores the name, width, height, and texture(s) + */ +class Item { +private: + bool beingUsed; + +protected: + std::vector interact; + +public: + + // what we want to call each item + std::string name; + + // how many pixel tall and white each thing is + dim2 dim; + + // the total amount of this item each slot can have + uint maxStackSize; + + // the array of textures for each frame of animation + Texturec *tex; + + // how much the item is rotated in the hand + float rotation = 0.0f; + + // return if the item is currently in use + virtual bool inUse(); + + // set the state of the item + virtual void setUse(bool use); + + // add entities to the list of those being interacted + virtual void addInteract(Entity* e); + virtual void addInteract(std::vector e); + + /** + * The function we use to call the child classes ability + * Note: Since this function is abstract, we HAVE to create one for each + * child class/type of item. + */ + virtual int useItem()=0; + + virtual Item* clone()=0; + + // destructor + virtual ~Item(); + // return the first texture for the item + GLuint rtex(); + + // return the nth texture for the item + GLuint rtex(int n); +}; + +/** + * Class for blank items, we use this for items that do not have an ability + * Like Quest or Debug items + */ +class BaseItem : public Item { +public: + // since the items don't have a use, we don't make one for it + int useItem(); + + BaseItem* clone(); + + //~BaseItem(){} +}; + +/** + * Sword class. This is for swords, y'know. Pretty basic stuff + */ +class Sword : public Item { +// can't touch this +private: + /** + * How much damage our sword will do + * notice that it's private to avoid a change + */ + float damage; + + Ray hitbox; + +//can touch this +public: + /** + * Lets us return the amount of damage the sword has + * TODO takes into account enchants and/or buffs/nerfs + */ + //TODO move + float getDamage(); + + // set the damage of the sword + void setDamage(float d); + + /** + * handles the swinging of the sword + */ + //TODO move + int useItem(); + + Sword* clone(); +}; + +class Arrow : public Item { +private: + // same as sword + float damage; +public: + + // see sword + float getDamage(); + + // sets amount of damage + void setDamage(float d); + + // uses item + int useItem(); + + Arrow *clone(); +}; + +/** + * Bow class. We use this for shooting bow and arrows + */ +class Bow : public Item { +private: + // same as sword + float damage; +public: + // returns the amount of damage, see sword + float getDamage(); + + // sets the amount of damages + void setDamage(float d); + + // handles shooting and arrow curving + int useItem(); + + Bow* clone(); +}; + +/** + * Raw food class, this will be used for uncooked meats... + * TODO Eating this may cause health loss, salmonela, mad cow diese + */ +class RawFood : public Item { +private: + // the amount of the health the food heals + float health; + +public: + // since the health is private, we get how much it is here + float getHealth(); + + // TODO chance to hurt + virtual int useItem(); + + RawFood* clone(); +}; + +/** + * Cooked/Naturale food class + * When this food is consumed, higher stats are gained than Raw Food and + * there is no chance of damage/de-buffs + */ +class Food : public RawFood { +private: +public: + + // consume food in hand, no chance for de-buff; + int useItem(); + + Food* clone(); +}; + +class ItemLight : public Item { +private: + // the color of the light + Color color; +public: + // turn on/off the light + // TODO + int useItem(); + + ItemLight* clone(); +}; + +/** + * Currency class. Well, it's used for currency + */ +class NewCurrency : public Item { +private: + // how much the coin is "worth" so to say + int value; +public: + // get the value of the coin + int getValue(); + + // TODO maybe play a jingling noise + // probably won't have a use + int useItem(); + + NewCurrency(){} + ~NewCurrency(){} +}; + +/*********************************************************************************** + * OLD STUFF THAT NEEDS TO GET UPDATED * + **********************************************************************************/ + +using InventorySlot = std::pair; + +class Inventory { +private: + unsigned int size; //how many slots our inventory has + unsigned int sel; //what item is currently selected + int os = 0; +public: + std::vector Items; + + bool invOpen = false; //is the inventory open + bool invOpening = false; //is the opening animation playing + bool invHover = false; //are we using the fancy hover inventory + bool selected = false; //used in hover inventory to show which item has been selected + bool mouseSel = false; //the location of the temperary selection for the hover inv + bool usingi = false; //bool used to tell if inventory owner is using selected item + + Inventory(unsigned int s); // Creates an inventory of size 's' + ~Inventory(void); // Free's allocated memory + + int useCurrent(); + void currentAddInteract(Entity* e); + void currentAddInteract(std::vector e); + + int addItem(std::string name,uint count); + int takeItem(std::string name,uint count); + int hasItem(std::string name); + + int useItem(void); + bool detectCollision(vec2,vec2); + + void setSelection(unsigned int s); + void setSelectionUp(); + void setSelectionDown(); + + void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now) + + const Item* getCurrentItem(void); +}; + +void initInventorySprites(void); +void destroyInventory(void); + +const char *getItemTexturePath(std::string name); +GLuint getItemTexture(std::string name); +float getItemWidth(std::string name); +float getItemHeight(std::string name); + +#include + +class InventorySystem : public entityx::System, public entityx::Receiver { +public: + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; + + void configure(entityx::EventManager &em); + void receive(const MouseScrollEvent &mse); +}; + +#endif // INVENTORY_H diff --git a/include/mob.hpp b/include/mob.hpp deleted file mode 100644 index 24b8ed9..0000000 --- a/include/mob.hpp +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef MOB_H_ -#define MOB_H_ - -#include -#include - -#include -#include -#include -#include -#include - -// local library headers -#include -using namespace tinyxml2; - -extern Player *player; -extern std::string currentXML; - -using Drop = std::tuple; - -class Mob : public Entity { -protected: - XMLElement *xmle; - std::forward_list drop; - - unsigned int actCounter; - unsigned int actCounterInitial; - bool ridable; -public: - Entity *rider; - bool aggressive; - std::string heyid; - - Mob(void); - ~Mob(void); - - void wander(void); - void ride(Entity *e); - virtual void act(void) =0; - - virtual void onHit(unsigned int) =0; - virtual void onDeath(void); - - virtual bool bindTex(void) =0; -}; - -constexpr Mob *Mobp(Entity *e) { - return (Mob *)e; -} - -class Page : public Mob { -private: - std::string cId, cValue; - std::string pageTexPath; - GLuint pageTexture; -public: - Page(void); - - void act(void); - void onHit(unsigned int); - bool bindTex(void); - void createFromXML(XMLElement *e, World *w) final; - void saveToXML(void) final; -}; - -class Door : public Mob { -public: - Door(void); - - void act(void); - void onHit(unsigned int); - bool bindTex(void); - void createFromXML(XMLElement *e, World *w) final; - void saveToXML(void) final; -}; - -class Cat : public Mob { -public: - Cat(void); - - void act(void); - void onHit(unsigned int); - bool bindTex(void); - void createFromXML(XMLElement *e, World *w) final; - void saveToXML(void) final; -}; - -class Rabbit : public Mob { -public: - Rabbit(void); - - void act(void); - void onHit(unsigned int); - bool bindTex(void); - void createFromXML(XMLElement *e, World *w) final; - void saveToXML(void) final; -}; - -class Bird : public Mob { -private: - float initialY; -public: - Bird(void); - - void act(void); - void onHit(unsigned int); - bool bindTex(void); - void createFromXML(XMLElement *e, World *w) final; - void saveToXML(void) final; -}; - -class Trigger : public Mob { -private: - std::string id; - bool triggered; -public: - bool notext; - - Trigger(void); - - void act(void); - void onHit(unsigned int); - bool bindTex(void); - void createFromXML(XMLElement *e, World *w) final; - void saveToXML(void) final; -}; - -class Chest : public Mob { -public: - Chest(void); - - void act(void); - void onHit(unsigned int); - bool bindTex(void); - void createFromXML(XMLElement *e, World *w) final; - void saveToXML(void) final; -}; - -#endif // MOB_H_ diff --git a/include/mob.hpp.bak b/include/mob.hpp.bak new file mode 100644 index 0000000..24b8ed9 --- /dev/null +++ b/include/mob.hpp.bak @@ -0,0 +1,140 @@ +#ifndef MOB_H_ +#define MOB_H_ + +#include +#include + +#include +#include +#include +#include +#include + +// local library headers +#include +using namespace tinyxml2; + +extern Player *player; +extern std::string currentXML; + +using Drop = std::tuple; + +class Mob : public Entity { +protected: + XMLElement *xmle; + std::forward_list drop; + + unsigned int actCounter; + unsigned int actCounterInitial; + bool ridable; +public: + Entity *rider; + bool aggressive; + std::string heyid; + + Mob(void); + ~Mob(void); + + void wander(void); + void ride(Entity *e); + virtual void act(void) =0; + + virtual void onHit(unsigned int) =0; + virtual void onDeath(void); + + virtual bool bindTex(void) =0; +}; + +constexpr Mob *Mobp(Entity *e) { + return (Mob *)e; +} + +class Page : public Mob { +private: + std::string cId, cValue; + std::string pageTexPath; + GLuint pageTexture; +public: + Page(void); + + void act(void); + void onHit(unsigned int); + bool bindTex(void); + void createFromXML(XMLElement *e, World *w) final; + void saveToXML(void) final; +}; + +class Door : public Mob { +public: + Door(void); + + void act(void); + void onHit(unsigned int); + bool bindTex(void); + void createFromXML(XMLElement *e, World *w) final; + void saveToXML(void) final; +}; + +class Cat : public Mob { +public: + Cat(void); + + void act(void); + void onHit(unsigned int); + bool bindTex(void); + void createFromXML(XMLElement *e, World *w) final; + void saveToXML(void) final; +}; + +class Rabbit : public Mob { +public: + Rabbit(void); + + void act(void); + void onHit(unsigned int); + bool bindTex(void); + void createFromXML(XMLElement *e, World *w) final; + void saveToXML(void) final; +}; + +class Bird : public Mob { +private: + float initialY; +public: + Bird(void); + + void act(void); + void onHit(unsigned int); + bool bindTex(void); + void createFromXML(XMLElement *e, World *w) final; + void saveToXML(void) final; +}; + +class Trigger : public Mob { +private: + std::string id; + bool triggered; +public: + bool notext; + + Trigger(void); + + void act(void); + void onHit(unsigned int); + bool bindTex(void); + void createFromXML(XMLElement *e, World *w) final; + void saveToXML(void) final; +}; + +class Chest : public Mob { +public: + Chest(void); + + void act(void); + void onHit(unsigned int); + bool bindTex(void); + void createFromXML(XMLElement *e, World *w) final; + void saveToXML(void) final; +}; + +#endif // MOB_H_ diff --git a/include/quest.hpp b/include/quest.hpp deleted file mode 100644 index 2db65a2..0000000 --- a/include/quest.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/** @file Quest.h - * @brief The quest handling system. - * - * This file contains Quest and QuestHandler, used to manage quests inside the - * game. - */ - -#ifndef QUEST_H -#define QUEST_H - -#include - -#include - -/** - * When defined, DEBUG allows extra messages to be printed to the terminal for - * debugging purposes. - */ - -#define DEBUG - -typedef struct { - std::string title; - std::string desc; - std::pair reward; - std::vector> need; -} Quest; - -/** - * The Quest Handler class. - * - * This class handles quests, including the assigning, dropping, and completing - * of the quests. - */ - -class QuestHandler { -public: - std::vectorcurrent; - - /** - * Adds a quest to the current quest vector by its title. - */ - - int assign(std::string title,std::string desc,std::string req); - - /** - * Drops a quest through its title. - */ - - int drop(std::string title); - - /** - * Finishes a quest through it's title, also giving a pointer to the Entity - * that gave the quest originally. - */ - - int finish(std::string t); - - /** - * Returns true if this handler is currently taking the quest. - */ - - bool hasQuest(std::string t); -}; - -#endif // QUEST_H diff --git a/include/quest.hpp.bak b/include/quest.hpp.bak new file mode 100644 index 0000000..2db65a2 --- /dev/null +++ b/include/quest.hpp.bak @@ -0,0 +1,66 @@ +/** @file Quest.h + * @brief The quest handling system. + * + * This file contains Quest and QuestHandler, used to manage quests inside the + * game. + */ + +#ifndef QUEST_H +#define QUEST_H + +#include + +#include + +/** + * When defined, DEBUG allows extra messages to be printed to the terminal for + * debugging purposes. + */ + +#define DEBUG + +typedef struct { + std::string title; + std::string desc; + std::pair reward; + std::vector> need; +} Quest; + +/** + * The Quest Handler class. + * + * This class handles quests, including the assigning, dropping, and completing + * of the quests. + */ + +class QuestHandler { +public: + std::vectorcurrent; + + /** + * Adds a quest to the current quest vector by its title. + */ + + int assign(std::string title,std::string desc,std::string req); + + /** + * Drops a quest through its title. + */ + + int drop(std::string title); + + /** + * Finishes a quest through it's title, also giving a pointer to the Entity + * that gave the quest originally. + */ + + int finish(std::string t); + + /** + * Returns true if this handler is currently taking the quest. + */ + + bool hasQuest(std::string t); +}; + +#endif // QUEST_H diff --git a/include/ui.hpp b/include/ui.hpp index 8671393..c7a69b6 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -21,10 +21,9 @@ // local game headers #include #include -#include -#include +//#include #include -#include +//#include // local library headers #include @@ -71,7 +70,6 @@ namespace ui { extern bool posFlag; extern unsigned char dialogOptChosen; - extern unsigned char merchOptChosen; extern bool dialogBoxExists; extern bool dialogImportant; extern bool dialogPassive; @@ -123,8 +121,6 @@ namespace ui { void drawBox(vec2 c1, vec2 c2); void drawNiceBox(vec2 c1, vec2 c2, float z); void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...); - void merchantBox(const char *name,Trade trade,const char *opt,bool passive,const char *text,...); - void merchantBox(); void closeBox(); void waitForDialog(void); diff --git a/include/ui_action.hpp b/include/ui_action.hpp deleted file mode 100644 index a275ab3..0000000 --- a/include/ui_action.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ACTION_H_ -#define ACTION_H_ - -#include -#include - -namespace ui { - namespace action { - extern bool make; - - // enables the action ui - void enable(void); - // disables the action ui - void disable(void); - - // draws the action ui - void draw(vec2 loc); - } -} - -#endif // ACTION_H_ diff --git a/include/ui_action.hpp.bak b/include/ui_action.hpp.bak new file mode 100644 index 0000000..a275ab3 --- /dev/null +++ b/include/ui_action.hpp.bak @@ -0,0 +1,21 @@ +#ifndef ACTION_H_ +#define ACTION_H_ + +#include +#include + +namespace ui { + namespace action { + extern bool make; + + // enables the action ui + void enable(void); + // disables the action ui + void disable(void); + + // draws the action ui + void draw(vec2 loc); + } +} + +#endif // ACTION_H_ diff --git a/include/ui_quest.hpp b/include/ui_quest.hpp index 24a5e1b..8582b67 100644 --- a/include/ui_quest.hpp +++ b/include/ui_quest.hpp @@ -27,14 +27,14 @@ namespace ui { ui::putStringCentered(offset.x, top_y - 40, "Current Quests:"); - auto y = top_y - 100; + /*auto y = top_y - 100; const auto x = offset.x - 180; for (const auto &q : player->qh.current) { ui::putText(x, y, q.title.c_str()); y -= 20; ui::putText(x + 40, y, q.desc.c_str()); y -= 40; - } + }*/ std::swap(textWrap, ui::textWrapLimit); } diff --git a/include/world.hpp b/include/world.hpp index dc07267..36ccdfa 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -8,9 +8,13 @@ // local game includes #include -#include #include +#include +#include +#include +using namespace tinyxml2; + /** * The background type enum. * This enum contains all different possibilities for world backgrounds; used @@ -43,13 +47,6 @@ typedef struct { unsigned char groundColor; /**< a value that affects the ground's color */ } WorldData; -/** - * Contains info necessary for switching worlds. - * This pair contains a pointer to the new world, and the new set of - * coordinates the player should be at in that world. - */ -using WorldSwitchInfo = std::pair; - /** * Alters how bright world elements are drawn. * This value is based off of the current time of day (tick count), set in @@ -95,41 +92,6 @@ constexpr const unsigned int INDOOR_FLOOR_HEIGHTT = 400; */ constexpr const unsigned int INDOOR_FLOOR_HEIGHT = (INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS); -/** - * The village class. - * This class defines an area in a world that is considered to be a village, - * and provides a welcome message when the player enters the area. - */ -class Village { -public: - /** - * The name of the village. - */ - std::string name; - - /** - * The start and end coordinates of the village. - */ - vec2 start, end; - - /** - * A "player in village" flag. - * This flag is used to trigger displaying the welcome message. - */ - bool in; - - /** - * Constructs a village with the given name, inside the given world. - */ - Village(std::string meme, World *w); - - /** - * Destructs the village. - */ - ~Village(void){} -}; - - #include constexpr const char* WorldWeatherString[3] = { @@ -138,20 +100,45 @@ constexpr const char* WorldWeatherString[3] = { "Snowy" }; +struct WorldData2 { + // data + std::vector data; + float startX; + + // indoor + bool indoor; + float indoorWidth; + GLuint indoorTex; + + // links + std::string toLeft, toRight; + + // style + WorldBGType style; + std::string styleFolder; + std::vector sTexLoc; + + // music + std::string bgm; + + // village + float villageStart, villageEnd; +}; + class WorldSystem : public entityx::System, public entityx::Receiver { private: - World *world; - World *outside; + WorldData2 world; WorldWeather weather; Mix_Music *bgmObj; - std::string bgmObjFile; std::vector bgFiles; TextureIterator bgTex; + XMLDocument xmlDoc; + public: explicit WorldSystem(void); ~WorldSystem(void); @@ -160,13 +147,14 @@ public: ev.subscribe(*this); } + inline float getWidth(void) const + { return world.startX * -2.0f; } + void receive(const BGMToggleEvent &bte); void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; void render(void); - void setWorld(World *w); - inline const std::string getWeatherStr(void) const { return WorldWeatherString[static_cast(weather)]; } @@ -175,299 +163,20 @@ public: void setWeather(const std::string &s); - void singleDetect(Entity *e, entityx::TimeDelta dt); void detect(entityx::TimeDelta dt); - void detect2(entityx::TimeDelta dt); - - void enterWorld(World *w); - void leaveWorld(void); -}; - - -/** - * The world class. - * This class handles entity creation, management, and deletion. Most - * world-related operations have to be done through this class, such as - * drawing. - */ -class World { -private: - bool m_Indoor; - -public: - - float HouseWidth; - GLuint houseTex; - - inline bool isIndoor(void) const - { return m_Indoor; } - - WorldBGType bgType; - - std::string styleFolder; + void goWorldLeft(void) {} + void goWorldRight(void) {} - /** - * An array of all the world's ground data, populated through - * World::generate(). - * @see generate() - */ - std::vector worldData; - - /** - * Contains the size of the 'worldData' array. - */ - unsigned int lineCount; - - /** - * The starting x-coordinate of the world. - */ - float worldStart; - - /** - * The path to the XML file of the world to the left. - * - * @see setToLeft() - */ - std::string toLeft; - - /** - * The path to the XML file of the world to the right. - * - * @see setToRight() - */ - std::string toRight; - - /** - * A vector of paths for the structure textures. - * The appearance of structures depends on the world's theme. - * - * @see setStyle() - */ - std::vector sTexLoc; - - /** - * Contains randomly generated coordinates for stars. - */ - std::vector star; - - /** - * A vector of all light elements in the world. - * - * @see addLight() - * @see getLastLight() - */ - std::vector light; - - /** - * A vector of all villages in the world. - * - * @see addVillage() - */ - std::vector village; - - std::vector entityPending; - - /** - * Destroys entities and clears vectors that contain them. - * This function is only called in the world destructor. - */ - void deleteEntities(void); - - /** - * The filename of the world's BGM file. - * - * @see setBGM() - */ - std::string bgm; - - CoolArray particles; - - /** - * A vector of pointers to all entities from the other vectors. - * This is used to mass-manage entities, or operate on entities - * outside of what the world does. - * - * @see getNearInteractable() - */ - std::vector entity; - - /** - * Constructs the world, resets variables. - */ - World(bool indoor = false); - - /** - * Destructs the world, frees memory. - */ - virtual ~World(void); - - /** - * Generates a world of the specified width. - * This will populate the 'worldData' array and create star coordinates. - * It's necessary to call this function to actually use the world. - */ - void generate(int width); - - /** - * Draws everything the world handles to the screen (and the player). - * Drawing is based off of the player so that off-screen elements are not - * drawn. - */ - virtual void draw(Player *p); - - /** - * Gets the width of the world, presumably in pixels. - * TODO - */ - int getTheWidth(void) const; - - /** - * Gets the starting x-coordinate of the world. - * - * @see worldStart - */ - float getWorldStart(void) const; - - inline unsigned int getEntityCount(void) const { - return entity.size(); - } + // worlddata2 stuff + WorldData2 worldData; - /** - * Gets a pointer to the most recently created light. - * This is used to update properties of the light outside of the - * world class. - */ - Light& getLastLight(void); + void generate(unsigned int width = 0); + void addHole(const unsigned int& start, const unsigned int& end); + void addHill(const ivec2& peak, const unsigned int& width); - /** - * Gets a pointer ot the most recently created mob. - * This is used to update properties of the mob outside of the - * world class. - */ - Mob* getLastMob(void); - - /** - * Finds the entity nearest to the provided one. - */ - Entity* getNearInteractable(Entity &e); - - /** - * Finds the mob nearest to the given entity. - */ - Mob* getNearMob(Entity &e); - - /** - * Gets the coordinates of the `index`th structure. - */ - vec2 getStructurePos(int index); - - /** - * Gets the texture path of the `index`th structure - */ - std::string getSTextureLocation(unsigned int index) const; - - // saves the world's data to an XML file, either the one provided or the current path - void save(const std::string& s=""); - - // sets the world's background theme - void setBackground(WorldBGType bgt); - - // sets the folder to collect entity textures from - void setStyle(std::string pre); - - // gets the string that represents the current weather - std::string getWeatherStr(void) const; - const WorldWeather& getWeatherId(void) const; - - // sets the weatherrrr - void setWeather(const std::string& w); - - // sets / gets pathnames of XML files for worlds to the left and right - std::string setToLeft(std::string file); - std::string setToRight(std::string file); - std::string getToLeft(void) const; - std::string getToRight(void) const; - - // attempts to enter the left/right adjacent world, returning either that world or this - WorldSwitchInfo goWorldLeft(Player *p); - WorldSwitchInfo goWorldRight(Player *p); - - /** - * Attempts to move an NPC to the left adjacent world, returning true on success. - */ - bool goWorldLeft(NPC *e); - - /** - * Attempts to move an NPC to the world to the right, returning true on success. - */ - bool goWorldRight(NPC *e); - - // attempts to enter a structure that the player would be standing in front of - WorldSwitchInfo goInsideStructure(Player *p); - - /** - * Adopts an NPC from another world, taking its ownership. - */ - void adoptNPC(NPC *e); - - /** - * Adopts a mob from another world, taking its ownership. - */ - void adoptMob(Mob *e); - - // adds a hole at the specified start and end x-coordinates - void addHole(unsigned int start,unsigned int end); - - // adds a hill that peaks at the given coordinate and is `width` HLINEs wide - void addHill(ivec2 peak, unsigned int width); - - // functions to add entities to the world - void addLight(vec2 xy, float radius, Color color); - - void addMerchant(float x, float y, bool housed); - - void addMob(Mob *m, vec2 coord); - - void addNPC(NPC *n); - - void addObject(std::string in, std::string pickupDialog, float x, float y); - - void addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int dur); - void addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int dur, unsigned char flags); - - void addStructure(Structures *s); - - Village *addVillage(std::string name, World *world); -}; - -/** - * The arena class - creates an arena. - * - * This world, when created, expects a pointer to a Mob. This mob will be - * transported to a temporary world with the player, and the Mob will be - * killed upon exiting the arena. - */ - -class Arena : public World { -private: - - // the mob that the player is fighting - Mob *mmob; - -public: - - // creates the arena with the world being left for it - Arena(void); - - // frees memory - ~Arena(void); - - // starts a new fight?? - void fight(World *leave, const Player *p, Mob *m); - - // attempts to exit the arena, returning what world the player should be in - WorldSwitchInfo exitArena(Player *p); + bool save(const std::string& file); + void load(const std::string& file); }; /** @@ -495,13 +204,4 @@ World *loadWorldFromXMLNoTakeover(std::string path); */ World *loadWorldFromPtr(World *ptr); -/** - * Casts a normal world to an indoor world, to access IndoorWorld-exclusive - * elements. - */ -constexpr IndoorWorld *Indoorp(World *w) -{ - return (IndoorWorld *)w; -} - #endif // WORLD_H -- cgit v1.2.3