summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2006-10-20 00:51:25 +0000
committerYohann Ferreira <bertram@cegetel.net>2006-10-20 00:51:25 +0000
commit80f7db7a84fb73d8266d872f56af108ed49ba2eb (patch)
tree1629aa705ebdc1a5c38a2e2e6091bcec715fd346 /src
parentf258986ba1184a0199e0bc241d68919a438eef29 (diff)
downloadmanaserv-80f7db7a84fb73d8266d872f56af108ed49ba2eb.tar.gz
manaserv-80f7db7a84fb73d8266d872f56af108ed49ba2eb.tar.bz2
manaserv-80f7db7a84fb73d8266d872f56af108ed49ba2eb.tar.xz
manaserv-80f7db7a84fb73d8266d872f56af108ed49ba2eb.zip
Simplified item status effect implementation. Made it all work, and filled items.xml with about 100 items. To come: maxPerSlot and weaponType parameters.
Diffstat (limited to 'src')
-rw-r--r--src/item.h84
-rw-r--r--src/itemmanager.cpp208
-rw-r--r--src/main.cpp4
3 files changed, 135 insertions, 161 deletions
diff --git a/src/item.h b/src/item.h
index 2015a029..2f568a9e 100644
--- a/src/item.h
+++ b/src/item.h
@@ -30,48 +30,47 @@
* Enumeration of available Item types.
*/
typedef enum {
- ITEM_USABLE = 1,
- ITEM_EQUIPMENT_ONE_HAND_WEAPON,
- ITEM_EQUIPMENT_TWO_HANDS_WEAPON,
- ITEM_EQUIPMENT_ONE_HAND_RANGED_WEAPON,
- ITEM_EQUIPMENT_TWO_HANDS_RANGED_WEAPON,
- ITEM_EQUIPMENT_BREST,
- ITEM_EQUIPMENT_ARMS,
- ITEM_EQUIPMENT_HEAD,
- ITEM_EQUIPMENT_LEGS,
- ITEM_EQUIPMENT_SHIELD,
- ITEM_EQUIPMENT_RING,
- ITEM_EQUIPMENT_NECKLACE
+ ITEM_UNUSABLE = 0,
+ ITEM_USABLE, // 1
+ ITEM_EQUIPMENT_ONE_HAND_WEAPON, // 2
+ ITEM_EQUIPMENT_TWO_HANDS_WEAPON, // 3
+ ITEM_EQUIPMENT_BREST, // 4
+ ITEM_EQUIPMENT_ARMS, // 5
+ ITEM_EQUIPMENT_HEAD, // 6
+ ITEM_EQUIPMENT_LEGS, // 7
+ ITEM_EQUIPMENT_SHIELD, // 8
+ ITEM_EQUIPMENT_RING, // 9
+ ITEM_EQUIPMENT_NECKLACE, // 10
+ ITEM_EQUIPMENT_FEET // 11
} ItemType;
/**
* States attribute effects to beings, and actors.
* States can be multiple for the same being.
*/
-struct BeingStateEffects {
- bool STATE_NORMAL;
- bool STATE_POISONED;
- bool STATE_STONED;
- bool STATE_STUNNED;
- bool STATE_SLOWED;
- bool STATE_TIRED;
- bool STATE_MAD;
- bool STATE_BERSERK;
- bool STATE_HASTED;
- bool STATE_FLOATING;
-
- bool STATE_NOT_POISONED;
- bool STATE_NOT_STONED;
- bool STATE_NOT_STUNNED;
- bool STATE_NOT_SLOWED;
- bool STATE_NOT_TIRED;
- bool STATE_NOT_MAD;
- bool STATE_NOT_BERSERK;
- bool STATE_NOT_HASTED;
- bool STATE_NOT_FLOATING;
+typedef enum BeingStateEffect {
+ STATE_NORMAL = 0,
+ STATE_POISONED,
+ STATE_STONED,
+ STATE_STUNNED,
+ STATE_SLOWED,
+ STATE_TIRED,
+ STATE_MAD,
+ STATE_BERSERK,
+ STATE_HASTED,
+ STATE_FLOATING,
+
+ STATE_NOT_POISONED,
+ STATE_NOT_STONED,
+ STATE_NOT_STUNNED,
+ STATE_NOT_SLOWED,
+ STATE_NOT_TIRED,
+ STATE_NOT_MAD,
+ STATE_NOT_BERSERK,
+ STATE_NOT_HASTED,
+ STATE_NOT_FLOATING
};
-
/**
* statistics modifiers.
* once for usables.
@@ -80,20 +79,19 @@ struct BeingStateEffects {
struct Modifiers
{
// General
- Element element; /** Item Element */
- BeingStateEffects beingStateEffects; /** Being State (dis)alteration */
- unsigned short lifetime; /** Modifiers lifetime in seconds. */
+ Element element; /**< Item Element */
+ BeingStateEffect beingStateEffect; /**< Being State (dis)alteration */
+ unsigned short lifetime; /**< Modifiers lifetime in seconds. */
// Caracteristics Modifiers
- short rawStats[NB_RSTAT];
- short computedStats[NB_CSTAT];
+ short rawStats[NB_RSTAT]; /**< Raw Stats modifiers */
+ short computedStats[NB_CSTAT]; /**< Computed Stats modifiers */
- int hpMod; /**< HP modifier */
- int mpMod; /**< MP Modifier */
+ int hp; /**< HP modifier */
+ int mp; /**< MP Modifier */
// Equipment
- unsigned short range; /** Weapon Item Range */
- /**< More to come */
+ unsigned short range; /**< Weapon Item Range */
};
diff --git a/src/itemmanager.cpp b/src/itemmanager.cpp
index 2b480397..d30fd276 100644
--- a/src/itemmanager.cpp
+++ b/src/itemmanager.cpp
@@ -34,7 +34,7 @@
xmlFree(prop); \
}
-ItemManager::ItemManager(std::string itemReferenceFile)
+ItemManager::ItemManager(const std::string &itemReferenceFile)
{
ResourceManager *resman = ResourceManager::getInstance();
int size;
@@ -62,127 +62,105 @@ ItemManager::ItemManager(std::string itemReferenceFile)
LOG_ERROR("Item Manager: " << itemReferenceFile
<< " is not a valid database file!", 0);
}
-
- unsigned int nbItems = 0;
- for (node = node->xmlChildrenNode; node != NULL; node = node->next)
+ else
{
- // Properties
- unsigned int id = 0;
- unsigned short itemType = 0;
- unsigned int weight = 0;
- unsigned int value = 0;
- std::string scriptName = "";
- Modifiers modifiers;
-
- if (!xmlStrEqual(node->name, BAD_CAST "item")) {
- continue;
- }
-
- xmlChar *prop = NULL;
- // Properties
- READ_PROP(node, prop, "id", id, atoi);
- READ_PROP(node, prop, "type", itemType, atoi);
- READ_PROP(node, prop, "weight", weight, atoi);
- READ_PROP(node, prop, "value", value, atoi);
- READ_PROP(node, prop, "script_name", scriptName, );
-
- // --- Modifiers
- // General
- READ_PROP(node, prop, "element", modifiers.element, (Element)atoi);
- READ_PROP(node, prop, "lifetime", modifiers.lifetime, atoi);
- // Raw Statistics
- READ_PROP(node, prop, "strength", modifiers.rawStats[STAT_STRENGTH], atoi);
- READ_PROP(node, prop, "agility", modifiers.rawStats[STAT_AGILITY], atoi);
- READ_PROP(node, prop, "vitality", modifiers.rawStats[STAT_VITALITY], atoi);
- READ_PROP(node, prop, "intelligence", modifiers.rawStats[STAT_INTELLIGENCE], atoi);
- READ_PROP(node, prop, "dexterity", modifiers.rawStats[STAT_DEXTERITY], atoi);
- READ_PROP(node, prop, "luck", modifiers.rawStats[STAT_LUCK], atoi);
- // Computed Statistics
- READ_PROP(node, prop, "heat", modifiers.computedStats[STAT_HEAT], atoi);
- READ_PROP(node, prop, "attack", modifiers.computedStats[STAT_ATTACK], atoi);
- READ_PROP(node, prop, "defence", modifiers.computedStats[STAT_DEFENCE], atoi);
- READ_PROP(node, prop, "magic", modifiers.computedStats[STAT_MAGIC], atoi);
- READ_PROP(node, prop, "accuracy", modifiers.computedStats[STAT_ACCURACY], atoi);
- READ_PROP(node, prop, "speed", modifiers.computedStats[STAT_SPEED], atoi);
- // Main Values
- READ_PROP(node, prop, "hp", modifiers.hpMod, atoi);
- READ_PROP(node, prop, "mp", modifiers.mpMod, atoi);
- // Equipment
- READ_PROP(node, prop, "range", modifiers.range, atoi);
- // Status effects addition
- READ_PROP(node, prop, "status_normal",
- modifiers.beingStateEffects.STATE_NORMAL, (bool)atoi);
- READ_PROP(node, prop, "status_poisoned",
- modifiers.beingStateEffects.STATE_POISONED, (bool)atoi);
- READ_PROP(node, prop, "status_stoned",
- modifiers.beingStateEffects.STATE_STONED, (bool)atoi);
- READ_PROP(node, prop, "status_stunned",
- modifiers.beingStateEffects.STATE_STUNNED, (bool)atoi);
- READ_PROP(node, prop, "status_slowed",
- modifiers.beingStateEffects.STATE_SLOWED, (bool)atoi);
- READ_PROP(node, prop, "status_tired",
- modifiers.beingStateEffects.STATE_TIRED, (bool)atoi);
- READ_PROP(node, prop, "status_mad",
- modifiers.beingStateEffects.STATE_MAD, (bool)atoi);
- READ_PROP(node, prop, "status_berserk",
- modifiers.beingStateEffects.STATE_BERSERK, (bool)atoi);
- READ_PROP(node, prop, "status_hasted",
- modifiers.beingStateEffects.STATE_HASTED, (bool)atoi);
- READ_PROP(node, prop, "status_floating",
- modifiers.beingStateEffects.STATE_FLOATING, (bool)atoi);
- // Status Effects deletion
- READ_PROP(node, prop, "status_not_poisoned",
- modifiers.beingStateEffects.STATE_NOT_POISONED, (bool)atoi);
- READ_PROP(node, prop, "status_not_stoned",
- modifiers.beingStateEffects.STATE_NOT_STONED, (bool)atoi);
- READ_PROP(node, prop, "status_not_stunned",
- modifiers.beingStateEffects.STATE_NOT_STUNNED, (bool)atoi);
- READ_PROP(node, prop, "status_not_slowed",
- modifiers.beingStateEffects.STATE_NOT_SLOWED, (bool)atoi);
- READ_PROP(node, prop, "status_not_tired",
- modifiers.beingStateEffects.STATE_NOT_TIRED, (bool)atoi);
- READ_PROP(node, prop, "status_not_mad",
- modifiers.beingStateEffects.STATE_NOT_MAD, (bool)atoi);
- READ_PROP(node, prop, "status_not_berserk",
- modifiers.beingStateEffects.STATE_NOT_BERSERK, (bool)atoi);
- READ_PROP(node, prop, "status_not_hasted",
- modifiers.beingStateEffects.STATE_NOT_HASTED, (bool)atoi);
- READ_PROP(node, prop, "status_not_floating",
- modifiers.beingStateEffects.STATE_NOT_FLOATING, (bool)atoi);
-
- // Checks
- if (id != 0)
- {
- ItemPtr item(new Item(modifiers, itemType, weight, value, scriptName));
- mItemReference[id] = item;
- nbItems++;
- }
-
- if (id == 0)
+ LOG_INFO("Loading item reference...", 0);
+ unsigned int nbItems = 0;
+ for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
- LOG_WARN("Item Manager: An (ignored) item has no ID in "
- << itemReferenceFile << "!", 0);
- }
- if (itemType == 0)
- {
- LOG_WARN("Item Manager: Missing Item Type for item: "
- << id << " in " << itemReferenceFile << ".", 0);
- }
- if (weight == 0)
- {
- LOG_WARN("Item Manager: Missing weight for item: "
- << id << " in " << itemReferenceFile << ".", 0);
+ // Properties
+ unsigned int id = 0;
+ unsigned short itemType = 0;
+ unsigned int weight = 0;
+ unsigned int value = 0;
+ std::string scriptName = "";
+ Modifiers modifiers;
+
+ if (!xmlStrEqual(node->name, BAD_CAST "item")) {
+ continue;
+ }
+
+ xmlChar *prop = NULL;
+ // Properties
+ READ_PROP(node, prop, "id", id, atoi);
+ READ_PROP(node, prop, "type", itemType, atoi);
+ READ_PROP(node, prop, "weight", weight, atoi);
+ READ_PROP(node, prop, "value", value, atoi);
+ READ_PROP(node, prop, "script_name", scriptName, );
+
+ // --- Modifiers
+ // General
+ READ_PROP(node, prop, "element", modifiers.element,
+ (Element)atoi);
+ READ_PROP(node, prop, "lifetime", modifiers.lifetime, atoi);
+ // Raw Statistics
+ READ_PROP(node, prop, "strength",
+ modifiers.rawStats[STAT_STRENGTH], atoi);
+ READ_PROP(node, prop, "agility",
+ modifiers.rawStats[STAT_AGILITY], atoi);
+ READ_PROP(node, prop, "vitality",
+ modifiers.rawStats[STAT_VITALITY], atoi);
+ READ_PROP(node, prop, "intelligence",
+ modifiers.rawStats[STAT_INTELLIGENCE], atoi);
+ READ_PROP(node, prop, "dexterity",
+ modifiers.rawStats[STAT_DEXTERITY], atoi);
+ READ_PROP(node, prop, "luck",
+ modifiers.rawStats[STAT_LUCK], atoi);
+ // Computed Statistics
+ READ_PROP(node, prop, "heat",
+ modifiers.computedStats[STAT_HEAT], atoi);
+ READ_PROP(node, prop, "attack",
+ modifiers.computedStats[STAT_ATTACK], atoi);
+ READ_PROP(node, prop, "defence",
+ modifiers.computedStats[STAT_DEFENCE], atoi);
+ READ_PROP(node, prop, "magic",
+ modifiers.computedStats[STAT_MAGIC], atoi);
+ READ_PROP(node, prop, "accuracy",
+ modifiers.computedStats[STAT_ACCURACY], atoi);
+ READ_PROP(node, prop, "speed",
+ modifiers.computedStats[STAT_SPEED], atoi);
+ // Main Values
+ READ_PROP(node, prop, "hp", modifiers.hp, atoi);
+ READ_PROP(node, prop, "mp", modifiers.mp, atoi);
+ // Equipment
+ READ_PROP(node, prop, "range", modifiers.range, atoi);
+ // Status effect
+ READ_PROP(node, prop, "status_effect",
+ modifiers.beingStateEffect, (BeingStateEffect)atoi);
+
+ // Checks
+ if (id != 0)
+ {
+ ItemPtr item(new Item(modifiers, itemType, weight,
+ value, scriptName));
+ mItemReference[id] = item;
+ nbItems++;
+ }
+
+ if (id == 0)
+ {
+ LOG_WARN("Item Manager: An (ignored) item has no ID in "
+ << itemReferenceFile << "!", 0);
+ }
+ if (weight == 0)
+ {
+ LOG_WARN("Item Manager: Missing weight for item: "
+ << id << " in " << itemReferenceFile << ".", 0);
+ }
+
+ LOG_INFO("Item: ID: " << id << ", itemType: " << itemType
+ << ", weight: " << weight << ", value: " << value <<
+ ", scriptName: " << scriptName << ".", 3);
+ //TODO: Log level 5 with everything
}
- LOG_INFO("Item: ID: " << id << ", itemType: " << itemType
- << ", weight: " << weight << ", value: " << value <<
- ", scriptName: " << scriptName << ".", 3);
- //TODO: Log level 5 with everything
- }
+ LOG_INFO("Loaded " << nbItems << " items from "
+ << itemReferenceFile << ".", 0);
- LOG_INFO("Loaded " << nbItems << " items from " << itemReferenceFile << ".", 0);
+ } // End if node "items"
xmlFreeDoc(doc);
+
} // End if doc?
} // End if data?
}
diff --git a/src/main.cpp b/src/main.cpp
index 9516efbd..08475d4a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -76,8 +76,6 @@ std::string scriptLanugage = "none";
#define DEFAULT_LOG_FILE "tmwserv.log"
#define DEFAULT_CONFIG_FILE "tmwserv.xml"
#define DEFAULT_ITEMSDB_FILE "items.xml"
-#define DEFAULT_MAP_FOLDER "maps"
-#define DEFAULT_DATA_FOLDER "data"
#ifndef DEFAULT_SERVER_PORT
#define DEFAULT_SERVER_PORT 9601
// Meaning Account Handler Port is 9601
@@ -177,7 +175,7 @@ void initialize()
// Initialize the Chat channels manager
chatChannelManager = new ChatChannelManager();
// Initialize the Item Manager
- itemManager = new ItemManager(DEFAULT_DATA_FOLDER"/"DEFAULT_ITEMSDB_FILE);
+ itemManager = new ItemManager(DEFAULT_ITEMSDB_FILE);
// --- Initialize the global handlers
// FIXME: Make the global handlers global vars or part of a bigger