summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-05-27 23:50:16 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-05-27 23:50:16 +0000
commit30063f42cc8d13ed241a52b90e63c2c68599115e (patch)
tree68868a0aa04007a0ad4a62d97556c27b48f057d7 /src
parent0ecae988adfa88cb6b8803a9f5b7215221fceb74 (diff)
downloadmana-client-30063f42cc8d13ed241a52b90e63c2c68599115e.tar.gz
mana-client-30063f42cc8d13ed241a52b90e63c2c68599115e.tar.bz2
mana-client-30063f42cc8d13ed241a52b90e63c2c68599115e.tar.xz
mana-client-30063f42cc8d13ed241a52b90e63c2c68599115e.zip
autoTarget is now a Being*, also may have fixed related crash and added label
to show current target.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp24
-rw-r--r--src/engine.cpp12
-rw-r--r--src/game.cpp19
-rw-r--r--src/game.h3
-rw-r--r--src/gui/skill.cpp6
-rw-r--r--src/net/protocol.cpp16
-rw-r--r--src/net/protocol.h2
-rw-r--r--src/resources/image.cpp5
-rw-r--r--src/sound.cpp9
9 files changed, 58 insertions, 38 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 30e32b7c..e6435487 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -67,8 +67,13 @@ void add_node(Being *being)
void remove_node(unsigned int id)
{
std::list<Being *>::iterator i;
- for (i = beings.begin(); i != beings.end(); i++) {
- if ((*i)->id == id) {
+ for (i = beings.begin(); i != beings.end(); i++)
+ {
+ if ((*i)->id == id)
+ {
+ if (autoTarget == (*i)) {
+ autoTarget = NULL;
+ }
delete (*i);
beings.erase(i);
return;
@@ -302,8 +307,8 @@ void Being::logic()
frame = (get_elapsed_time(walk_time) * 4) / aspd;
if (frame >= 4) {
nextStep();
- if (autoTarget > 0 && this == player_node) {
- attack(findNode(autoTarget));
+ if (autoTarget && this == player_node) {
+ attack(autoTarget);
}
}
break;
@@ -335,9 +340,14 @@ void Being::drawSpeech(Graphics *graphics)
}
if (showDamage) {
graphics->drawText(damage,
- text_x + 60,
- text_y - 60 - get_elapsed_time(damage_time) / 100,
- gcn::Graphics::CENTER);
+ text_x + 60,
+ text_y - 60 - get_elapsed_time(damage_time) / 100,
+ gcn::Graphics::CENTER);
+ }
+ if (this == autoTarget) {
+ graphics->drawText("[TARGET]",
+ text_x + 60, text_y,
+ gcn::Graphics::CENTER);
}
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 938068b7..75d4ba2f 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -267,7 +267,11 @@ void Engine::logic()
being->logic();
- if (being->action == MONSTER_DEAD && being->frame >= 20) {
+ if (being->action == MONSTER_DEAD && being->frame >= 20)
+ {
+ if (autoTarget == being) {
+ autoTarget = NULL;
+ }
delete being;
beingIterator = beings.erase(beingIterator);
}
@@ -400,8 +404,10 @@ 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;
+
+ if (autoTarget == being) {
+ autoTarget = NULL;
+ }
}
else {
monsterset[being->job-1002]->spriteset[dir + 4 * mf]->draw(
diff --git a/src/game.cpp b/src/game.cpp
index 3865b575..9193e821 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -21,7 +21,6 @@
* $Id$
*/
-#include "being.h"
#include "engine.h"
#include "floor_item.h"
#include "graphics.h"
@@ -54,7 +53,7 @@ int fps = 0, frame = 0, current_npc = 0;
bool displayPathToMouse = false;
int startX = 0, startY = 0;
int gameTime = 0;
-int autoTarget = 0;
+Being* autoTarget = NULL;
OkDialog *deathNotice = NULL;
ConfirmDialog *exitConfirm = NULL;
@@ -217,7 +216,7 @@ void do_input()
// Get the state of the keyboard keys
Uint8* keys;
keys = SDL_GetKeyState(NULL);
-
+
// Events
SDL_Event event;
while (SDL_PollEvent(&event))
@@ -385,7 +384,7 @@ void do_input()
Being *target = findNode(mx, my);
if (target) {
if (target->isNpc()) {
- // Check if no conflicting npc window is open
+ // Check if no conflicting NPC window is open
if (current_npc == 0)
{
WFIFOW(0) = net_w_value(0x0090);
@@ -397,8 +396,9 @@ void do_input()
}
else if (target->isMonster()) {
if (keys[SDLK_LSHIFT]) {
- if (target->action != MONSTER_DEAD)
- autoTarget = target->id;
+ if (target->action != MONSTER_DEAD) {
+ autoTarget = target;
+ }
}
attack(target);
}
@@ -548,10 +548,11 @@ void do_input()
if (keys[SDLK_LCTRL])
{
player_node->action = ATTACK;
- int monsterId = attack(player_node->x,
+ Being *monster = attack(player_node->x,
player_node->y, player_node->direction);
- if (keys[SDLK_LSHIFT])
- autoTarget = monsterId;
+ if (keys[SDLK_LSHIFT]) {
+ autoTarget = monster;
+ }
}
}
}
diff --git a/src/game.h b/src/game.h
index 23c859f2..54d11b01 100644
--- a/src/game.h
+++ b/src/game.h
@@ -25,6 +25,7 @@
#define _TMW_GAME_H
#include "main.h"
+#include "being.h"
#include "./gui/gui.h"
#include "./gui/skill.h"
#include <stdio.h>
@@ -62,7 +63,7 @@ extern volatile int tick_time;
extern int server_tick;
extern bool displayPathToMouse;
extern int startX, startY;
-extern int autoTarget;
+extern Being* autoTarget;
/**
* Main game loop
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 8c22af55..e511a24e 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -107,10 +107,8 @@ void SkillDialog::action(const std::string& eventId)
{
// Increment skill
int selectedSkill = skillListBox->getSelected();
- std::cout << "SkillDialog::action(" << selectedSkill << ")\n";
- if (char_info->skill_point > 0 && selectedSkill >= 0) {
- std::cout << "Sending upgrade of id " <<
- skillList[selectedSkill]->id << "\n";
+ if (char_info->skill_point > 0 && selectedSkill >= 0)
+ {
WFIFOW(0) = net_w_value(0x0112);
WFIFOW(2) = net_w_value(
skillList[selectedSkill]->id);
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);
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 59745894..2669059e 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -55,12 +55,9 @@ Image* Image::load(void* buffer, unsigned int bufferSize, int flags)
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
- // Use SDL_Image to load the raw image data
+ // Use SDL_Image to load the raw image data and have it free the data
SDL_Surface* tmpImage = IMG_Load_RW(rw, 1);
- // Now free the SDL_RWops data
- //SDL_FreeRW(rw);
-
#ifndef USE_OPENGL
SDL_Surface *image;
diff --git a/src/sound.cpp b/src/sound.cpp
index 78e949cb..b44ba077 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -69,7 +69,8 @@ void Sound::init()
installed = true;
}
-void Sound::info() {
+void Sound::info()
+{
SDL_version compiledVersion;
const SDL_version *linkedVersion;
char driver[40] = "Unknown";
@@ -102,9 +103,9 @@ void Sound::info() {
linkedVersion->minor,
linkedVersion->patch);
logger->log("Sound::info() Driver: %s", driver);
- logger->log("Sound::init() Format: %s", format);
- logger->log("Sound::init() Rate: %i", rate);
- logger->log("Sound::init() Channels: %i", channels);
+ logger->log("Sound::info() Format: %s", format);
+ logger->log("Sound::info() Rate: %i", rate);
+ logger->log("Sound::info() Channels: %i", channels);
}
void Sound::setMusicVolume(int volume)