Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Turned the src/common/global files to use four spaces instead of tabs.

  • Loading branch information...
commit 625836ed9eabc89b4e85ee363ff76a2ce3062055 1 parent 8117972
Yohann Ferreira authored
View
2,403 src/common/global/global.cpp
1,202 additions, 1,201 deletions not shown
View
1,424 src/common/global/global.h
@@ -37,10 +37,11 @@
#include "modes/map/map_utils.h"
//! \brief All calls to global code are wrapped inside this namespace.
-namespace hoa_global {
+namespace hoa_global
+{
//! \brief The singleton pointer responsible for the management of global game data.
-extern GameGlobal* GlobalManager;
+extern GameGlobal *GlobalManager;
//! \brief Determines whether the code in the hoa_global namespace should print debug statements or not.
extern bool GLOBAL_DEBUG;
@@ -69,65 +70,71 @@ extern bool GLOBAL_DEBUG;
*** objects and provides methods to allow the creation, modification, and
*** retrieval of these objects.
*** ***************************************************************************/
-class GlobalEventGroup {
+class GlobalEventGroup
+{
public:
- //! \param group_name The name of the group to create (this can not be changed)
- GlobalEventGroup(const std::string& group_name) :
- _group_name(group_name) {}
-
- ~GlobalEventGroup() {}
-
- /** \brief Queries whether or not an event of a given name exists in the group
- *** \param event_name The name of the event to check for
- *** \return True if the event name was found in the group, false if it was not
- **/
- bool DoesEventExist(const std::string& event_name)
- { if (_events.find(event_name) != _events.end()) return true; else return false; }
-
- /** \brief Adds a new event to the group
- *** \param event_name The name of the event to add
- *** \param event_value The value of the event to add (default value is zero)
- *** \note If an event by the given name already exists, a warning will be printed and no addition
- *** or modification of any kind will take place
- **/
- void AddNewEvent(const std::string& event_name, int32 event_value = 0);
-
- /** \brief Retrieves the value of a specific event in the group
- *** \param event_name The name of the event to retrieve
- *** \return The value of the event, or GLOBAL_BAD_EVENT if there is no event corresponding to
- *** the requested event named
- **/
- int32 GetEvent(const std::string& event_name);
-
- /** \brief Sets the value for an existing event
- *** \param event_name The name of the event whose value should be changed
- *** \param event_value The value to set for the event
- *** \note If the event by the given name is not found, the event group will be created.
- **/
- void SetEvent(const std::string& event_name, int32 event_value);
-
- //! \brief Returns the number of events currently stored within the group
- uint32 GetNumberEvents() const
- { return _events.size(); }
-
- //! \brief Returns a copy of the name of this group
- std::string GetGroupName() const
- { return _group_name; }
-
- //! \brief Returns an immutable reference to the private _events container
- const std::map<std::string, int32>& GetEvents() const
- { return _events; }
+ //! \param group_name The name of the group to create (this can not be changed)
+ GlobalEventGroup(const std::string &group_name) :
+ _group_name(group_name) {}
+
+ ~GlobalEventGroup() {}
+
+ /** \brief Queries whether or not an event of a given name exists in the group
+ *** \param event_name The name of the event to check for
+ *** \return True if the event name was found in the group, false if it was not
+ **/
+ bool DoesEventExist(const std::string &event_name) {
+ if(_events.find(event_name) != _events.end()) return true;
+ else return false;
+ }
+
+ /** \brief Adds a new event to the group
+ *** \param event_name The name of the event to add
+ *** \param event_value The value of the event to add (default value is zero)
+ *** \note If an event by the given name already exists, a warning will be printed and no addition
+ *** or modification of any kind will take place
+ **/
+ void AddNewEvent(const std::string &event_name, int32 event_value = 0);
+
+ /** \brief Retrieves the value of a specific event in the group
+ *** \param event_name The name of the event to retrieve
+ *** \return The value of the event, or GLOBAL_BAD_EVENT if there is no event corresponding to
+ *** the requested event named
+ **/
+ int32 GetEvent(const std::string &event_name);
+
+ /** \brief Sets the value for an existing event
+ *** \param event_name The name of the event whose value should be changed
+ *** \param event_value The value to set for the event
+ *** \note If the event by the given name is not found, the event group will be created.
+ **/
+ void SetEvent(const std::string &event_name, int32 event_value);
+
+ //! \brief Returns the number of events currently stored within the group
+ uint32 GetNumberEvents() const {
+ return _events.size();
+ }
+
+ //! \brief Returns a copy of the name of this group
+ std::string GetGroupName() const {
+ return _group_name;
+ }
+
+ //! \brief Returns an immutable reference to the private _events container
+ const std::map<std::string, int32>& GetEvents() const {
+ return _events;
+ }
private:
- //! \brief The name given to this group of events
- std::string _group_name;
-
- /** \brief The map container for all the events in the group
- *** The string is the name of the event, which is unique within the group. The integer value
- *** represents the event's state and can take on multiple meanings depending on the context
- *** of this specific event.
- **/
- std::map<std::string, int32> _events;
+ //! \brief The name given to this group of events
+ std::string _group_name;
+
+ /** \brief The map container for all the events in the group
+ *** The string is the name of the event, which is unique within the group. The integer value
+ *** represents the event's state and can take on multiple meanings depending on the context
+ *** of this specific event.
+ **/
+ std::map<std::string, int32> _events;
}; // class GlobalEventGroup
@@ -144,662 +151,715 @@ class GlobalEventGroup {
*** manager class. There can only be one game instance that the player is playing
*** at any given time.
*** ***************************************************************************/
-class GameGlobal : public hoa_utils::Singleton<GameGlobal> {
- friend class hoa_utils::Singleton<GameGlobal>;
+class GameGlobal : public hoa_utils::Singleton<GameGlobal>
+{
+ friend class hoa_utils::Singleton<GameGlobal>;
public:
- ~GameGlobal();
-
- bool SingletonInitialize();
-
- /** \brief Deletes all data stored within the GameGlobal class object
- *** This function is meant to be called when the user quits the current game instance
- *** and returns to the boot screen. It will delete all characters, inventory, and other
- *** data relevant to the current game.
- **/
- void ClearAllData();
-
- //! \name Character Functions
- //@{
- /** \brief Adds a new character to the party with its initial settings
- *** \param id The ID number of the character to add to the party.
- ***
- *** Only use this function for when you wish the character to be constructed using
- *** its initial stats, equipment, and skills. Otherwise, you should construct the
- *** GlobalCharacter externally and invoke the other AddCharacter function with a
- *** pointer to it.
- ***
- *** \note If the number of characters is less than four when this function is called,
- *** the new character will automatically be added to the active party.
- **/
- void AddCharacter(uint32 id);
-
- /** \brief Adds a new pre-initialized character to the party
- *** \param ch A pointer to the initialized GlobalCharacter object to add
- ***
- *** The GlobalCharacter argument must be created -and- properly initalized (stats
- *** members all set, equipment added, skills added) prior to making this call.
- *** Adding an uninitialized character will likely result in a segmentation fault
- *** or other run-time error somewhere down the road.
- ***
- *** \note If the number of characters is less than four when this function is called,
- *** the new character will automatically be added to the active party.
- **/
- void AddCharacter(GlobalCharacter* ch);
-
- /** \brief Removes a character from the party.
- *** \param id The ID number of the character to remove from the party.
- *** \param erase Tells whether the character should be completely remove
- or just from the active party.
- **/
- void RemoveCharacter(uint32 id, bool erase = false);
-
- /** \brief Returns a pointer to a character currently in the party.
- *** \param id The ID number of the character to retrieve.
- *** \return A pointer to the character, or NULL if the character was not found.
- ***/
- GlobalCharacter* GetCharacter(uint32 id);
-
- /** \brief Swaps the location of two character in the party by their indeces
- *** \param first_index The index of the first character to swap
- *** \param second_index The index of the second character to swap
- **/
- void SwapCharactersByIndex(uint32 first_index, uint32 second_index);
-
- /** \brief Checks whether or not a character is in the party
- *** \param id The id of the character to check for
- *** \return True if the character was found to be in the party, or false if they were not found.
- **/
- bool IsCharacterInParty(uint32 id)
- { if (_characters.find(id) != _characters.end()) return true; else return false; }
- //@}
-
- //! \name Inventory Methods
- //@{
- /** \brief Adds a new object to the inventory
- *** \param obj_id The identifier value of the object to add
- *** \param obj_count The number of instances of the object to add (default == 1)
- *** If the item already exists in the inventory, then instead the GlobalObject#_count member is used to
- *** increment the count of the stored item.
- **/
- void AddToInventory(uint32 obj_id, uint32 obj_count = 1);
-
- /** \brief Adds a new object to the inventory
- *** \param object A pointer to the pre-created GlobalObject-type class to add
- ***
- *** Once you call this function, GameGlobal assumes it is now responsible for memory management of this
- *** object. Therefore, you should <b>never</b> attempt to reference the argument pointer after it is
- *** passed to this function, because it may very well now point to an invalid location in memory. You
- *** should also never use this function to pass a pointer to an object that was <b>not</b> created with
- *** the new operator, because it is guaranteed that sooner or later GameGlobal will invoke delete on
- *** this object.
- **/
- void AddToInventory(GlobalObject* object);
-
- /** \brief Removes an object from the inventory
- *** \param obj_id The identifier value of the object to remove
- *** \note If the object is not in the inventory, the function will do nothing.
- ***
- *** This function removes the item regardless of what the GlobalObject#_count member is set to.
- *** If you want to remove only a certain number of instances of the object, use the function
- *** GameGlobal#DecrementObjectCount.
- **/
- void RemoveFromInventory(uint32 obj_id);
-
- /** \brief Retries a single copy of an object from the inventory
- *** \param obj_id The identifier value of the item to remove
- *** \param all_counts If set to true, all counts of the object will be removed from the inventory (default value == false)
- *** \return A newly instantiated copy of the object, or NULL if the object was not found in the inventory
- ***
- *** If all_counts is false, the returned object will have a count of one and the count of the object inside the inventory
- *** will be decremented by one. If all_counts is ture, the returned object will have the same count as was previously in
- *** the inventory, and the object will be removed from the inventory alltogether. Note that the pointer returned will need
- *** to be deleted by the user code, unless the object is re-added to the inventory or equipped on a character.
- **/
- GlobalObject* RetrieveFromInventory(uint32 obj_id, bool all_counts = false);
-
- /** \brief Increments the number (count) of an object in the inventory
- *** \param item_id The integer identifier of the item that will have its count incremented
- *** \param count The amount to increase the object's count by (default value == 1)
- ***
- *** If the item does not exist in the inventory, this function will do nothing. If the count parameter
- *** is set to zero, no change will take place.
- ***
- *** \note The callee can not assume that the function call succeeded, but rather has to check this themselves.
- **/
- void IncrementObjectCount(uint32 obj_id, uint32 obj_count = 1);
-
- /** \brief Decrements the number (count) of an object in the inventory
- *** \param item_id The integer identifier of the item that will have its count decremented
- *** \param count The amount to decrease the object's count by (default value == 1)
- ***
- *** If the item does not exist in the inventory, this function will do nothing. If the count parameter
- *** is set to zero, no change will take place. If the count parameter is greater than or equal to the
- *** current count of the object, the object will be completely removed from the inventory.
- ***
- *** \note The callee can not assume that the function call succeeded, but rather has to check this themselves.
- **/
- void DecrementObjectCount(uint32 obj_id, uint32 obj_count = 1);
-
- /** \brief Checks whether or a given object is currently stored in the inventory
- *** \param id The id of the object (item, weapon, armor, etc.) to check for
- *** \return True if the object was found in the inventor, or false if it was not found
- **/
- bool IsObjectInInventory(uint32 id)
- { return (_inventory.find(id) != _inventory.end()); }
-
- /** \brief Gives how many of a given item is in the inventory
- *** \param id The id of the object (item, weapon, armor, etc.) to check for
- *** \return The number of the object found in the inventory
- **/
- uint32 HowManyObjectsInInventory(uint32 id)
- { return (_inventory.find(id) != _inventory.end()) ? _inventory.at(id)->GetCount() : 0; }
- //@}
-
- //! \name Event Group Methods
- //@{
- /** \brief Queries whether or not an event group of a given name exists
- *** \param group_name The name of the event group to check for
- *** \return True if the event group name was found, false if it was not
- **/
- bool DoesEventGroupExist(const std::string& group_name) const
- { return (_event_groups.find(group_name) != _event_groups.end()); }
-
- /** \brief Determines if an event of a given name exists within a given group
- *** \param group_name The name of the event group where the event to check is contained
- *** \param event_name The name of the event to check for
- *** \return True if the event was found, or false if the event name or group name was not found
- **/
- bool DoesEventExist(const std::string& group_name, const std::string& event_name) const;
-
- /** \brief Adds a new event group for the class to manage
- *** \param group_name The name of the new event group to add
- *** \note If an event group by the given name already exists, the function will abort
- *** and not add the new event group. Otherwise, this class will automatically construct
- *** a new event group of the given name and place it in its map of event groups.
- **/
- void AddNewEventGroup(const std::string& group_name);
-
- /** \brief Returns a pointer to an event group of the specified name
- *** \param group_name The name of the event group to retreive
- *** \return A pointer to the GlobalEventGroup that represents the event group, or NULL if no event group
- *** of the specifed name was found
- ***
- *** You can use this method to invoke the public methods of the GlobalEventGroup class. For example, if
- *** we wanted to add a new event "cave_collapse" with a value of 1 to the group event "cave_map", we
- *** would do the following: GlobalManager->GetEventGroup("cave_map")->AddNewEvent("cave_collapse", 1);
- *** Be careful, however, because since this function returns NULL if the event group was not found, the
- *** example code above would produce a segmentation fault if no event group by the name "cave_map" existed.
- **/
- GlobalEventGroup* GetEventGroup(const std::string& group_name) const;
-
- /** \brief Returns the value of an event inside of a specified group
- *** \param group_name The name of the event group where the event is contained
- *** \param event_name The name of the event whose value should be retrieved
- *** \return The value of the requested event, or GLOBAL_BAD_EVENT if the event was not found
- **/
- int32 GetEventValue(const std::string& group_name, const std::string& event_name) const;
-
- /** \brief Set the value of an event inside of a specified group
- *** \param group_name The name of the event group where the event is contained
- *** \param event_name The name of the event whose value should be retrieved
- *** \return The event value.
- *** \note Events and event groups will be created when necessary.
- **/
- void SetEventValue(const std::string& group_name, const std::string& event_name, int32 event_value);
-
- //! \brief Returns the number of event groups stored in the class
- uint32 GetNumberEventGroups() const
- { return _event_groups.size(); }
-
- /** \brief Returns the number of events for a specified group name
- *** \param group_name The name of the event group to retrieve the number of events for
- *** \return The number of events in the group, or zero if no such group name existed
- **/
- uint32 GetNumberEvents(const std::string& group_name) const;
- //@}
-
- //! \note The overflow condition is not checked here: we just assume it will never occur
- void AddDrunes(uint32 amount)
- { _drunes += amount; }
-
- //! \note The amount is only subtracted if the current funds is equal to or exceeds the amount to subtract
- void SubtractDrunes(uint32 amount)
- { if (_drunes >= amount) _drunes -= amount; }
-
- /** \brief Calculates the average experience level of members in the active party
- *** \return The average (integer) experience level of all members in the active party
- *** This is used for determining the level of growth for enemies in battle.
- **/
- uint32 AverageActivePartyExperienceLevel() const
- { return static_cast<uint32>(_active_party.AverageExperienceLevel()); }
-
- /** \brief Sets the name and graphic for the current location
- *** \param map_filename The string that contains the name of the current map.
- *** \param map_image_filename The filename of the image that presents this map
- *** \param map_hud_name The UTF16 map name shown at map intro time.
- **/
- void SetMap(const std::string& map_filename, const std::string& map_image_filename,
- const hoa_utils::ustring& map_hud_name);
-
- /** \brief Sets the active Map filename (for game saves)
- *** \param location_name The string that contains the name of the current map
- **/
- void SetMapFilename(const std::string& map_filename)
- { _map_filename = map_filename; }
-
- /** Set up the previous map point the character is coming from.
- *** It is used to make the new map aware about where the character should appear.
- ***
- *** \param previous_location The string telling the location the character is coming from.
- **/
- void SetPreviousLocation(const std::string& previous_location)
- { _previous_location = previous_location; }
-
- const std::string& GetPreviousLocation() const
- { return _previous_location; }
-
- /** Get the previous map hud name shown at intro time.
- *** Used to know whether the new hud name is the same in the map mode.
- **/
- bool ShouldDisplayHudNameOnMapIntro() const
- { return !_same_map_hud_name_as_previous; }
-
- //! \brief Executes function NewGame() from global script
- void NewGame();
-
- /** \brief Saves all global data to a saved game file
- *** \param filename The filename of the saved game file where to write the data to
- *** \param slot_id The game slot id used for the save menu.
- *** \param positions When used in a save point, the save map tile positions are given there.
- *** \return True if the game was successfully saved, false if it was not
- **/
- bool SaveGame(const std::string& filename, uint32 slot_id, uint32 x_position = 0, uint32 y_position = 0);
-
- /** \brief Loads all global data from a saved game file
- *** \param filename The filename of the saved game file where to read the data from
- *** \param slot_id The save slot the file correspond to. Used to set the correct cursor position
- *** when further saving.
- *** \return True if the game was successfully loaded, false if it was not
- **/
- bool LoadGame(const std::string& filename, uint32 slot_id);
-
- uint32 GetGameSlotId() const
- { return _game_slot_id; }
-
- //! \name Class Member Access Functions
- //@{
- void SetDrunes(uint32 amount)
- { _drunes = amount; }
+ ~GameGlobal();
+
+ bool SingletonInitialize();
+
+ /** \brief Deletes all data stored within the GameGlobal class object
+ *** This function is meant to be called when the user quits the current game instance
+ *** and returns to the boot screen. It will delete all characters, inventory, and other
+ *** data relevant to the current game.
+ **/
+ void ClearAllData();
+
+ //! \name Character Functions
+ //@{
+ /** \brief Adds a new character to the party with its initial settings
+ *** \param id The ID number of the character to add to the party.
+ ***
+ *** Only use this function for when you wish the character to be constructed using
+ *** its initial stats, equipment, and skills. Otherwise, you should construct the
+ *** GlobalCharacter externally and invoke the other AddCharacter function with a
+ *** pointer to it.
+ ***
+ *** \note If the number of characters is less than four when this function is called,
+ *** the new character will automatically be added to the active party.
+ **/
+ void AddCharacter(uint32 id);
+
+ /** \brief Adds a new pre-initialized character to the party
+ *** \param ch A pointer to the initialized GlobalCharacter object to add
+ ***
+ *** The GlobalCharacter argument must be created -and- properly initalized (stats
+ *** members all set, equipment added, skills added) prior to making this call.
+ *** Adding an uninitialized character will likely result in a segmentation fault
+ *** or other run-time error somewhere down the road.
+ ***
+ *** \note If the number of characters is less than four when this function is called,
+ *** the new character will automatically be added to the active party.
+ **/
+ void AddCharacter(GlobalCharacter *ch);
+
+ /** \brief Removes a character from the party.
+ *** \param id The ID number of the character to remove from the party.
+ *** \param erase Tells whether the character should be completely remove
+ or just from the active party.
+ **/
+ void RemoveCharacter(uint32 id, bool erase = false);
+
+ /** \brief Returns a pointer to a character currently in the party.
+ *** \param id The ID number of the character to retrieve.
+ *** \return A pointer to the character, or NULL if the character was not found.
+ ***/
+ GlobalCharacter *GetCharacter(uint32 id);
+
+ /** \brief Swaps the location of two character in the party by their indeces
+ *** \param first_index The index of the first character to swap
+ *** \param second_index The index of the second character to swap
+ **/
+ void SwapCharactersByIndex(uint32 first_index, uint32 second_index);
+
+ /** \brief Checks whether or not a character is in the party
+ *** \param id The id of the character to check for
+ *** \return True if the character was found to be in the party, or false if they were not found.
+ **/
+ bool IsCharacterInParty(uint32 id) {
+ if(_characters.find(id) != _characters.end()) return true;
+ else return false;
+ }
+ //@}
+
+ //! \name Inventory Methods
+ //@{
+ /** \brief Adds a new object to the inventory
+ *** \param obj_id The identifier value of the object to add
+ *** \param obj_count The number of instances of the object to add (default == 1)
+ *** If the item already exists in the inventory, then instead the GlobalObject#_count member is used to
+ *** increment the count of the stored item.
+ **/
+ void AddToInventory(uint32 obj_id, uint32 obj_count = 1);
+
+ /** \brief Adds a new object to the inventory
+ *** \param object A pointer to the pre-created GlobalObject-type class to add
+ ***
+ *** Once you call this function, GameGlobal assumes it is now responsible for memory management of this
+ *** object. Therefore, you should <b>never</b> attempt to reference the argument pointer after it is
+ *** passed to this function, because it may very well now point to an invalid location in memory. You
+ *** should also never use this function to pass a pointer to an object that was <b>not</b> created with
+ *** the new operator, because it is guaranteed that sooner or later GameGlobal will invoke delete on
+ *** this object.
+ **/
+ void AddToInventory(GlobalObject *object);
+
+ /** \brief Removes an object from the inventory
+ *** \param obj_id The identifier value of the object to remove
+ *** \note If the object is not in the inventory, the function will do nothing.
+ ***
+ *** This function removes the item regardless of what the GlobalObject#_count member is set to.
+ *** If you want to remove only a certain number of instances of the object, use the function
+ *** GameGlobal#DecrementObjectCount.
+ **/
+ void RemoveFromInventory(uint32 obj_id);
+
+ /** \brief Retries a single copy of an object from the inventory
+ *** \param obj_id The identifier value of the item to remove
+ *** \param all_counts If set to true, all counts of the object will be removed from the inventory (default value == false)
+ *** \return A newly instantiated copy of the object, or NULL if the object was not found in the inventory
+ ***
+ *** If all_counts is false, the returned object will have a count of one and the count of the object inside the inventory
+ *** will be decremented by one. If all_counts is ture, the returned object will have the same count as was previously in
+ *** the inventory, and the object will be removed from the inventory alltogether. Note that the pointer returned will need
+ *** to be deleted by the user code, unless the object is re-added to the inventory or equipped on a character.
+ **/
+ GlobalObject *RetrieveFromInventory(uint32 obj_id, bool all_counts = false);
+
+ /** \brief Increments the number (count) of an object in the inventory
+ *** \param item_id The integer identifier of the item that will have its count incremented
+ *** \param count The amount to increase the object's count by (default value == 1)
+ ***
+ *** If the item does not exist in the inventory, this function will do nothing. If the count parameter
+ *** is set to zero, no change will take place.
+ ***
+ *** \note The callee can not assume that the function call succeeded, but rather has to check this themselves.
+ **/
+ void IncrementObjectCount(uint32 obj_id, uint32 obj_count = 1);
+
+ /** \brief Decrements the number (count) of an object in the inventory
+ *** \param item_id The integer identifier of the item that will have its count decremented
+ *** \param count The amount to decrease the object's count by (default value == 1)
+ ***
+ *** If the item does not exist in the inventory, this function will do nothing. If the count parameter
+ *** is set to zero, no change will take place. If the count parameter is greater than or equal to the
+ *** current count of the object, the object will be completely removed from the inventory.
+ ***
+ *** \note The callee can not assume that the function call succeeded, but rather has to check this themselves.
+ **/
+ void DecrementObjectCount(uint32 obj_id, uint32 obj_count = 1);
+
+ /** \brief Checks whether or a given object is currently stored in the inventory
+ *** \param id The id of the object (item, weapon, armor, etc.) to check for
+ *** \return True if the object was found in the inventor, or false if it was not found
+ **/
+ bool IsObjectInInventory(uint32 id) {
+ return (_inventory.find(id) != _inventory.end());
+ }
+
+ /** \brief Gives how many of a given item is in the inventory
+ *** \param id The id of the object (item, weapon, armor, etc.) to check for
+ *** \return The number of the object found in the inventory
+ **/
+ uint32 HowManyObjectsInInventory(uint32 id) {
+ return (_inventory.find(id) != _inventory.end()) ? _inventory.at(id)->GetCount() : 0;
+ }
+ //@}
+
+ //! \name Event Group Methods
+ //@{
+ /** \brief Queries whether or not an event group of a given name exists
+ *** \param group_name The name of the event group to check for
+ *** \return True if the event group name was found, false if it was not
+ **/
+ bool DoesEventGroupExist(const std::string &group_name) const {
+ return (_event_groups.find(group_name) != _event_groups.end());
+ }
+
+ /** \brief Determines if an event of a given name exists within a given group
+ *** \param group_name The name of the event group where the event to check is contained
+ *** \param event_name The name of the event to check for
+ *** \return True if the event was found, or false if the event name or group name was not found
+ **/
+ bool DoesEventExist(const std::string &group_name, const std::string &event_name) const;
+
+ /** \brief Adds a new event group for the class to manage
+ *** \param group_name The name of the new event group to add
+ *** \note If an event group by the given name already exists, the function will abort
+ *** and not add the new event group. Otherwise, this class will automatically construct
+ *** a new event group of the given name and place it in its map of event groups.
+ **/
+ void AddNewEventGroup(const std::string &group_name);
+
+ /** \brief Returns a pointer to an event group of the specified name
+ *** \param group_name The name of the event group to retreive
+ *** \return A pointer to the GlobalEventGroup that represents the event group, or NULL if no event group
+ *** of the specifed name was found
+ ***
+ *** You can use this method to invoke the public methods of the GlobalEventGroup class. For example, if
+ *** we wanted to add a new event "cave_collapse" with a value of 1 to the group event "cave_map", we
+ *** would do the following: GlobalManager->GetEventGroup("cave_map")->AddNewEvent("cave_collapse", 1);
+ *** Be careful, however, because since this function returns NULL if the event group was not found, the
+ *** example code above would produce a segmentation fault if no event group by the name "cave_map" existed.
+ **/
+ GlobalEventGroup *GetEventGroup(const std::string &group_name) const;
+
+ /** \brief Returns the value of an event inside of a specified group
+ *** \param group_name The name of the event group where the event is contained
+ *** \param event_name The name of the event whose value should be retrieved
+ *** \return The value of the requested event, or GLOBAL_BAD_EVENT if the event was not found
+ **/
+ int32 GetEventValue(const std::string &group_name, const std::string &event_name) const;
+
+ /** \brief Set the value of an event inside of a specified group
+ *** \param group_name The name of the event group where the event is contained
+ *** \param event_name The name of the event whose value should be retrieved
+ *** \return The event value.
+ *** \note Events and event groups will be created when necessary.
+ **/
+ void SetEventValue(const std::string &group_name, const std::string &event_name, int32 event_value);
+
+ //! \brief Returns the number of event groups stored in the class
+ uint32 GetNumberEventGroups() const {
+ return _event_groups.size();
+ }
+
+ /** \brief Returns the number of events for a specified group name
+ *** \param group_name The name of the event group to retrieve the number of events for
+ *** \return The number of events in the group, or zero if no such group name existed
+ **/
+ uint32 GetNumberEvents(const std::string &group_name) const;
+ //@}
+
+ //! \note The overflow condition is not checked here: we just assume it will never occur
+ void AddDrunes(uint32 amount) {
+ _drunes += amount;
+ }
+
+ //! \note The amount is only subtracted if the current funds is equal to or exceeds the amount to subtract
+ void SubtractDrunes(uint32 amount) {
+ if(_drunes >= amount) _drunes -= amount;
+ }
+
+ /** \brief Calculates the average experience level of members in the active party
+ *** \return The average (integer) experience level of all members in the active party
+ *** This is used for determining the level of growth for enemies in battle.
+ **/
+ uint32 AverageActivePartyExperienceLevel() const {
+ return static_cast<uint32>(_active_party.AverageExperienceLevel());
+ }
+
+ /** \brief Sets the name and graphic for the current location
+ *** \param map_filename The string that contains the name of the current map.
+ *** \param map_image_filename The filename of the image that presents this map
+ *** \param map_hud_name The UTF16 map name shown at map intro time.
+ **/
+ void SetMap(const std::string &map_filename, const std::string &map_image_filename,
+ const hoa_utils::ustring &map_hud_name);
+
+ /** \brief Sets the active Map filename (for game saves)
+ *** \param location_name The string that contains the name of the current map
+ **/
+ void SetMapFilename(const std::string &map_filename) {
+ _map_filename = map_filename;
+ }
+
+ /** Set up the previous map point the character is coming from.
+ *** It is used to make the new map aware about where the character should appear.
+ ***
+ *** \param previous_location The string telling the location the character is coming from.
+ **/
+ void SetPreviousLocation(const std::string &previous_location) {
+ _previous_location = previous_location;
+ }
+
+ const std::string &GetPreviousLocation() const {
+ return _previous_location;
+ }
+
+ /** Get the previous map hud name shown at intro time.
+ *** Used to know whether the new hud name is the same in the map mode.
+ **/
+ bool ShouldDisplayHudNameOnMapIntro() const {
+ return !_same_map_hud_name_as_previous;
+ }
+
+ //! \brief Executes function NewGame() from global script
+ void NewGame();
+
+ /** \brief Saves all global data to a saved game file
+ *** \param filename The filename of the saved game file where to write the data to
+ *** \param slot_id The game slot id used for the save menu.
+ *** \param positions When used in a save point, the save map tile positions are given there.
+ *** \return True if the game was successfully saved, false if it was not
+ **/
+ bool SaveGame(const std::string &filename, uint32 slot_id, uint32 x_position = 0, uint32 y_position = 0);
+
+ /** \brief Loads all global data from a saved game file
+ *** \param filename The filename of the saved game file where to read the data from
+ *** \param slot_id The save slot the file correspond to. Used to set the correct cursor position
+ *** when further saving.
+ *** \return True if the game was successfully loaded, false if it was not
+ **/
+ bool LoadGame(const std::string &filename, uint32 slot_id);
+
+ uint32 GetGameSlotId() const {
+ return _game_slot_id;
+ }
+
+ //! \name Class Member Access Functions
+ //@{
+ void SetDrunes(uint32 amount) {
+ _drunes = amount;
+ }
+
+ void SetMaxExperienceLevel(uint32 level) {
+ _max_experience_level = level;
+ }
+
+ uint32 GetMaxExperienceLevel() const {
+ return _max_experience_level;
+ }
+
+ uint32 GetDrunes() const {
+ return _drunes;
+ }
+
+ const std::string &GetMapFilename() {
+ return _map_filename;
+ }
+
+ uint32 GetSaveLocationX() {
+ return _x_save_map_position;
+ }
+
+ uint32 GetSaveLocationY() {
+ return _y_save_map_position;
+ }
+
+ /** \brief Unset the save location once retreived at load time.
+ *** It should be done in the map code once the location has been set up.
+ **/
+ void UnsetSaveLocation() {
+ _x_save_map_position = 0;
+ _y_save_map_position = 0;
+ }
+
+ hoa_video::StillImage &GetMapImage() {
+ return _map_image;
+ }
+
+ std::vector<GlobalCharacter *>* GetOrderedCharacters() {
+ return &_ordered_characters;
+ }
+
+ GlobalParty *GetActiveParty() {
+ return &_active_party;
+ }
+
+ std::map<uint32, GlobalObject *>* GetInventory() {
+ return &_inventory;
+ }
+
+ std::vector<GlobalItem *>* GetInventoryItems() {
+ return &_inventory_items;
+ }
+
+ std::vector<GlobalWeapon *>* GetInventoryWeapons() {
+ return &_inventory_weapons;
+ }
+
+ std::vector<GlobalArmor *>* GetInventoryHeadArmor() {
+ return &_inventory_head_armor;
+ }
+
+ std::vector<GlobalArmor *>* GetInventoryTorsoArmor() {
+ return &_inventory_torso_armor;
+ }
+
+ std::vector<GlobalArmor *>* GetInventoryArmArmor() {
+ return &_inventory_arm_armor;
+ }
+
+ std::vector<GlobalArmor *>* GetInventoryLegArmor() {
+ return &_inventory_leg_armor;
+ }
+
+ std::vector<GlobalShard *>* GetInventoryShards() {
+ return &_inventory_shards;
+ }
+
+ std::vector<GlobalKeyItem *>* GetInventoryKeyItems() {
+ return &_inventory_key_items;
+ }
+
+ hoa_script::ReadScriptDescriptor &GetItemsScript() {
+ return _items_script;
+ }
+
+ hoa_script::ReadScriptDescriptor &GetKeyItemsScript() {
+ return _key_items_script;
+ }
+
+ hoa_script::ReadScriptDescriptor &GetWeaponsScript() {
+ return _weapons_script;
+ }
+
+ hoa_script::ReadScriptDescriptor &GetHeadArmorScript() {
+ return _head_armor_script;
+ }
+
+ hoa_script::ReadScriptDescriptor &GetTorsoArmorScript() {
+ return _torso_armor_script;
+ }
- void SetMaxExperienceLevel(uint32 level)
- { _max_experience_level = level; }
+ hoa_script::ReadScriptDescriptor &GetArmArmorScript() {
+ return _arm_armor_script;
+ }
- uint32 GetMaxExperienceLevel() const
- { return _max_experience_level; }
+ hoa_script::ReadScriptDescriptor &GetLegArmorScript() {
+ return _leg_armor_script;
+ }
- uint32 GetDrunes() const
- { return _drunes; }
+ hoa_script::ReadScriptDescriptor &GetAttackSkillsScript() {
+ return _attack_skills_script;
+ }
- const std::string& GetMapFilename()
- { return _map_filename; }
+ hoa_script::ReadScriptDescriptor &GetDefendSkillsScript() {
+ return _defend_skills_script;
+ }
- uint32 GetSaveLocationX()
- { return _x_save_map_position; }
+ hoa_script::ReadScriptDescriptor &GetSupportSkillsScript() {
+ return _support_skills_script;
+ }
- uint32 GetSaveLocationY()
- { return _y_save_map_position; }
+ hoa_script::ReadScriptDescriptor &GetStatusEffectsScript() {
+ return _status_effects_script;
+ }
- /** \brief Unset the save location once retreived at load time.
- *** It should be done in the map code once the location has been set up.
- **/
- void UnsetSaveLocation()
- { _x_save_map_position = 0; _y_save_map_position = 0; }
+ hoa_script::ReadScriptDescriptor &GetMapSpriteScript() {
+ return _map_sprites_script;
+ }
+ //@}
- hoa_video::StillImage& GetMapImage()
- { return _map_image; }
+ //! \brief loads the emotes used for character feelings expression in the given lua file.
+ void LoadEmotes(const std::string &emotes_filename);
- std::vector<GlobalCharacter*>* GetOrderedCharacters()
- { return &_ordered_characters; }
+ //! \brief Set up the offsets for the given emote animation and sprite direction.
+ void GetEmoteOffset(float &x, float &y, const std::string &emote_id, hoa_map::private_map::ANIM_DIRECTIONS dir);
- GlobalParty* GetActiveParty()
- { return &_active_party; }
+ //! \brief Tells whether an emote id exists and is valid
+ bool DoesEmoteExist(const std::string &emote_id) {
+ return (_emotes.count(emote_id));
+ }
- std::map<uint32, GlobalObject*>* GetInventory()
- { return &_inventory; }
-
- std::vector<GlobalItem*>* GetInventoryItems()
- { return &_inventory_items; }
-
- std::vector<GlobalWeapon*>* GetInventoryWeapons()
- { return &_inventory_weapons; }
-
- std::vector<GlobalArmor*>* GetInventoryHeadArmor()
- { return &_inventory_head_armor; }
-
- std::vector<GlobalArmor*>* GetInventoryTorsoArmor()
- { return &_inventory_torso_armor; }
-
- std::vector<GlobalArmor*>* GetInventoryArmArmor()
- { return &_inventory_arm_armor; }
-
- std::vector<GlobalArmor*>* GetInventoryLegArmor()
- { return &_inventory_leg_armor; }
-
- std::vector<GlobalShard*>* GetInventoryShards()
- { return &_inventory_shards; }
-
- std::vector<GlobalKeyItem*>* GetInventoryKeyItems()
- { return &_inventory_key_items; }
-
- hoa_script::ReadScriptDescriptor& GetItemsScript()
- { return _items_script; }
-
- hoa_script::ReadScriptDescriptor& GetKeyItemsScript()
- { return _key_items_script; }
-
- hoa_script::ReadScriptDescriptor& GetWeaponsScript()
- { return _weapons_script; }
-
- hoa_script::ReadScriptDescriptor& GetHeadArmorScript()
- { return _head_armor_script; }
-
- hoa_script::ReadScriptDescriptor& GetTorsoArmorScript()
- { return _torso_armor_script; }
-
- hoa_script::ReadScriptDescriptor& GetArmArmorScript()
- { return _arm_armor_script; }
-
- hoa_script::ReadScriptDescriptor& GetLegArmorScript()
- { return _leg_armor_script; }
-
- hoa_script::ReadScriptDescriptor& GetAttackSkillsScript()
- { return _attack_skills_script; }
-
- hoa_script::ReadScriptDescriptor& GetDefendSkillsScript()
- { return _defend_skills_script; }
-
- hoa_script::ReadScriptDescriptor& GetSupportSkillsScript()
- { return _support_skills_script; }
-
- hoa_script::ReadScriptDescriptor& GetStatusEffectsScript()
- { return _status_effects_script; }
-
- hoa_script::ReadScriptDescriptor& GetMapSpriteScript()
- { return _map_sprites_script; }
- //@}
-
- //! \brief loads the emotes used for character feelings expression in the given lua file.
- void LoadEmotes(const std::string& emotes_filename);
-
- //! \brief Set up the offsets for the given emote animation and sprite direction.
- void GetEmoteOffset(float& x, float& y, const std::string& emote_id, hoa_map::private_map::ANIM_DIRECTIONS dir);
-
- //! \brief Tells whether an emote id exists and is valid
- bool DoesEmoteExist(const std::string& emote_id)
- { return (_emotes.count(emote_id)); }
-
- //! \brief Get a pointer reference to the given emote animation. Don't delete it!
- hoa_video::AnimatedImage* GetEmoteAnimation(const std::string& emote_id)
- { if (_emotes.find(emote_id) != _emotes.end()) return &_emotes.at(emote_id); else return 0; }
+ //! \brief Get a pointer reference to the given emote animation. Don't delete it!
+ hoa_video::AnimatedImage *GetEmoteAnimation(const std::string &emote_id) {
+ if(_emotes.find(emote_id) != _emotes.end()) return &_emotes.at(emote_id);
+ else return 0;
+ }
private:
- GameGlobal();
-
- //! \brief The slot id the game was loaded from/saved to, or 0 if none.
- uint32 _game_slot_id;
-
- //! \brief The amount of financial resources (drunes) that the party currently has
- uint32 _drunes;
-
- /** \brief Set the max level that can be reached by a character
- *** This equals 100 by default, @see Set/GetMaxExperienceLevel()
- **/
- uint32 _max_experience_level;
-
- //! \brief The map filename the current party is on.
- std::string _map_filename;
-
- //! \brief last save point map tile location.
- uint32 _x_save_map_position, _y_save_map_position;
+ GameGlobal();
+
+ //! \brief The slot id the game was loaded from/saved to, or 0 if none.
+ uint32 _game_slot_id;
+
+ //! \brief The amount of financial resources (drunes) that the party currently has
+ uint32 _drunes;
+
+ /** \brief Set the max level that can be reached by a character
+ *** This equals 100 by default, @see Set/GetMaxExperienceLevel()
+ **/
+ uint32 _max_experience_level;
+
+ //! \brief The map filename the current party is on.
+ std::string _map_filename;
+
+ //! \brief last save point map tile location.
+ uint32 _x_save_map_position, _y_save_map_position;
- //! \brief The graphical image which represents the current location
- hoa_video::StillImage _map_image;
+ //! \brief The graphical image which represents the current location
+ hoa_video::StillImage _map_image;
- //! \brief The map location the character is com from. Used to make the new map know where to make the character appear.
- std::string _previous_location;
-
- /** \brief Stores the previous and current map names appearing on screen at intro time.
- *** This is used to know whether we have to display it, as we won't when it's the same location name than the previous map.
- **/
- hoa_utils::ustring _previous_map_hud_name;
- hoa_utils::ustring _map_hud_name;
- bool _same_map_hud_name_as_previous;
-
- /** \brief A map containing all characters that the player has discovered
- *** This map contains all characters that the player has met with, regardless of whether or not they are in the active party.
- *** The map key is the character's unique ID number.
- **/
- std::map<uint32, GlobalCharacter*> _characters;
+ //! \brief The map location the character is com from. Used to make the new map know where to make the character appear.
+ std::string _previous_location;
+
+ /** \brief Stores the previous and current map names appearing on screen at intro time.
+ *** This is used to know whether we have to display it, as we won't when it's the same location name than the previous map.
+ **/
+ hoa_utils::ustring _previous_map_hud_name;
+ hoa_utils::ustring _map_hud_name;
+ bool _same_map_hud_name_as_previous;
+
+ /** \brief A map containing all characters that the player has discovered
+ *** This map contains all characters that the player has met with, regardless of whether or not they are in the active party.
+ *** The map key is the character's unique ID number.
+ **/
+ std::map<uint32, GlobalCharacter *> _characters;
- /** \brief A vector whose purpose is to maintain the order of characters
- *** The first four characters in this vector are in the active party; the rest are in reserve.
- **/
- std::vector<GlobalCharacter*> _ordered_characters;
-
- /** \brief The active party of characters
- *** The active party contains the group of characters that will fight when a battle begins.
- *** This party can be up to four characters, and should always contain at least one character.
- **/
- GlobalParty _active_party;
-
- /** \brief Retains a list of all of the objects currently stored in the player's inventory
- *** This map is used to quickly check if an item is in the inventory or not. The key to the map is the object's
- *** identification number. When an object is added to the inventory, if it already exists then the object counter
- *** is simply increased instead of adding an entire new class object. When the object count becomes zero, the object
- *** is removed from the inventory. Duplicates of all objects are retained in the various inventory containers below.
- **/
- std::map<uint32, GlobalObject*> _inventory;
-
- /** \brief Inventory containers
- *** These vectors contain the inventory of the entire party. The vectors are sorted according to the player's personal preferences.
- *** When a new object is added to the inventory, by default it will be placed at the end of the vector.
- **/
- //@{
- std::vector<GlobalItem*> _inventory_items;
- std::vector<GlobalWeapon*> _inventory_weapons;
- std::vector<GlobalArmor*> _inventory_head_armor;
- std::vector<GlobalArmor*> _inventory_torso_armor;
- std::vector<GlobalArmor*> _inventory_arm_armor;
- std::vector<GlobalArmor*> _inventory_leg_armor;
- std::vector<GlobalShard*> _inventory_shards;
- std::vector<GlobalKeyItem*> _inventory_key_items;
- //@}
-
- //! \name Global data and function script files
- //@{
- //! \brief Contains character ID definitions and a number of useful functions
- hoa_script::ReadScriptDescriptor _global_script;
-
- //! \brief Contains data definitions for all items
- hoa_script::ReadScriptDescriptor _items_script;
-
- //! \brief Contains data definitions for all key items
- hoa_script::ReadScriptDescriptor _key_items_script;
-
- //! \brief Contains data definitions for all weapons
- hoa_script::ReadScriptDescriptor _weapons_script;
-
- //! \brief Contains data definitions for all armor that are equipped on the head
- hoa_script::ReadScriptDescriptor _head_armor_script;
-
- //! \brief Contains data definitions for all armor that are equipped on the torso
- hoa_script::ReadScriptDescriptor _torso_armor_script;
-
- //! \brief Contains data definitions for all armor that are equipped on the arms
- hoa_script::ReadScriptDescriptor _arm_armor_script;
-
- //! \brief Contains data definitions for all armor that are equipped on the legs
- hoa_script::ReadScriptDescriptor _leg_armor_script;
-
- //! \brief Contains data definitions for all shards
- // hoa_script::ReadScriptDescriptor _shard_script;
-
- //! \brief Contains data definitions for all key items
- // hoa_script::ReadScriptDescriptor _key_items_script;
-
- //! \brief Contains data and functional definitions for all attack skills
- hoa_script::ReadScriptDescriptor _attack_skills_script;
-
- //! \brief Contains data and functional definitions for all defense skills
- hoa_script::ReadScriptDescriptor _defend_skills_script;
-
- //! \brief Contains data and functional definitions for all support skills
- hoa_script::ReadScriptDescriptor _support_skills_script;
-
- //! \brief Contains functional definitions for all status effects
- hoa_script::ReadScriptDescriptor _status_effects_script;
-
- //! \brief Contains data and functional definitions for sprites seen in game maps
- hoa_script::ReadScriptDescriptor _map_sprites_script;
-
- //! \brief Contains data and functional definitions for map objects seen in game maps
- hoa_script::ReadScriptDescriptor _map_objects_script;
-
- //! \brief Contains data and functional definitions for map treasures seen in game maps
- hoa_script::ReadScriptDescriptor _map_treasures_script;
- //@}
-
- /** \brief The container which stores all of the groups of events that have occured in the game
- *** The name of each GlobalEventGroup object serves as its key in this map data structure.
- **/
- std::map<std::string, GlobalEventGroup*> _event_groups;
-
- //! \brief A map containing all the emote animations
- std::map<std::string, hoa_video::AnimatedImage> _emotes;
- //! \brief The map continaing the four sprite direction offsets (x and y value).
- std::map<std::string, std::vector<std::pair<float, float> > > _emotes_offsets;
-
- // ----- Private methods
-
- /** \brief A helper template function that finds and removes an object from the inventory
- *** \param obj_id The ID of the object to remove from the inventory
- *** \param inv The vector container of the appropriate inventory type
- *** \return True if the object was successfully removed, or false if it was not
- **/
- template <class T> bool _RemoveFromInventory(uint32 obj_id, std::vector<T*>& inv);
-
- /** \brief A helper template function that finds and returns a copy of an object from the inventory
- *** \param obj_id The ID of the object to remove from the inventory
- *** \param inv The vector container of the appropriate inventory type
- *** \param all_counts If false the object's count is decremented by one from the inventory, otherwise all counts are removed completely
- *** \return A pointer to the newly created copy of the object, or NULL if the object could not be found
- **/
- template <class T> T* _RetrieveFromInventory(uint32 obj_id, std::vector<T*>& inv, bool all_counts);
-
- /** \brief A helper function to GameGlobal::SaveGame() that stores the contents of a type of inventory to the saved game file
- *** \param file A reference to the open and valid file where to write the inventory list
- *** \param name The name under which this set of inventory data should be categorized (ie "items", "weapons", etc)
- *** \param inv A reference to the inventory vector to store
- *** \note The class type T must be a derived class of GlobalObject
- **/
- template <class T> void _SaveInventory(hoa_script::WriteScriptDescriptor& file, const std::string& name, std::vector<T*>& inv);
-
- /** \brief A helper function to GameGlobal::SaveGame() that writes character data to the saved game file
- *** \param file A reference to the open and valid file where to write the character data
- *** \param objects A ponter to the character whose data should be saved
- *** \param last Set to true if this is the final character that needs to be saved
- *** This method will need to be called once for each character in the player's party
- **/
- void _SaveCharacter(hoa_script::WriteScriptDescriptor& file, GlobalCharacter* character, bool last);
-
- /** \brief A helper function to GameGlobal::SaveGame() that writes a group of event data to the saved game file
- *** \param file A reference to the open and valid file where to write the event data
- *** \param event_group A pointer to the group of events to store
- *** This method will need to be called once for each GlobalEventGroup contained by this class.
- **/
- void _SaveEvents(hoa_script::WriteScriptDescriptor& file, GlobalEventGroup* event_group);
-
- /** \brief A helper function to GameGlobal::LoadGame() that restores the contents of the inventory from a saved game file
- *** \param file A reference to the open and valid file from where to read the inventory list
- *** \param category_name The name of the table in the file that should contain the inventory for a specific category
- **/
- void _LoadInventory(hoa_script::ReadScriptDescriptor& file, const std::string& category_name);
-
- /** \brief A helper function to GameGlobal::LoadGame() that loads a saved game character and adds it to the party
- *** \param file A reference to the open and valid file from where to read the character from
- *** \param id The character's integer ID, used to find and restore the character data
- **/
- void _LoadCharacter(hoa_script::ReadScriptDescriptor& file, uint32 id);
-
- /** \brief A helper function to GameGlobal::LoadGame() that loads a group of game events from a saved game file
- *** \param file A reference to the open and valid file from where to read the event data from
- *** \param group_name The name of the event group to load
- **/
- void _LoadEvents(hoa_script::ReadScriptDescriptor& file, const std::string& group_name);
+ /** \brief A vector whose purpose is to maintain the order of characters
+ *** The first four characters in this vector are in the active party; the rest are in reserve.
+ **/
+ std::vector<GlobalCharacter *> _ordered_characters;
+
+ /** \brief The active party of characters
+ *** The active party contains the group of characters that will fight when a battle begins.
+ *** This party can be up to four characters, and should always contain at least one character.
+ **/
+ GlobalParty _active_party;
+
+ /** \brief Retains a list of all of the objects currently stored in the player's inventory
+ *** This map is used to quickly check if an item is in the inventory or not. The key to the map is the object's
+ *** identification number. When an object is added to the inventory, if it already exists then the object counter
+ *** is simply increased instead of adding an entire new class object. When the object count becomes zero, the object
+ *** is removed from the inventory. Duplicates of all objects are retained in the various inventory containers below.
+ **/
+ std::map<uint32, GlobalObject *> _inventory;
+
+ /** \brief Inventory containers
+ *** These vectors contain the inventory of the entire party. The vectors are sorted according to the player's personal preferences.
+ *** When a new object is added to the inventory, by default it will be placed at the end of the vector.
+ **/
+ //@{
+ std::vector<GlobalItem *> _inventory_items;
+ std::vector<GlobalWeapon *> _inventory_weapons;
+ std::vector<GlobalArmor *> _inventory_head_armor;
+ std::vector<GlobalArmor *> _inventory_torso_armor;
+ std::vector<GlobalArmor *> _inventory_arm_armor;
+ std::vector<GlobalArmor *> _inventory_leg_armor;
+ std::vector<GlobalShard *> _inventory_shards;
+ std::vector<GlobalKeyItem *> _inventory_key_items;
+ //@}
+
+ //! \name Global data and function script files
+ //@{
+ //! \brief Contains character ID definitions and a number of useful functions
+ hoa_script::ReadScriptDescriptor _global_script;
+
+ //! \brief Contains data definitions for all items
+ hoa_script::ReadScriptDescriptor _items_script;
+
+ //! \brief Contains data definitions for all key items
+ hoa_script::ReadScriptDescriptor _key_items_script;
+
+ //! \brief Contains data definitions for all weapons
+ hoa_script::ReadScriptDescriptor _weapons_script;
+
+ //! \brief Contains data definitions for all armor that are equipped on the head
+ hoa_script::ReadScriptDescriptor _head_armor_script;
+
+ //! \brief Contains data definitions for all armor that are equipped on the torso
+ hoa_script::ReadScriptDescriptor _torso_armor_script;
+
+ //! \brief Contains data definitions for all armor that are equipped on the arms
+ hoa_script::ReadScriptDescriptor _arm_armor_script;
+
+ //! \brief Contains data definitions for all armor that are equipped on the legs
+ hoa_script::ReadScriptDescriptor _leg_armor_script;
+
+ //! \brief Contains data definitions for all shards
+ // hoa_script::ReadScriptDescriptor _shard_script;
+
+ //! \brief Contains data definitions for all key items
+ // hoa_script::ReadScriptDescriptor _key_items_script;
+
+ //! \brief Contains data and functional definitions for all attack skills
+ hoa_script::ReadScriptDescriptor _attack_skills_script;
+
+ //! \brief Contains data and functional definitions for all defense skills
+ hoa_script::ReadScriptDescriptor _defend_skills_script;
+
+ //! \brief Contains data and functional definitions for all support skills
+ hoa_script::ReadScriptDescriptor _support_skills_script;
+
+ //! \brief Contains functional definitions for all status effects
+ hoa_script::ReadScriptDescriptor _status_effects_script;
+
+ //! \brief Contains data and functional definitions for sprites seen in game maps
+ hoa_script::ReadScriptDescriptor _map_sprites_script;
+
+ //! \brief Contains data and functional definitions for map objects seen in game maps
+ hoa_script::ReadScriptDescriptor _map_objects_script;
+
+ //! \brief Contains data and functional definitions for map treasures seen in game maps
+ hoa_script::ReadScriptDescriptor _map_treasures_script;
+ //@}
+
+ /** \brief The container which stores all of the groups of events that have occured in the game
+ *** The name of each GlobalEventGroup object serves as its key in this map data structure.
+ **/
+ std::map<std::string, GlobalEventGroup *> _event_groups;
+
+ //! \brief A map containing all the emote animations
+ std::map<std::string, hoa_video::AnimatedImage> _emotes;
+ //! \brief The map continaing the four sprite direction offsets (x and y value).
+ std::map<std::string, std::vector<std::pair<float, float> > > _emotes_offsets;
+
+ // ----- Private methods
+
+ /** \brief A helper template function that finds and removes an object from the inventory
+ *** \param obj_id The ID of the object to remove from the inventory
+ *** \param inv The vector container of the appropriate inventory type
+ *** \return True if the object was successfully removed, or false if it was not
+ **/
+ template <class T> bool _RemoveFromInventory(uint32 obj_id, std::vector<T *>& inv);
+
+ /** \brief A helper template function that finds and returns a copy of an object from the inventory
+ *** \param obj_id The ID of the object to remove from the inventory
+ *** \param inv The vector container of the appropriate inventory type
+ *** \param all_counts If false the object's count is decremented by one from the inventory, otherwise all counts are removed completely
+ *** \return A pointer to the newly created copy of the object, or NULL if the object could not be found
+ **/
+ template <class T> T *_RetrieveFromInventory(uint32 obj_id, std::vector<T *>& inv, bool all_counts);
+
+ /** \brief A helper function to GameGlobal::SaveGame() that stores the contents of a type of inventory to the saved game file
+ *** \param file A reference to the open and valid file where to write the inventory list
+ *** \param name The name under which this set of inventory data should be categorized (ie "items", "weapons", etc)
+ *** \param inv A reference to the inventory vector to store
+ *** \note The class type T must be a derived class of GlobalObject
+ **/
+ template <class T> void _SaveInventory(hoa_script::WriteScriptDescriptor &file, const std::string &name, std::vector<T *>& inv);
+
+ /** \brief A helper function to GameGlobal::SaveGame() that writes character data to the saved game file
+ *** \param file A reference to the open and valid file where to write the character data
+ *** \param objects A ponter to the character whose data should be saved
+ *** \param last Set to true if this is the final character that needs to be saved
+ *** This method will need to be called once for each character in the player's party
+ **/
+ void _SaveCharacter(hoa_script::WriteScriptDescriptor &file, GlobalCharacter *character, bool last);
+
+ /** \brief A helper function to GameGlobal::SaveGame() that writes a group of event data to the saved game file
+ *** \param file A reference to the open and valid file where to write the event data
+ *** \param event_group A pointer to the group of events to store
+ *** This method will need to be called once for each GlobalEventGroup contained by this class.
+ **/
+ void _SaveEvents(hoa_script::WriteScriptDescriptor &file, GlobalEventGroup *event_group);
+
+ /** \brief A helper function to GameGlobal::LoadGame() that restores the contents of the inventory from a saved game file
+ *** \param file A reference to the open and valid file from where to read the inventory list
+ *** \param category_name The name of the table in the file that should contain the inventory for a specific category
+ **/
+ void _LoadInventory(hoa_script::ReadScriptDescriptor &file, const std::string &category_name);
+
+ /** \brief A helper function to GameGlobal::LoadGame() that loads a saved game character and adds it to the party
+ *** \param file A reference to the open and valid file from where to read the character from
+ *** \param id The character's integer ID, used to find and restore the character data
+ **/
+ void _LoadCharacter(hoa_script::ReadScriptDescriptor &file, uint32 id);
+
+ /** \brief A helper function to GameGlobal::LoadGame() that loads a group of game events from a saved game file
+ *** \param file A reference to the open and valid file from where to read the event data from
+ *** \param group_name The name of the event group to load
+ **/
+ void _LoadEvents(hoa_script::ReadScriptDescriptor &file, const std::string &group_name);
}; // class GameGlobal : public hoa_utils::Singleton<GameGlobal>
//-----------------------------------------------------------------------------
// Template Function Definitions
//-----------------------------------------------------------------------------
-template <class T> bool GameGlobal::_RemoveFromInventory(uint32 obj_id, std::vector<T*>& inv) {
- for (typename std::vector<T*>::iterator i = inv.begin(); i != inv.end(); i++) {
- if ((*i)->GetID() == obj_id) {
- // Delete the object, remove it from the vector container, and remove it from the _inventory map
- delete _inventory[obj_id];
- inv.erase(i);
- _inventory.erase(obj_id);
- return true;
- }
- }
-
- return false;
+template <class T> bool GameGlobal::_RemoveFromInventory(uint32 obj_id, std::vector<T *>& inv)
+{
+ for(typename std::vector<T *>::iterator i = inv.begin(); i != inv.end(); i++) {
+ if((*i)->GetID() == obj_id) {
+ // Delete the object, remove it from the vector container, and remove it from the _inventory map
+ delete _inventory[obj_id];
+ inv.erase(i);
+ _inventory.erase(obj_id);
+ return true;
+ }
+ }
+
+ return false;
} // template <class T> bool GameGlobal::_RemoveFromInventory(uint32 obj_id, std::vector<T*>& inv)
-template <class T> T* GameGlobal::_RetrieveFromInventory(uint32 obj_id, std::vector<T*>& inv, bool all_counts) {
- for (typename std::vector<T*>::iterator i = inv.begin(); i != inv.end(); i++) {
- if ((*i)->GetID() == obj_id) {
- T* return_object;
- if (all_counts == true || _inventory[obj_id]->GetCount() == 1) {
- return_object = *i;
- _inventory.erase(obj_id);
- inv.erase(i);
- }
- else {
- return_object = new T(**i);
- return_object->SetCount(1);
- _inventory[obj_id]->DecrementCount();
- }
- return return_object;
- }
- }
-
- return NULL;
+template <class T> T *GameGlobal::_RetrieveFromInventory(uint32 obj_id, std::vector<T *>& inv, bool all_counts)
+{
+ for(typename std::vector<T *>::iterator i = inv.begin(); i != inv.end(); i++) {
+ if((*i)->GetID() == obj_id) {
+ T *return_object;
+ if(all_counts == true || _inventory[obj_id]->GetCount() == 1) {
+ return_object = *i;
+ _inventory.erase(obj_id);
+ inv.erase(i);
+ } else {
+ return_object = new T(**i);
+ return_object->SetCount(1);
+ _inventory[obj_id]->DecrementCount();
+ }
+ return return_object;
+ }
+ }
+
+ return NULL;
} // template <class T> T* GameGlobal::_RetrieveFromInventory(uint32 obj_id, std::vector<T*>& inv, bool all_counts)
-template <class T> void GameGlobal::_SaveInventory(hoa_script::WriteScriptDescriptor& file, const std::string& name, std::vector<T*>& inv) {
- if (file.IsFileOpen() == false) {
- IF_PRINT_WARNING(GLOBAL_DEBUG) << "failed because the argument file was not open" << std::endl;
- return;
- }
-
- file.InsertNewLine();
- file.WriteLine(name + " = {");
- for (uint32 i = 0; i < inv.size(); i++) {
- if (i == 0)
- file.WriteLine("\t", false);
- else
- file.WriteLine(", ", false);
- file.WriteLine("[" + hoa_utils::NumberToString(inv[i]->GetID()) + "] = "
- + hoa_utils::NumberToString(inv[i]->GetCount()), false);
- }
- file.InsertNewLine();
- file.WriteLine("}");
+template <class T> void GameGlobal::_SaveInventory(hoa_script::WriteScriptDescriptor &file, const std::string &name, std::vector<T *>& inv)
+{
+ if(file.IsFileOpen() == false) {
+ IF_PRINT_WARNING(GLOBAL_DEBUG) << "failed because the argument file was not open" << std::endl;
+ return;
+ }
+
+ file.InsertNewLine();
+ file.WriteLine(name + " = {");
+ for(uint32 i = 0; i < inv.size(); i++) {
+ if(i == 0)
+ file.WriteLine("\t", false);
+ else
+ file.WriteLine(", ", false);
+ file.WriteLine("[" + hoa_utils::NumberToString(inv[i]->GetID()) + "] = "
+ + hoa_utils::NumberToString(inv[i]->GetCount()), false);
+ }
+ file.InsertNewLine();
+ file.WriteLine("}");
} // template <class T> void GameGlobal::_SaveInventory(hoa_script::WriteScriptDescriptor& file, std::string name, std::vector<T*>& inv)
} // namespace hoa_global
View
2,899 src/common/global/global_actors.cpp
1,465 additions, 1,434 deletions not shown
View
1,902 src/common/global/global_actors.h
@@ -35,15 +35,18 @@
*** This method should <b>only be called once</b>. It must be called after the
*** ScriptEngine is initialized, otherwise the application will crash.
**/
-namespace hoa_defs {
+namespace hoa_defs
+{
void BindCommonCode();
}
-namespace hoa_script {
+namespace hoa_script
+{
class ReadScriptDescriptor;
}
-namespace hoa_global {
+namespace hoa_global
+{
class GlobalActor;
class GlobalArmor;
@@ -60,135 +63,149 @@ class GlobalWeapon;
*** are located on the head, torso, arms, and legs. Each attack points may have certain weaknesses
*** or resistances.
*** ***************************************************************************/
-class GlobalAttackPoint {
+class GlobalAttackPoint
+{
public:
- //! \param actor_owner A pointer to the GlobalActor owner of this attack point
- GlobalAttackPoint(GlobalActor* owner);
-
- ~GlobalAttackPoint()
- { _actor_owner = NULL; }
-
- /** \brief Reads in the attack point's data from a script file
- *** \param script A reference to the open script file where to retrieve the data from
- *** \return True upon success, false upon failure.
- ***
- *** There are two requirements for using this function. First, the script file must already
- *** be opened for reading permissions. Second, the table which contains the attack point data
- *** must be opened <b>prior</b> to making this function call. This function will not close the
- *** table containing the attack point when it finishes loading the data, so the calling routine
- *** must remember to close the table after this call is made.
- **/
- bool LoadData(hoa_script::ReadScriptDescriptor& script);
-
- /** \brief Determines the total physical and metaphysical defense of the attack point
- *** \param equipped_armor A pointer to the armor equipped on the attack point, or NULL if no armor is equipped
- ***
- *** This method uses the owning GlobalActor's base defense stats, the attack point's defense modifiers stats,
- *** and the properties of the equipped armor to calculate the attack point's total physical and metaphysical defense.
- *** This method should be called whenever the actor's base defense stats or equipped armor on this point changes.
- **/
- void CalculateTotalDefense(const GlobalArmor* equipped_armor);
-
- /** \brief Determines the total evade rating of the attack point
- ***
- *** This method uses the owning GlobalActor's base evade rating and the attack point's evade modifiers stats to
- *** calculate the attack point's total evade rating. This method should be called whenever the actor's base defense
- *** rating changes.
- **/
- void CalculateTotalEvade();
-
- //! \name Class Member Access Functions
- //@{
- hoa_utils::ustring& GetName()
- { return _name; }
-
- GlobalActor* GetActorOwner() const
- { return _actor_owner; }
-
- int16 GetXPosition() const
- { return _x_position; }
-
- int16 GetYPosition() const
- { return _y_position; }
-
- float GetFortitudeModifier() const
- { return _fortitude_modifier; }
-
- float GetProtectionModifier() const
- { return _protection_modifier; }
-
- float GetEvadeModifier() const
- { return _evade_modifier; }
-
- uint16 GetTotalPhysicalDefense() const
- { return _total_physical_defense; }
-
- uint16 GetTotalMetaphysicalDefense() const
- { return _total_metaphysical_defense; }
-
- float GetTotalEvadeRating() const
- { return _total_evade_rating; }
-
- const std::vector<std::pair<GLOBAL_STATUS, float> >& GetStatusEffects() const
- { return _status_effects; }
-
- //! \note Use this method with extreme caution. It does not update defense/evade totals or any other members
- void SetActorOwner(GlobalActor* new_owner)
- { _actor_owner = new_owner; }
- //@}
+ //! \param actor_owner A pointer to the GlobalActor owner of this attack point
+ GlobalAttackPoint(GlobalActor *owner);
+
+ ~GlobalAttackPoint() {
+ _actor_owner = NULL;
+ }
+
+ /** \brief Reads in the attack point's data from a script file
+ *** \param script A reference to the open script file where to retrieve the data from
+ *** \return True upon success, false upon failure.
+ ***
+ *** There are two requirements for using this function. First, the script file must already
+ *** be opened for reading permissions. Second, the table which contains the attack point data
+ *** must be opened <b>prior</b> to making this function call. This function will not close the
+ *** table containing the attack point when it finishes loading the data, so the calling routine
+ *** must remember to close the table after this call is made.
+ **/
+ bool LoadData(hoa_script::ReadScriptDescriptor &script);
+
+ /** \brief Determines the total physical and metaphysical defense of the attack point
+ *** \param equipped_armor A pointer to the armor equipped on the attack point, or NULL if no armor is equipped
+ ***
+ *** This method uses the owning GlobalActor's base defense stats, the attack point's defense modifiers stats,
+ *** and the properties of the equipped armor to calculate the attack point's total physical and metaphysical defense.
+ *** This method should be called whenever the actor's base defense stats or equipped armor on this point changes.
+ **/
+ void CalculateTotalDefense(const GlobalArmor *equipped_armor);
+
+ /** \brief Determines the total evade rating of the attack point
+ ***
+ *** This method uses the owning GlobalActor's base evade rating and the attack point's evade modifiers stats to
+ *** calculate the attack point's total evade rating. This method should be called whenever the actor's base defense
+ *** rating changes.
+ **/
+ void CalculateTotalEvade();
+
+ //! \name Class Member Access Functions
+ //@{
+ hoa_utils::ustring &GetName() {
+ return _name;
+ }
+
+ GlobalActor *GetActorOwner() const {
+ return _actor_owner;
+ }
+
+ int16 GetXPosition() const {
+ return _x_position;
+ }
+
+ int16 GetYPosition() const {
+ return _y_position;
+ }
+
+ float GetFortitudeModifier() const {
+ return _fortitude_modifier;
+ }
+
+ float GetProtectionModifier() const {
+ return _protection_modifier;
+ }
+
+ float GetEvadeModifier() const {
+ return _evade_modifier;
+ }
+
+ uint16 GetTotalPhysicalDefense() const {
+ return _total_physical_defense;
+ }
+
+ uint16 GetTotalMetaphysicalDefense() const {
+ return _total_metaphysical_defense;
+ }
+
+ float GetTotalEvadeRating() const {
+ return _total_evade_rating;
+ }
+
+ const std::vector<std::pair<GLOBAL_STATUS, float> >& GetStatusEffects() const {
+ return _status_effects;
+ }
+
+ //! \note Use this method with extreme caution. It does not update defense/evade totals or any other members
+ void SetActorOwner(GlobalActor *new_owner) {
+ _actor_owner = new_owner;
+ }
+ //@}
private:
- /** \brief The name of the attack point as is displayed on the screen
- *** Usually, this is simply the name of a body part such as "head" or "tail". More elaborate names
- *** may be chosen for special foes and bosses, however.
- **/
- hoa_utils::ustring _name;
-
- //! \brief A pointer to the actor which "owns" this attack point (i.e., the attack point is a location on the actor)
- GlobalActor* _actor_owner;
-
- /** \brief The position of the physical attack point relative to the actor's battle sprite
- *** These members treat the bottom center of the sprite as the origin (0, 0) and increase in the
- *** right and upwards directions. The combination of these two members point to the center pinpoint
- *** location of the attack point. The units of these two members are in number of pixels. The _y_position
- *** member should always be positive, by _x_position may be either positive or negative.
- **/
- int16 _x_position, _y_position;
-
- /** \brief The defense and evasion percentage modifiers for this attack point
- ***
- *** These are called "modifiers" because they modify the value of fortitude, protection, and evade ratings of the
- *** actor. They represent percentage change from the base stat. So for example, a fortitude modifer that is 0.25f
- *** increases the fortitude of the attack point by 25%. If the base protection rating was 10 and the protection
- *** modifier was -0.30f, the resulting protection for the attack point would be: 10 + (10 * -0.30f) = 7.
- ***
- *** The lower bound for each modifier is -1.0f (-100%), which will result in a value of zero for that stat. No
- *** actor stats can be negative so even if the modifier drops below -1.0f, the resulting value will still be zero.
- *** There is no theoretical upper bound, but it is usually advised to keep it under 1.0f (100%).
- **/
- //@{
- float _fortitude_modifier;
- float _protection_modifier;
- float _evade_modifier;
- //@}
-
- /** \brief The cumunalative defense and evade stats for this attack point
- *** These totals include the actor's base stat, the percentage modifier for the attack point, and the stats of any
- *** armor that is equipped on the attack point.
- **/
- //@{
- uint16 _total_physical_defense;
- uint16 _total_metaphysical_defense;
- float _total_evade_rating;
- //@}
-
- /** \brief A vector containing all status effects that may be triggered by attacking the point
- *** This vector contains only the status effects that have a non-zero chance of affecting their target. Therefore,
- *** it is very possible that this vector may be empty, and usually it will contain only a single entry. The first
- *** element of the pair is an identifier for the type of status. The second element is a floating point value from
- *** 0.0 to 100.0, representing a 0-100% probability range for this effect to be triggered upon being hit.
- **/
- std::vector<std::pair<GLOBAL_STATUS, float> > _status_effects;
+ /** \brief The name of the attack point as is displayed on the screen
+ *** Usually, this is simply the name of a body part such as "head" or "tail". More elaborate names
+ *** may be chosen for special foes and bosses, however.
+ **/
+ hoa_utils::ustring _name;
+
+ //! \brief A pointer to the actor which "owns" this attack point (i.e., the attack point is a location on the actor)
+ GlobalActor *_actor_owner;
+
+ /** \brief The position of the physical attack point relative to the actor's battle sprite
+ *** These members treat the bottom center of the sprite as the origin (0, 0) and increase in the
+ *** right and upwards directions. The combination of these two members point to the center pinpoint
+ *** location of the attack point. The units of these two members are in number of pixels. The _y_position
+ *** member should always be positive, by _x_position may be either positive or negative.
+ **/
+ int16 _x_position, _y_position;
+
+ /** \brief The defense and evasion percentage modifiers for this attack point
+ ***
+ *** These are called "modifiers" because they modify the value of fortitude, protection, and evade ratings of the
+ *** actor. They represent percentage change from the base stat. So for example, a fortitude modifer that is 0.25f
+ *** increases the fortitude of the attack point by 25%. If the base protection rating was 10 and the protection
+ *** modifier was -0.30f, the resulting protection for the attack point would be: 10 + (10 * -0.30f) = 7.
+ ***
+ *** The lower bound for each modifier is -1.0f (-100%), which will result in a value of zero for that stat. No
+ *** actor stats can be negative so even if the modifier drops below -1.0f, the resulting value will still be zero.
+ *** There is no theoretical upper bound, but it is usually advised to keep it under 1.0f (100%).
+ **/
+ //@{
+ float _fortitude_modifier;
+ float _protection_modifier;
+ float _evade_modifier;
+ //@}
+
+ /** \brief The cumunalative defense and evade stats for this attack point
+ *** These totals include the actor's base stat, the percentage modifier for the attack point, and the stats of any
+ *** armor that is equipped on the attack point.
+ **/
+ //@{
+ uint16 _total_physical_defense;
+ uint16 _total_metaphysical_defense;
+ float _total_evade_rating;
+ //@}
+
+ /** \brief A vector containing all status effects that may be triggered by attacking the point
+ *** This vector contains only the status effects that have a non-zero chance of affecting their target. Therefore,
+ *** it is very possible that this vector may be empty, and usually it will contain only a single entry. The first
+ *** element of the pair is an identifier for the type of status. The second element is a floating point value from
+ *** 0.0 to 100.0, representing a 0-100% probability range for this effect to be triggered upon being hit.
+ **/
+ std::vector<std::pair<GLOBAL_STATUS, float> > _status_effects;
}; // class GlobalAttackPoint
@@ -199,147 +216,173 @@ class GlobalAttackPoint {
*** inherit from in order to provide a consistent interface to the statistics
*** that characters and enemies share.
*** ***************************************************************************/
-class GlobalActor {
+class GlobalActor
+{
public:
- GlobalActor();
+ GlobalActor();
+
+ virtual ~GlobalActor();
+
+ GlobalActor(const GlobalActor &copy);
+
+ GlobalActor &operator=(const GlobalActor &copy);
+
+ /** \brief Equips a new weapon on the actor
+ *** \param weapon The new weapon to equip on the actor
+ *** \return A pointer to the weapon that was previouslly equipped, or NULL if no weapon was equipped.
+ ***
+ *** This function will also automatically re-calculate all attack ratings, elemental, and status bonuses.
+ **/
+ GlobalWeapon *EquipWeapon(GlobalWeapon *weapon);
+
+ /** \brief Equips a new armor on the actor
+ *** \param armor The piece of armor to equip
+ *** \param index The index into the _armor_equippd vector where to equip the armor
+ *** \return A pointer to the armor that was previously equipped, or NULL if no armor was equipped
+ ***
+ *** This function will also automatically re-calculate all defense ratings, elemental, and status bonuses
+ *** for the attack point that the armor was equipped on. If the index argument is invalid (out-of-bounds),
+ *** the function will return the armor argument.
+ **/
+ GlobalArmor *EquipArmor(GlobalArmor *armor, uint32 index);
+
+ /** \brief Adds a new skill to the actor's skill set
+ *** \param skill_id The id number of the skill to add
+ ***
+ *** No skill may be added more than once. If this case is detected or an error occurs when trying
+ *** to load the skill data, it will not be added.
+ **/
+ virtual void AddSkill(uint32 skill_id) = 0;
+
+ /** \brief Determines if the actor is "alive" and able to perform actions
+ *** \return True if the character has a non-zero amount of hit points
+ **/
+ bool IsAlive() const {
+ return (_hit_points != 0);
+ }
+
+ /** \name Class member get functions
+ *** Some of these functions take an index argument to retrieve a particular
+ *** attack point stat or piece of armor. If an invalid index is given, a zero
+ *** or NULL value will be returned.
+ **/
+ //@{
+ uint32 GetID() const {
+ return _id;
+ }
+
+ hoa_utils::ustring &GetName() {
+ return _name;
+ }
+
+ const std::string &GetMapSpriteName() {
+ return _map_sprite_name;
+ }
+
+ hoa_video::StillImage &GetPortrait() {
+ return _portrait;
+ }
+
+ hoa_video::StillImage &GetFullPortrait() {
+ return _full_portrait;
+ }
+
+ hoa_video::StillImage &GetStaminaIcon() {
+ return _stamina_icon;
+ }
+
+ uint32 GetHitPoints() const {
+ return _hit_points;
+ }
+
+ uint32 GetMaxHitPoints() const {
+ return _max_hit_points;
+ }
+
+ uint32 GetSkillPoints() const {
+ return _skill_points;
+ }
+
+ uint32 GetMaxSkillPoints() const {
+ return _max_skill_points;
+ }
+
+ uint32 GetExperienceLevel() const {
+ return _experience_level;
+ }
+
+ uint32 GetExperiencePoints() const {
+ return _experience_points;
+ }
+
+ uint32 GetStrength() const {
+ return _strength;
+ }
+
+ uint32 GetVigor() const {
+ return _vigor;
+ }
+
+ uint32 GetFortitude() const {
+ return _fortitude;
+ }
+
+ uint32 GetProtection() const {
+ return _protection;
+ }
+
+ uint32 GetAgility() const {
+ return _agility;
+ }
+
+ float GetEvade() const {
+ return _evade;
+ }
+
+ uint32 GetTotalPhysicalAttack() const {
+ return _total_physical_attack;
+ }
+
+ uint32 GetTotalMetaphysicalAttack() const {
+ return _total_metaphysical_attack;
+ }
+
+ uint32 GetTotalPhysicalDefense(uint32 index) const;
- virtual ~GlobalActor();
+ uint32 GetTotalMetaphysicalDefense(uint32 index) const;
- GlobalActor(const GlobalActor& copy);
+ float GetTotalEvadeRating(uint32 index) const;
- GlobalActor& operator=(const GlobalActor& copy);
+ GlobalWeapon *GetWeaponEquipped() const {
+ return _weapon_equipped;
+ }
- /** \brief Equips a new weapon on the actor
- *** \param weapon The new weapon to equip on the actor
- *** \return A pointer to the weapon that was previouslly equipped, or NULL if no weapon was equipped.
- ***
- *** This function will also automatically re-calculate all attack ratings, elemental, and status bonuses.
- **/
- GlobalWeapon* EquipWeapon(GlobalWeapon* weapon);
+ const std::vector<GlobalArmor *>& GetArmorEquipped() {
+ return _armor_equipped;
+ }
- /** \brief Equips a new armor on the actor
- *** \param armor The piece of armor to equip
- *** \param index The index into the _armor_equippd vector where to equip the armor
- *** \return A pointer to the armor that was previously equipped, or NULL if no armor was equipped
- ***
- *** This function will also automatically re-calculate all defense ratings, elemental, and status bonuses
- *** for the attack point that the armor was equipped on. If the index argument is invalid (out-of-bounds),
- *** the function will return the armor argument.
- **/
- GlobalArmor* EquipArmor(GlobalArmor* armor, uint32 index);
+ GlobalArmor *GetArmorEquipped(uint32 index) const;
- /** \brief Adds a new skill to the actor's skill set
- *** \param skill_id The id number of the skill to add
- ***
- *** No skill may be added more than once. If this case is detected or an error occurs when trying
- *** to load the skill data, it will not be added.
- **/
- virtual void AddSkill(uint32 skill_id) = 0;
+ const std::vector<GlobalAttackPoint *>& GetAttackPoints() {
+ return _attack_points;
+ }
- /** \brief Determines if the actor is "alive" and able to perform actions
- *** \return True if the character has a non-zero amount of hit points
- **/
- bool IsAlive() const
- { return (_hit_points != 0); }
+ GlobalAttackPoint *GetAttackPoint(uint32 index) const;
- /** \name Class member get functions
- *** Some of these functions take an index argument to retrieve a particular
- *** attack point stat or piece of armor. If an invalid index is given, a zero
- *** or NULL value will be returned.
- **/
- //@{
- uint32 GetID() const
- { return _id; }
+ const std::map<uint32, GlobalSkill *>& GetSkills() {
+ return _skills;
+ }
- hoa_utils::ustring& GetName()
- { return _name; }
+ /** \brief Retrieves a pointer to a skill with a specific id
+ *** \param skill_id The unique ID of the skill to find and return
+ *** \return A pointer to the skill if it is found, or NULL if the skill was not found
+ **/
+ GlobalSkill *GetSkill(uint32 skill_id) const;
- const std::string& GetMapSpriteName()
- { return _map_sprite_name; }
+ //! \brief An alternative GetSkill call that takes a skill pointer as an argument
+ GlobalSkill *GetSkill(const GlobalSkill *skill) const;
- hoa_video::StillImage& GetPortrait()
- { return _portrait; }
-
- hoa_video::StillImage& GetFullPortrait()
- { return _full_portrait; }
-
- hoa_video::StillImage& GetStaminaIcon()
- { return _stamina_icon; }
-
- uint32 GetHitPoints() const
- { return _hit_points; }
-
- uint32 GetMaxHitPoints() const
- { return _max_hit_points; }
-
- uint32 GetSkillPoints() const
- { return _skill_points; }
-
- uint32 GetMaxSkillPoints() const
- { return _max_skill_points; }
-
- uint32 GetExperienceLevel() const
- { return _experience_level; }
-
- uint32 GetExperiencePoints() const
- { return _experience_points; }
-
- uint32 GetStrength() const
- { return _strength; }
-
- uint32 GetVigor() const
- { return _vigor; }
-
- uint32 GetFortitude() const
- { return _fortitude; }
-
- uint32 GetProtection() const
- { return _protection; }
-
- uint32 GetAgility() const
- { return _agility; }
-
- float GetEvade() const
- { return _evade; }
-
- uint32 GetTotalPhysicalAttack() const
- { return _total_physical_attack; }
-
- uint32 GetTotalMetaphysicalAttack() const
- { return _total_metaphysical_attack; }
-
- uint32 GetTotalPhysicalDefense(uint32 index) const;
-
- uint32 GetTotalMetaphysicalDefense(uint32 index) const;
-
- float GetTotalEvadeRating(uint32 index) const;
-
- GlobalWeapon* GetWeaponEquipped() const
- { return _weapon_equipped; }
-
- const std::vector<GlobalArmor*>& GetArmorEquipped()
- { return _armor_equipped; }
-
- GlobalArmor* GetArmorEquipped(uint32 index) const;
-
- const std::vector<GlobalAttackPoint*>& GetAttackPoints()
- { return _attack_points; }
-
- GlobalAttackPoint* GetAttackPoint(uint32 index) const;
-
- const std::map<uint32, GlobalSkill*>& GetSkills()
- { return _skills; }
-
- /** \brief Retrieves a pointer to a skill with a specific id
- *** \param skill_id The unique ID of the skill to find and return
- *** \return A pointer to the skill if it is found, or NULL if the skill was not found
- **/
- GlobalSkill* GetSkill(uint32 skill_id) const;
-
- //! \brief An alternative GetSkill call that takes a skill pointer as an argument
- GlobalSkill* GetSkill(const GlobalSkill* skill) const;
-
- // TODO: elemental and status effects not yet available in game
+ // TODO: elemental and status effects not yet available in game
// std::vector<GlobalElementalEffect*>& GetElementalAttackBonuses()
// { return _elemental_attack_bonuses; }
//
@@ -351,244 +394,265 @@ class GlobalActor {
//
// std::vector<std::pair<float, GlobalStatusEffect*> >& GetStatusDefenseBonuses()
// { return _status_defense_bonuses; }
- //@}
+ //@}
+
+ /** \name Class member set functions
+ *** Normally you should not need to directly set the value of these members, but rather add or subtract
+ *** an amount from the current value of the member. Total attack, defense, and evade ratings are
+ *** re-calculated when an appropriately related stat is changed.
+ **/
+ //@{
+ void SetExperienceLevel(uint32 xp_level) {
+ _experience_level = xp_level;
+ }
- /** \name Class member set functions
- *** Normally you should not need to directly set the value of these members, but rather add or subtract
- *** an amount from the current value of the member. Total attack, defense, and evade ratings are
- *** re-calculated when an appropriately related stat is changed.
- **/
- //@{
- void SetExperienceLevel(uint32 xp_level)
- { _experience_level = xp_level; }
+ void SetExperiencePoints(uint32 xp_points) {
+ _experience_points = xp_points;
+ }
- void SetExperiencePoints(uint32 xp_points)
- { _experience_points = xp_points; }
+ void SetHitPoints(uint32 hp) {
+ if(hp > _max_hit_points) _hit_points = _max_hit_points;
+ else _hit_points = hp;
+ }
- void SetHitPoints(uint32 hp)
- { if (hp > _max_hit_points) _hit_points = _max_hit_points; else _hit_points = hp; }
+ void SetMaxHitPoints(uint32 hp) {
+ _max_hit_points = hp;
+ if(_hit_points > _max_hit_points) _hit_points = _max_hit_points;
+ }
- void SetMaxHitPoints(uint32 hp)
- { _max_hit_points = hp; if (_hit_points > _max_hit_points) _hit_points = _max_hit_points; }
+ void SetSkillPoints(uint32 sp) {
+ if(sp > _max_skill_points) _skill_points = _max_skill_points;
+ else _skill_points = sp;
+ }
- void SetSkillPoints(uint32 sp)
- { if (sp > _max_skill_points) _skill_points = _max_skill_points; else _skill_points = sp; }
+ void SetMaxSkillPoints(uint32 sp) {
+ _max_skill_points = sp;
+ if(_skill_points > _max_skill_points) _skill_points = _max_skill_points;
+ }
- void SetMaxSkillPoints(uint32 sp)
- { _max_skill_points = sp; if (_skill_points > _max_skill_points) _skill_points = _max_skill_points; }
+ void SetStrength(uint32 st) {
+ _strength = st;
+ _CalculateAttackRatings();
+ }
- void SetStrength(uint32 st)
- { _strength = st; _CalculateAttackRatings(); }
+ void SetVigor(uint32 vi) {
+ _vigor = vi;
+ _CalculateAttackRatings();
+ }
- void SetVigor(uint32 vi)
- { _vigor = vi; _CalculateAttackRatings(); }
+ void SetFortitude(uint32 fo) {
+ _fortitude = fo;
+ _CalculateDefenseRatings();
+ }
- void SetFortitude(uint32 fo)
- { _fortitude = fo; _CalculateDefenseRatings(); }
+ void SetProtection(uint32 pr) {
+ _protection = pr;
+ _CalculateDefenseRatings();
+ }
- void SetProtection(uint32 pr)
- { _protection = pr; _CalculateDefenseRatings(); }
+ //! Made virtual to permit Battle Actors to recompute the idle state time.
+ virtual void SetAgility(uint32 ag) {
+ _agility = ag;
+ }
- //! Made virtual to permit Battle Actors to recompute the idle state time.
- virtual void SetAgility(uint32 ag)
- { _agility = ag; }
+ void SetEvade(float ev) {
+ _evade = ev;
+ _CalculateEvadeRatings();
+ }
+ //@}
- void SetEvade(float ev)
- { _evade = ev; _CalculateEvadeRatings(); }
- //@}
+ /** \name Class member add and subtract functions
+ *** These methods provide a means to easily add or subtract amounts off of certain stats, such
+ *** as hit points or stength. Total attack, defense, or evade ratings are re-calculated when
+ *** an appropriately related stat is changed. Corner cases are checked to prevent overflow conditions
+ *** and other invalid values, such as current hit points exceeded maximum hit points.
+ ***
+ *** \note When making changes to the maximum hit points or skill points, you should also consider
+ *** making the same addition or subtraction to the current hit points / skill points. Modifying the
+ *** maximum values will not modify the current values unless the change causes the new maximum to
+ *** exceed the current values.
+ **/
+ //@{
+ void AddHitPoints(uint32 amount);
- /** \name Class member add and subtract functions
- *** These methods provide a means to easily add or subtract amounts off of certain stats, such
- *** as hit points or stength. Total attack, defense, or evade ratings are re-calculated when
- *** an appropriately related stat is changed. Corner cases are checked to prevent overflow conditions
- *** and other invalid values, such as current hit points exceeded maximum hit points.
- ***
- *** \note When making changes to the maximum hit points or skill points, you should also consider
- *** making the same addition or subtraction to the current hit points / skill points. Modifying the
- *** maximum values will not modify the current values unless the change causes the new maximum to
- *** exceed the current values.
- **/
- //@{
- void AddHitPoints(uint32 amount);
+ void SubtractHitPoints(uint32 amount);
- void SubtractHitPoints(uint32 amount);
+ void AddMaxHitPoints(uint32 amount);
- void AddMaxHitPoints(uint32 amount);
+ //! \note The number of hit points will be decreased if they are greater than the new maximum
+ void SubtractMaxHitPoints(uint32 amount);
- //! \note The number of hit points will be decreased if they are greater than the new maximum
- void SubtractMaxHitPoints(uint32 amount);
+ void AddSkillPoints(uint32 amount);
- void AddSkillPoints(uint32 amount);
+ void SubtractSkillPoints(uint32 amount);
- void SubtractSkillPoints(uint32 amount);
+ void AddMaxSkillPoints(uint32 amount);
- void AddMaxSkillPoints(uint32 amount);
+ //! \note The number of skill points will be decreased if they are greater than the new maximum
+ void SubtractMaxSkillPoints(uint32 amount);
- //! \note The number of skill points will be decreased if they are greater than the new maximum
- void SubtractMaxSkillPoints(uint32 amount);
+ void AddStrength(uint32 amount);
- void AddStrength(uint32 amount);
+ void SubtractStrength(uint32 amount);
- void SubtractStrength(uint32 amount);
+ void AddVigor(uint32 amount);
- void AddVigor(uint32 amount);
+ void SubtractVigor(uint32 amount);
- void SubtractVigor(uint32 amount);
+ void AddFortitude(uint32 amount);
- void AddFortitude(uint32 amount);
+ void SubtractFortitude(uint32 amount);
- void SubtractFortitude(uint32 amount);
+ void AddProtection(uint32 amount);
- void AddProtection(uint32 amount);
+ void SubtractProtection(uint32 amount);
- void SubtractProtection(uint32 amount);
+ void AddAgility(uint32 amount);
- void AddAgility(uint32 amount);
+ void SubtractAgility(uint32 amount);
- void SubtractAgility(uint32 amount);
+ void AddEvade(float amount);
- void AddEvade(float amount);
-
- void SubtractEvade(float amount);
- //@}
+ void SubtractEvade(float amount);
+ //@}
protected:
- //! \brief An identification number to represent the actor
- uint32 _id;
+ //! \brief An identification number to represent the actor
+ uint32 _id;
- //! \brief The name of the actor as it will be displayed on the screen
- hoa_utils::ustring _name;
+ //! \brief The name of the actor as it will be displayed on the screen
+ hoa_utils::ustring _name;
- //! \brief Used to know the sprite linked to the character in map mode.
- std::string _map_sprite_name;
+ //! \brief Used to know the sprite linked to the character in map mode.
+ std::string _map_sprite_name;
- //! \brief The character portrait
- hoa_video::StillImage _portrait;
+ //! \brief The character portrait
+ hoa_video::StillImage _portrait;
- //! \brief The character full pose portrait
- hoa_video::StillImage _full_portrait;
+ //! \brief The character full pose portrait
+ hoa_video::StillImage _full_portrait;
- //! \brief The character stamina icon
- hoa_video::StillImage _stamina_icon;
+ //! \brief The character stamina icon
+ hoa_video::StillImage _stamina_icon;
- //! \name Base Actor Statistics
- //@{
- //! \brief The current experience level of the actor
- uint32 _experience_level;
+ //! \name Base Actor Statistics
+ //@{
+ //! \brief The current experience level of the actor
+ uint32 _experience_level;
- //! \brief The number of experience points the actor has earned
- uint32 _experience_points;
+ //! \brief The number of experience points the actor has earned
+ uint32 _experience_points;
- //! \brief The current number of hit points that the actor has
- uint32 _hit_points;
+ //! \brief The current number of hit points that the actor has
+ uint32 _hit_points;
- //! \brief The maximum number of hit points that the actor may have
- uint32 _max_hit_points;
+ //! \brief The maximum number of hit points that the actor may have
+ uint32 _max_hit_points;
- //! \brief The current number of skill points that the actor has
- uint32 _skill_points;
+ //! \brief The current number of skill points that the actor has
+ uint32 _skill_points;
- //! \brief The maximum number of skill points that the actor may have
- uint32 _max_skill_points;
+ //! \brief The maximum number of skill points that the actor may have
+ uint32 _max_skill_points;
- //! \brief Used to determine the actor's physical attack rating
- uint32 _strength;
+ //! \brief Used to determine the actor's physical attack rating
+ uint32 _strength;
- //! \brief Used to determine the actor's metaphysical attack rating
- uint32 _vigor;
+ //! \brief Used to determine the actor's metaphysical attack rating
+ uint32 _vigor;
- //! \brief Used to determine the actor's physical defense rating
- uint32 _fortitude;
+ //! \brief Used to determine the actor's physical defense rating
+ uint32 _fortitude;
- //! \brief Used to determine the actor's metaphysical defense rating
- uint32 _protection;
+ //! \brief Used to determine the actor's metaphysical defense rating
+ uint32 _protection;
- //! \brief Used to calculate the time it takes to recover stamina in battles
- uint32 _agility;
+ //! \brief Used to calculate the time it takes to recover stamina in battles
+ uint32 _agility;
- //! \brief The attack evade percentage of the actor, ranged from 0.0 to 1.0
- float _evade;
- //@}
+ //! \brief The attack evade percentage of the actor, ranged from 0.0 to 1.0
+ float _evade;
+ //@}
- //! \brief The sum of the character's strength and their weapon's physical attack
- uint32 _total_physical_attack;
+ //! \brief The sum of the character's strength and their weapon's physical attack
+ uint32 _total_physical_attack;
- //! \brief The sum of the character's vigor and their weapon's metaphysical attack
- uint32 _total_metaphysical_attack;
+ //! \brief The sum of the character's vigor and their weapon's metaphysical attack
+ uint32 _total_metaphysical_attack;
- /** \brief The attack points that are located on the actor
- *** \note All actors must have at least one attack point.
- **/
- std::vector<GlobalAttackPoint*> _attack_points;
+ /** \brief The attack points that are located on the actor
+ *** \note All actors must have at least one attack point.
+ **/
+ std::vector<GlobalAttackPoint *> _attack_points;
- /** \brief The weapon that the actor has equipped
- *** \note If no weapon is equipped, this member will be equal to NULL.
- ***
- *** Actors are not required to have weapons equipped, and indeed most enemies will probably not have any
- *** weapons explicitly equipped. The various bonuses to attack ratings, elemental attacks, and status
- *** attacks are automatically added to the appropriate members of this class when the weapon is equipped,
- *** and likewise those bonuses are removed when the weapon is unequipped.
- **/
- GlobalWeapon* _weapon_equipped;
+ /** \brief The weapon that the actor has equipped
+ *** \note If no weapon is equipped, this member will be equal to NULL.
+ ***
+ *** Actors are not required to have weapons equipped, and indeed most enemies will probably not have any
+ *** weapons explicitly equipped. The various bonuses to attack ratings, elemental attacks, and status
+ *** attacks are automatically added to the appropriate members of this class when the weapon is equipped,
+ *** and likewise those bonuses are removed when the weapon is unequipped.
+ **/
+ GlobalWeapon *_weapon_equipped;
- /** \brief The various armors that the actor has equipped
- *** \note The size of this vector will always be equal to the number of attack points on the actor.
- ***
- *** Actors are not required to have armor of any sort equipped. Note that the defense bonuses that
- *** are afforded by the armors are not directly applied to the character's defense ratings, but rather to
- *** the defense ratings of their attack points. However the elemental and status bonuses of the armor are
- *** applied to the character as a whole. The armor must be equipped on one of the actor's attack points to
- *** really afford any kind of defensive bonus.
- **/
- std::vector<GlobalArmor*> _armor_equipped;
+ /** \brief The various armors that the actor has equipped
+ *** \note The size of this vector will always be equal to the number of attack points on the actor.
+ ***
+ *** Actors are not required to have armor of any sort equipped. Note that the defense bonuses that
+ *** are afforded by the armors are not directly applied to the character's defense ratings, but rather to
+ *** the defense ratings of their attack points. However the elemental and status bonuses of the armor are
+ *** applied to the character as a whole. The armor must be equipped on one of the actor's attack points to
+ *** really afford any kind of defensive bonus.
+ **/
+ std::vector<GlobalArmor *> _armor_equipped;
- /** \brief A map containing all skills that the actor can use
- *** Unlike with characters, there is no need to hold the various types of skills in seperate containers
- *** for enemies. An enemy must have <b>at least</b> one skill in order to do anything useful in battle.
- **/
- std::map<uint32, GlobalSkill*> _skills;
+ /** \brief A map containing all skills that the actor can use
+ *** Unlike with characters, there is no need to hold the various types of skills in seperate containers
+ *** for enemies. An enemy must have <b>at least</b> one skill in order to do anything useful in battle.
+ **/
+ std::map<uint32, GlobalSkill *> _skills;
- /** \brief The elemental effects added to the actor's attack
- *** Actors may carry various elemental attack bonuses, or they may carry none. These bonuses include
- *** those that are brought upon by the weapon that the character may have equipped.
- **/
+ /** \brief The elemental effects added to the actor's attack
+ *** Actors may carry various elemental attack bonuses, or they may carry none. These bonuses include
+ *** those that are brought upon by the weapon that the character may have equipped.
+ **/
// std::vector<GlobalElementalEffect*> _elemental_attack_bonuses;