summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-30 13:29:45 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-30 13:29:45 +0000
commitad3623ced5020c9c886cb85100ae05efa460f84a (patch)
tree2f01f33e4bf0f5e20f81a7d3f64cd6466381df95
parent22799314e68a0535f65cc7aa56c490cdde7ca544 (diff)
downloadmana-ad3623ced5020c9c886cb85100ae05efa460f84a.tar.gz
mana-ad3623ced5020c9c886cb85100ae05efa460f84a.tar.bz2
mana-ad3623ced5020c9c886cb85100ae05efa460f84a.tar.xz
mana-ad3623ced5020c9c886cb85100ae05efa460f84a.zip
Some fixes to player control, also attempting to solve long walk path problem.
-rw-r--r--ChangeLog2
-rw-r--r--src/being.cpp30
-rw-r--r--src/game.cpp155
-rw-r--r--src/gui/chat.cpp8
-rw-r--r--src/gui/gui.cpp6
-rw-r--r--src/map.cpp7
6 files changed, 126 insertions, 82 deletions
diff --git a/ChangeLog b/ChangeLog
index cf2442d4..eb0c7628 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,8 @@
- Fixed speech and emoticons position
- Fixed speech and damage display to be framerate independent
- Fixed rendering of some monsters and items in OpenGL mode
+- Fixed skipping with mouse walk and made interruptable with keyboard
+- Fixed mouse walk when dead or talking with NPC
0.0.11.2 (8 April 2005)
- Damage text now floats upwards
diff --git a/src/being.cpp b/src/being.cpp
index 0ef1e15f..90819f70 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -37,7 +37,8 @@ PATH_NODE::PATH_NODE(unsigned short x, unsigned short y):
{
}
-void add_node(Being *being) {
+void add_node(Being *being)
+{
beings.push_back(being);
// If the being is a player, request the name
if (being-> job < 10) {
@@ -59,10 +60,10 @@ void add_node(Being *being) {
monsterset[being->job - 1002] = new Spriteset(monsterbitmap, 60, 60);
}
}
-
}
-void remove_node(unsigned int id) {
+void remove_node(unsigned int id)
+{
std::list<Being *>::iterator i;
for (i = beings.begin(); i != beings.end(); i++) {
if ((*i)->id == id) {
@@ -73,7 +74,8 @@ void remove_node(unsigned int id) {
}
}
-unsigned int findNpc(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 +89,8 @@ unsigned int findNpc(unsigned short x, unsigned short y) {
return 0;
}
-unsigned int findPlayer(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 +102,8 @@ unsigned int findPlayer(unsigned short x, unsigned short y) {
return 0;
}
-unsigned int findMonster(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 +118,8 @@ unsigned int findMonster(unsigned short x, unsigned short y) {
return 0;
}
-Being *findNode(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,7 +130,8 @@ Being *findNode(unsigned int id) {
return NULL;
}
-Being *findNode(unsigned short x, unsigned short y) {
+Being *findNode(unsigned short x, unsigned short y)
+{
std::list<Being*>::iterator i;
for (i = beings.begin(); i != beings.end(); i++) {
Being *being = (*i);
@@ -179,8 +185,12 @@ void Being::clearPath()
void Being::setPath(std::list<PATH_NODE> path)
{
this->path = path;
- nextStep();
- walk_time = tick_time;
+
+ if (action != WALK)
+ {
+ nextStep();
+ walk_time = tick_time;
+ }
}
void Being::setDestination(int destX, int destY)
diff --git a/src/game.cpp b/src/game.cpp
index 87c59354..b079135c 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -209,7 +209,7 @@ void do_input()
used = true;
}
}
-
+
if ((keysym.sym == SDLK_F5) && action_time)
{
if (player_node->action == STAND)
@@ -285,7 +285,7 @@ void do_input()
{
state = EXIT;
}
-
+
if (keysym.sym == SDLK_g)
{
// Get the item code
@@ -404,7 +404,7 @@ void do_input()
int yDirection = 0;
int Direction = DIR_NONE;
- if (walk_status == 0 && player_node->action != DEAD && current_npc == 0)
+ if (player_node->action != DEAD && current_npc == 0)
{
int x = player_node->x;
int y = player_node->y;
@@ -447,66 +447,76 @@ void do_input()
yDirection = -1;
}
- // Translate movement to direction
- if (xDirection == 1 && yDirection == 0) // Right
- {
- Direction = EAST;
- }
- if (xDirection == -1 && yDirection == 0) // Left
- {
- Direction = WEST;
- }
- if (xDirection == 0 && yDirection == -1) // Up
- {
- Direction = NORTH;
- }
- if (xDirection == 0 && yDirection == 1) // Down
- {
- Direction = SOUTH;
- }
- if (xDirection == 1 && yDirection == 1) // Bottom-Right
- {
- Direction = SE;
- }
- if (xDirection == -1 && yDirection == -1) // Top-left
- {
- Direction = NW;
- }
- if (xDirection == 1 && yDirection == -1) // Top-Right
- {
- Direction = NE;
- }
- if (xDirection == -1 && yDirection == 1) // Bottom-Left
+ // Allow keyboard control to interrupt an existing path
+ if ((xDirection != 0 || yDirection != 0) &&
+ player_node->action == WALK)
{
- Direction = SW;
+ player_node->setDestination(player_node->x, player_node->y);
}
- // Update the player direction to where he wants to walk
- // Warning: Not communicated to the server yet
- if (Direction != DIR_NONE) {
- player_node->direction = Direction;
- }
+ if (player_node->action != WALK)
+ {
+ // Translate movement to direction
+ if (xDirection == 1 && yDirection == 0) // Right
+ {
+ Direction = EAST;
+ }
+ if (xDirection == -1 && yDirection == 0) // Left
+ {
+ Direction = WEST;
+ }
+ if (xDirection == 0 && yDirection == -1) // Up
+ {
+ Direction = NORTH;
+ }
+ if (xDirection == 0 && yDirection == 1) // Down
+ {
+ Direction = SOUTH;
+ }
+ if (xDirection == 1 && yDirection == 1) // Bottom-Right
+ {
+ Direction = SE;
+ }
+ if (xDirection == -1 && yDirection == -1) // Top-left
+ {
+ Direction = NW;
+ }
+ if (xDirection == 1 && yDirection == -1) // Top-Right
+ {
+ Direction = NE;
+ }
+ if (xDirection == -1 && yDirection == 1) // Bottom-Left
+ {
+ Direction = SW;
+ }
- // Prevent skipping corners over colliding tiles
- if (xDirection != 0 && tiledMap->tileCollides(x + xDirection, y)) {
- xDirection = 0;
- }
- if (yDirection != 0 && tiledMap->tileCollides(x, y + yDirection)) {
- yDirection = 0;
- }
+ // Prevent skipping corners over colliding tiles
+ if (xDirection != 0 && tiledMap->tileCollides(x + xDirection, y)) {
+ xDirection = 0;
+ }
+ if (yDirection != 0 && tiledMap->tileCollides(x, y + yDirection)) {
+ yDirection = 0;
+ }
- // Choose a straight direction when diagonal target is blocked
- if (yDirection != 0 && xDirection != 0 &&
- !tiledMap->getWalk(x + xDirection, y + yDirection)) {
- xDirection = 0;
- }
+ // Choose a straight direction when diagonal target is blocked
+ if (yDirection != 0 && xDirection != 0 &&
+ !tiledMap->getWalk(x + xDirection, y + yDirection)) {
+ xDirection = 0;
+ }
- // Walk to where the player can actually go
- if ((xDirection != 0 || yDirection != 0) &&
- tiledMap->getWalk(x + xDirection, y + yDirection))
- {
- walk(x + xDirection, y + yDirection, Direction);
- player_node->setDestination(x + xDirection, y + yDirection);
+ // Walk to where the player can actually go
+ if ((xDirection != 0 || yDirection != 0) &&
+ tiledMap->getWalk(x + xDirection, y + yDirection))
+ {
+ walk(x + xDirection, y + yDirection, Direction);
+ player_node->setDestination(x + xDirection, y + yDirection);
+ }
+ else if (Direction != DIR_NONE)
+ {
+ // Update the player direction to where he wants to walk
+ // Warning: Not communicated to the server yet
+ player_node->direction = Direction;
+ }
}
if (player_node->action == STAND)
@@ -759,13 +769,13 @@ void do_parse()
npcTextDialog->setVisible(true);
current_npc = RFIFOL(4);
break;
-
+
// Trade: Receiving a request to trade
case 0x00e5:
//printf("Getting a call from %s\n", RFIFOP(2));
requestTradeDialog->request(RFIFOP(2));
break;
-
+
// Trade: Response
case 0x00e7:
switch (RFIFOB(2)) {
@@ -831,15 +841,16 @@ void do_parse()
break;
case 1:
// Add item failed - player overweighted
- chatWindow->chat_log("Failed adding item. Trade partner is over weighted.",
- BY_SERVER);
+ chatWindow->chat_log("Failed adding item. Trade "
+ "partner is over weighted.", BY_SERVER);
break;
default:
//printf("Unhandled 0x00ea byte!\n");
break;
}
break;
- // Trade: Received Ok message
+
+ // Trade received Ok message
case 0x00ec:
switch (RFIFOB(2)) {
// Received ok from myself
@@ -852,27 +863,29 @@ void do_parse()
break;
}
break;
- // Trade: Trade cancelled
+
+ // Trade cancelled
case 0x00ee:
chatWindow->chat_log("Trade cancelled.", BY_SERVER);
tradeWindow->setVisible(false);
tradeWindow->reset();
break;
-
- // Trade: Trade completed
+
+ // Trade completed
case 0x00f0:
chatWindow->chat_log("Trade completed.", BY_SERVER);
tradeWindow->setVisible(false);
tradeWindow->reset();
break;
-
+
// Get the items
// Only called on map load / warp
case 0x01ee:
// Reset all items to not load them twice on map change
inventoryWindow->items->resetItems();
-
- for (int loop = 0; loop < (RFIFOW(2) - 4) / 18; loop++) {
+
+ for (int loop = 0; loop < (RFIFOW(2) - 4) / 18; loop++)
+ {
inventoryWindow->addItem(RFIFOW(4 + loop * 18),
RFIFOW(4 + loop * 18 + 2),
RFIFOW(4 + loop * 18 + 6), false);
@@ -889,7 +902,8 @@ void do_parse()
// Get the equipments
case 0x00a4:
- for (int loop = 0; loop < (RFIFOW(2) - 4) / 20; loop++) {
+ for (int loop = 0; loop < (RFIFOW(2) - 4) / 20; loop++)
+ {
inventoryWindow->addItem(RFIFOW(4 + loop * 20),
RFIFOW(4 + loop * 20 + 2), 1, true);
/*char info[40];
@@ -899,7 +913,8 @@ void do_parse()
RFIFOW(4+loop*20+6), RFIFOW(4+loop*20+8),
RFIFOB(4+loop*20+10), RFIFOB(4+loop*20+11));
chatWindow->chat_log(info, BY_SERVER);*/
- if(RFIFOW(4+loop*20+8)) {
+ if (RFIFOW(4 + loop * 20 + 8))
+ {
int mask = 1;
int position = 0;
while(!(RFIFOW(4+loop*20+8) & mask)) {
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 49841623..380d9d13 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -213,13 +213,21 @@ void ChatWindow::action(const std::string& eventId)
std::string message = chatInput->getText();
if (message.length() > 0) {
+ // If message different from previous, put it in the history
if (history.size() == 0 || message != history.back()) {
history.push_back(message);
}
+
+ // Reset history iterator
curHist = history.end();
+
+ // Send the message to the server
chat_send(char_info[0].name, message.c_str());
+
+ // Clear the text from the chat input
chatInput->setText("");
}
+
gui->focusNone();
}
}
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index d9ab90bd..5ef31a78 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -101,9 +101,11 @@ void Gui::draw()
void Gui::mousePress(int mx, int my, int button)
{
// Mouse pressed on window container (basically, the map)
- // Experimental mouse walk support
- if (button == gcn::MouseInput::LEFT) {
+ // When conditions for walking are met, set new player destination
+ if (player_node->action != DEAD && current_npc == 0 &&
+ button == gcn::MouseInput::LEFT)
+ {
int tilex = mx / 32 + camera_x;
int tiley = my / 32 + camera_y;
diff --git a/src/map.cpp b/src/map.cpp
index a658d8c6..c27a29d6 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -367,6 +367,13 @@ std::list<PATH_NODE> Map::findPath(
// 14 for moving diagonal
int Gcost = curr.tile->Gcost + ((dx == 0 || dy == 0) ? 10 : 14);
+ // Skip if Gcost becomes too much
+ // Warning: probably not entirely accurate
+ if (Gcost > 200)
+ {
+ continue;
+ }
+
if (newTile->whichList != onOpenList)
{
// Found a new tile (not on open nor on closed list)