diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-22 19:53:22 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-04-22 19:53:22 +0000 |
commit | 5501c96d2c17f63e03b2e36d01d2b9cf64722f56 (patch) | |
tree | 6bbfc6f41fee58d6c99a23afadcd762579580a24 | |
parent | 87a4e3eea7865c37d3a73c60015988673b6178b5 (diff) | |
download | mana-5501c96d2c17f63e03b2e36d01d2b9cf64722f56.tar.gz mana-5501c96d2c17f63e03b2e36d01d2b9cf64722f56.tar.bz2 mana-5501c96d2c17f63e03b2e36d01d2b9cf64722f56.tar.xz mana-5501c96d2c17f63e03b2e36d01d2b9cf64722f56.zip |
Now you can attack with right mouse button, useful when using bow, need improvements though
-rw-r--r-- | src/being.cpp | 37 | ||||
-rw-r--r-- | src/being.h | 28 | ||||
-rw-r--r-- | src/game.cpp | 72 | ||||
-rw-r--r-- | src/gui/equipment.h | 4 | ||||
-rw-r--r-- | src/net/protocol.cpp | 8 |
5 files changed, 98 insertions, 51 deletions
diff --git a/src/being.cpp b/src/being.cpp index 1b2e595c..03649dc6 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -73,7 +73,7 @@ void remove_node(unsigned int id) { } } -unsigned int find_npc(unsigned short x, unsigned short y) { +unsigned int findNpc(unsigned short x, unsigned short y) { std::list<Being *>::iterator i; for (i = beings.begin(); i != beings.end(); i++) { Being *being = (*i); @@ -87,7 +87,7 @@ unsigned int find_npc(unsigned short x, unsigned short y) { return 0; } -unsigned int find_pc(unsigned short x, unsigned short y) { +unsigned int findPlayer(unsigned short x, unsigned short y) { std::list<Being *>::iterator i; for (i = beings.begin(); i != beings.end(); i++) { Being *being = (*i); @@ -99,7 +99,7 @@ unsigned int find_pc(unsigned short x, unsigned short y) { return 0; } -unsigned int find_monster(unsigned short x, unsigned short y) { +unsigned int findMonster(unsigned short x, unsigned short y) { std::list<Being*>::iterator i; for (i = beings.begin(); i != beings.end(); i++) { Being *being = (*i); @@ -114,7 +114,7 @@ unsigned int find_monster(unsigned short x, unsigned short y) { return 0; } -Being *find_node(unsigned int id) { +Being *findNode(unsigned int id) { std::list<Being*>::iterator i; for (i = beings.begin(); i != beings.end(); i++) { Being *being = (*i); @@ -125,6 +125,17 @@ Being *find_node(unsigned int id) { return NULL; } +Being *findNode(unsigned short x, unsigned short y) { + std::list<Being*>::iterator i; + for (i = beings.begin(); i != beings.end(); i++) { + Being *being = (*i); + if (being->x == x && being->y == y) { + return being; + } + } + return NULL; +} + class BeingCompare { public: bool operator() (const Being *a, const Being *b) const { @@ -281,3 +292,21 @@ void Being::drawSpeech(Graphics *graphics) gcn::Graphics::CENTER); } } + +bool Being::isPlayer() { + if (job < 10) + return true; + return false; +} + +bool Being::isNpc() { + if (job > 45 && job <126) + return true; + return false; +} + +bool Being::isMonster() { + if (job > 200) + return true; + return false; +} diff --git a/src/being.h b/src/being.h index 9e65793d..dc90942d 100644 --- a/src/being.h +++ b/src/being.h @@ -141,25 +141,43 @@ class Being { * Draws the speech text above the being. */ void drawSpeech(Graphics *graphics); + + /** + * Checks if the being is a player. + */ + bool isPlayer(); + + /** + * Checks if the being is a npc. + */ + bool isNpc(); + + /** + * Checks if the being is a monster. + */ + bool isMonster(); }; /** Add a Being to the list */ void add_node(Being *being); /** Return a specific id Being */ -Being *find_node(unsigned int id); +Being *findNode(unsigned int id); + +/** Return a being at specific coordinates */ +Being *findNode(unsigned short x, unsigned short y); /** Remove a Being */ void remove_node(unsigned int id); /** Find a NPC id based on its coordinates */ -unsigned int find_npc(unsigned short x, unsigned short y); +unsigned int findNpc(unsigned short x, unsigned short y); -/** Find a PC id based on its coordinates */ -unsigned int find_pc(unsigned short x, unsigned short y); +/** Find a PLAYER id based on its coordinates */ +unsigned int findPlayer(unsigned short x, unsigned short y); /** Find a MONSTER id based on its coordinates */ -unsigned int find_monster(unsigned short x, unsigned short y); +unsigned int findMonster(unsigned short x, unsigned short y); /** Sort beings in vertical order */ void sort(); diff --git a/src/game.cpp b/src/game.cpp index 534ac35e..10c2a63c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -343,35 +343,35 @@ void do_input() if (event.button.button == 3) { - // We click the right button - // NPC Call - int id = find_npc(mx, my); - if (id != 0) - { - // Check if no conflicting npc window is open - if (current_npc == 0) - { - WFIFOW(0) = net_w_value(0x0090); - WFIFOL(2) = net_l_value(id); - WFIFOB(6) = 0; - WFIFOSET(7); - current_npc = id; + Being *target = findNode(mx, my); + if (target) { + if (target->isNpc()) { + // Check if no conflicting npc window is open + if (current_npc == 0) + { + WFIFOW(0) = net_w_value(0x0090); + WFIFOL(2) = net_l_value(target->id); + WFIFOB(6) = 0; + WFIFOSET(7); + current_npc = target->id; + } } - } - else { - // Search for player character to trade with - - id = find_pc(mx, my); - if (id != 0) { + else if (target->isMonster()) { + player_node->action = ATTACK; + action(0, target->id); + player_node->walk_time = tick_time; + if (player_node->weapon == 2) + sound.playSfx("sfx/bow_shoot_1.ogg"); + else + sound.playSfx("sfx/fist-swish.ogg"); + } + else if (target->isPlayer()) { // Begin a trade WFIFOW(0) = net_w_value(0x00e4); - WFIFOL(2) = net_l_value(id); + WFIFOL(2) = net_l_value(target->id); WFIFOSET(6); } } - - - } } else if (event.type == SDL_QUIT) @@ -592,7 +592,7 @@ void do_parse() { temp = (char *)malloc(RFIFOW(2)-7); memset(temp, '\0', RFIFOW(2)-7); memcpy(temp, RFIFOP(8), RFIFOW(2)-8); - being = find_node(RFIFOL(4)); + being = findNode(RFIFOL(4)); if (being != NULL) { // White being->setSpeech(temp, SPEECH_TIME); @@ -633,7 +633,7 @@ void do_parse() { break; // Add new being / stop monster case 0x0078: - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being == NULL) { being = new Being(); @@ -664,7 +664,7 @@ void do_parse() { case SMSG_REMOVE_BEING: // A being should be removed or has died - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being != NULL) { if (RFIFOB(6) == 1) { // Death if (being->job > 110) { @@ -684,7 +684,7 @@ void do_parse() { case SMSG_PLAYER_UPDATE_1: case SMSG_PLAYER_UPDATE_2: // A message about a player, doesn't include movement. - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being == NULL) { being = new Being(); @@ -706,7 +706,7 @@ void do_parse() { case SMSG_MOVE_BEING: // A being nearby is moving - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being == NULL) { being = new Being(); @@ -731,7 +731,7 @@ void do_parse() { case SMSG_MOVE_PLAYER_BEING: // A nearby player being moves - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being == NULL) { being = new Being(); @@ -1039,7 +1039,7 @@ void do_parse() { break; // Stop walking case 0x0088: // Disabled because giving some problems - //if (being = find_node(RFIFOL(2))) { + //if (being = findNode(RFIFOL(2))) { // if (being->id!=player_node->id) { // char ids[20]; // sprintf(ids,"%i",RFIFOL(2)); @@ -1054,7 +1054,7 @@ void do_parse() { case 0x008a: switch (RFIFOB(26)) { case 0: // Damage - being = find_node(RFIFOL(6)); + being = findNode(RFIFOL(6)); if (being != NULL) { if (RFIFOW(22) == 0) { @@ -1068,7 +1068,7 @@ void do_parse() { } if (RFIFOL(2) != player_node->id) { // buggy - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being != NULL) { if (being->job<10) { being->action = ATTACK; @@ -1083,7 +1083,7 @@ void do_parse() { break; case 2: // Sit case 3: // Stand up - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being != NULL) { being->frame = 0; if (RFIFOB(26) == 2) { @@ -1126,7 +1126,7 @@ void do_parse() { break; // Emotion case 0x00c0: - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if(being) { being->emotion = RFIFOB(6); being->emotion_time = EMOTION_TIME; @@ -1325,7 +1325,7 @@ void do_parse() { break; case SMSG_CHANGE_BEING_LOOKS: - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being) { if (RFIFOB(6) == 6) { being->setHairColor(RFIFOB(7)); @@ -1510,7 +1510,7 @@ void do_parse() { break; // Get being name case 0x0095: - being = find_node(RFIFOL(2)); + being = findNode(RFIFOL(2)); if (being) strcpy(being->name, RFIFOP(6)); break; diff --git a/src/gui/equipment.h b/src/gui/equipment.h index 8dde09d6..60522b19 100644 --- a/src/gui/equipment.h +++ b/src/gui/equipment.h @@ -65,9 +65,9 @@ class EquipmentWindow : public Window, gcn::ActionListener { void removeEquipment(int index); void setInventoryIndex(int index, int inventoryIndex); - + int getInventoryIndex(int index); - + void setArrows(int id); EQUIPMENT_HOLDER equipments[10]; diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index d2f1bd77..d2761457 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -228,19 +228,19 @@ void attack(unsigned short x, unsigned short y, unsigned char direction) int monster_id = 0; if (direction == SOUTH) { - monster_id = find_monster(x, y + 1); + monster_id = findMonster(x, y + 1); if (monster_id != 0) action(0, monster_id); } else if(direction == WEST) { - monster_id = find_monster(x - 1, y); + monster_id = findMonster(x - 1, y); if (monster_id != 0) action(0, monster_id); } else if(direction == NORTH) { - monster_id = find_monster(x, y - 1); + monster_id = findMonster(x, y - 1); if (monster_id != 0) action(0, monster_id); } else if(direction==EAST) { - monster_id = find_monster(x + 1, y); + monster_id = findMonster(x + 1, y); if (monster_id != 0) action(0, monster_id); } |