From 30063f42cc8d13ed241a52b90e63c2c68599115e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 27 May 2005 23:50:16 +0000 Subject: autoTarget is now a Being*, also may have fixed related crash and added label to show current target. --- src/net/protocol.cpp | 16 +++++++++++----- src/net/protocol.h | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/net') diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index 0187f69e..f357b103 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -224,7 +224,7 @@ void action(char type, int id) WFIFOSET(7); } -int attack(unsigned short x, unsigned short y, unsigned char direction) +Being* attack(unsigned short x, unsigned short y, unsigned char direction) { Being *target; @@ -237,32 +237,38 @@ int attack(unsigned short x, unsigned short y, unsigned char direction) } else if(direction==EAST) { target = findNode(x + 1, y); } + if (target && target->isMonster()) { attack(target); - return target->id; + return target; } // Implement charging attacks here char_info->lastAttackTime = 0; - return 0; + return NULL; } 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 (abs(dist_y) >= abs(dist_x)) + { if (dist_y > 0) player_node->direction = SOUTH; else player_node->direction = NORTH; - } else { + } + 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; diff --git a/src/net/protocol.h b/src/net/protocol.h index 57321d45..002b4b2f 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -83,7 +83,7 @@ void walk(unsigned short x, unsigned short y, unsigned char direction); void speak(char *speech); /** Request to attack */ -int attack(unsigned short x, unsigned short y, unsigned char direction); +Being* attack(unsigned short x, unsigned short y, unsigned char direction); /** Request to attack */ void attack(Being *target); -- cgit v1.2.3-70-g09d2