diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-05-22 13:02:47 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-05-22 13:02:47 +0000 |
commit | 0c6830040481247a96ccc8fe15f9b1022506c0ae (patch) | |
tree | 1d19cac108370e3dfdb421ad3f497d02d5ab3e4f | |
parent | c669ed4986b0a01abc78f6d793993d9081c6b49e (diff) | |
download | mana-0c6830040481247a96ccc8fe15f9b1022506c0ae.tar.gz mana-0c6830040481247a96ccc8fe15f9b1022506c0ae.tar.bz2 mana-0c6830040481247a96ccc8fe15f9b1022506c0ae.tar.xz mana-0c6830040481247a96ccc8fe15f9b1022506c0ae.zip |
An attemp on auto attack, not bug free for sure
-rw-r--r-- | src/being.cpp | 3 | ||||
-rw-r--r-- | src/engine.cpp | 2 | ||||
-rw-r--r-- | src/game.cpp | 32 | ||||
-rw-r--r-- | src/game.h | 1 | ||||
-rw-r--r-- | src/gui/gui.cpp | 2 | ||||
-rw-r--r-- | src/net/protocol.cpp | 23 | ||||
-rw-r--r-- | src/net/protocol.h | 3 |
7 files changed, 43 insertions, 23 deletions
diff --git a/src/being.cpp b/src/being.cpp index 8fe61f14..30e32b7c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -302,6 +302,9 @@ void Being::logic() frame = (get_elapsed_time(walk_time) * 4) / aspd; if (frame >= 4) { nextStep(); + if (autoTarget > 0 && this == player_node) { + attack(findNode(autoTarget)); + } } break; } diff --git a/src/engine.cpp b/src/engine.cpp index 2073c0d3..2049d53f 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -408,6 +408,8 @@ void Engine::draw() if (being->action == MONSTER_DEAD) { monsterset[being->job - 1002]->spriteset[dir + 4 * MONSTER_DEAD]->draw(screen, being->text_x + 30, being->text_y + 40); + if (autoTarget == being->id) + autoTarget = 0; } else { monsterset[being->job-1002]->spriteset[dir + 4 * mf]->draw( diff --git a/src/game.cpp b/src/game.cpp index f41651e2..5fe8354c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -53,6 +53,7 @@ int fps = 0, frame = 0, current_npc = 0; bool displayPathToMouse = false; int startX = 0, startY = 0; int gameTime = 0; +int autoTarget = 0; OkDialog *deathNotice = NULL; ConfirmDialog *exitConfirm = NULL; @@ -212,6 +213,10 @@ void do_exit() void do_input() { + // Get the state of the keyboard keys + Uint8* keys; + keys = SDL_GetKeyState(NULL); + // Events SDL_Event event; while (SDL_PollEvent(&event)) @@ -390,26 +395,11 @@ void do_input() } } else if (target->isMonster()) { - int dist_x = mx - player_node->x; - int dist_y = my - player_node->y; - if (abs(dist_y) >= abs(dist_x)) { - if (dist_y > 0) - player_node->direction = SOUTH; - else - player_node->direction = NORTH; - } else { - if (dist_x > 0) - player_node->direction = EAST; - else - player_node->direction = WEST; + if (keys[SDLK_LSHIFT]) { + if (target->action != MONSTER_DEAD) + autoTarget = target->id; } - 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"); + attack(target); } else if (target->isPlayer()) { // Begin a trade @@ -432,10 +422,6 @@ void do_input() } // End while - - // Get the state of the keyboard keys - Uint8* keys; - keys = SDL_GetKeyState(NULL); int xDirection = 0; int yDirection = 0; int Direction = DIR_NONE; @@ -62,6 +62,7 @@ extern volatile int tick_time; extern int server_tick; extern bool displayPathToMouse; extern int startX, startY; +extern int autoTarget; /** * Main game loop diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index ab818555..e3b5a0bb 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -128,5 +128,7 @@ void Gui::mousePress(int mx, int my, int button) walk(tilex, tiley, 0); player_node->setDestination(tilex, tiley); } + + autoTarget = 0; } } diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index e3b84457..7dc83cfa 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -248,3 +248,26 @@ void attack(unsigned short x, unsigned short y, unsigned char direction) // implement charging attacks here char_info->lastAttackTime = 0; } + +void attack(Being *target) { + int dist_x = target->x - player_node->x; + int dist_y = target->y - player_node->y; + if (abs(dist_y) >= abs(dist_x)) { + if (dist_y > 0) + player_node->direction = SOUTH; + else + player_node->direction = NORTH; + } else { + if (dist_x > 0) + player_node->direction = EAST; + else + player_node->direction = WEST; + } + 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"); +} diff --git a/src/net/protocol.h b/src/net/protocol.h index 14c21d59..dd6b36e2 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -83,6 +83,9 @@ void speak(char *speech); /** Request to attack */ void attack(unsigned short x, unsigned short y, unsigned char direction); +/** Request to attack */ +void attack(Being *target); + /** Request action */ void action(char type, int id); |