summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp3
-rw-r--r--src/engine.cpp2
-rw-r--r--src/game.cpp32
-rw-r--r--src/game.h1
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/net/protocol.cpp23
-rw-r--r--src/net/protocol.h3
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;
diff --git a/src/game.h b/src/game.h
index 4bbf1a2f..23c859f2 100644
--- a/src/game.h
+++ b/src/game.h
@@ -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);