summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-03 16:13:12 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-03 16:13:12 +0000
commit182b5231ba13a0a5865a1b7dcb4731c3009d4c57 (patch)
treed0f536d7c3357825efc5f527922c10487517e8bf /src
parentb48b39c87da9fc2c59be533e1dc445cc82c2f323 (diff)
downloadmana-client-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.tar.gz
mana-client-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.tar.bz2
mana-client-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.tar.xz
mana-client-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.zip
Some indent, comment and const parameter changes.
Diffstat (limited to 'src')
-rw-r--r--src/map.cpp96
-rw-r--r--src/map.h15
-rw-r--r--src/net/protocol.cpp288
-rw-r--r--src/net/protocol.h53
4 files changed, 237 insertions, 215 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 154f1adc..0687dd53 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -17,6 +17,8 @@
* You should have received a copy of the GNU General Public License
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
*/
#include "main.h"
@@ -33,26 +35,22 @@
MAP tiled_map;
-/** Loads a map file */
bool load_map(char *map_file) {
- PACKFILE *file = pack_fopen(map_file, "rp");
- if(!file) {
- warning(map_file);
- return false;
- }
- pack_fread(&tiled_map, sizeof(MAP), file);
- pack_fclose(file);
- return true;
+ PACKFILE *file = pack_fopen(map_file, "rp");
+ if (!file) {
+ warning(map_file);
+ return false;
+ }
+ pack_fread(&tiled_map, sizeof(MAP), file);
+ pack_fclose(file);
+ return true;
}
-
-/** Set walkability flag for a tile */
void set_walk(short x_c, short y_c, bool walkable) {
- if(walkable==true)tiled_map.tiles[x_c][y_c].data[3] |= 0x0002;
- else tiled_map.tiles[x_c][y_c].data[3] &= 0x00fd;
+ if (walkable == true) tiled_map.tiles[x_c][y_c].data[3] |= 0x0002;
+ else tiled_map.tiles[x_c][y_c].data[3] &= 0x00fd;
}
-/** Tell if a tile is walkable or not */
bool get_walk(short x_c, short y_c) {
bool ret = (tiled_map.tiles[x_c][y_c].data[3] & 0x0002)>0;
if(ret==true) {
@@ -66,57 +64,53 @@ bool get_walk(short x_c, short y_c) {
} else return false;
}
-/** Tell if a tile is walkable or not (0=walkable,1=not walkable) */
unsigned char get_path_walk(unsigned short x, unsigned short y) {
- if(get_walk(x, y))return 0;
- else return 1;
+ if (get_walk(x, y)) return 0;
+ else return 1;
}
-/** Tell if a tile is animated or not */
bool get_anim(short x_c, short y_c, char layer) {
- char temp = tiled_map.tiles[x_c][y_c].flags & 0x00C0;
- temp>>=6;
- if(abs(temp)==layer)return (tiled_map.tiles[x_c][y_c].data[3] & 0x0001)>0;
- else return false;
+ char temp = tiled_map.tiles[x_c][y_c].flags & 0x00C0;
+ temp >>= 6;
+ if(abs(temp)==layer)return (tiled_map.tiles[x_c][y_c].data[3] & 0x0001)>0;
+ else return false;
}
-/** Set tile ID */
void set_tile(short x_c, short y_c, char layer, unsigned short id) {
- if(layer==0) {
- id <<= 6;
+ if (layer == 0) {
+ id <<= 6;
tiled_map.tiles[x_c][y_c].data[0] = HIBYTE(id);
- tiled_map.tiles[x_c][y_c].data[1] &= 0x003f;
+ tiled_map.tiles[x_c][y_c].data[1] &= 0x003f;
tiled_map.tiles[x_c][y_c].data[1] |= LOBYTE(id);
- } else if(layer==1) {
- id <<= 4;
- tiled_map.tiles[x_c][y_c].data[1] &= 0x00c0;
- tiled_map.tiles[x_c][y_c].data[1] |= HIBYTE(id);
- tiled_map.tiles[x_c][y_c].data[2] &= 0x000f;
- tiled_map.tiles[x_c][y_c].data[2] |= LOBYTE(id);
- } else if(layer==2) {
- id <<= 2;
- tiled_map.tiles[x_c][y_c].data[2] &= 0x00f0;
- tiled_map.tiles[x_c][y_c].data[2] |= HIBYTE(id);
- tiled_map.tiles[x_c][y_c].data[3] &= 0x0003;
- tiled_map.tiles[x_c][y_c].data[3] |= LOBYTE(id);
- }
+ } else if (layer == 1) {
+ id <<= 4;
+ tiled_map.tiles[x_c][y_c].data[1] &= 0x00c0;
+ tiled_map.tiles[x_c][y_c].data[1] |= HIBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[2] &= 0x000f;
+ tiled_map.tiles[x_c][y_c].data[2] |= LOBYTE(id);
+ } else if (layer == 2) {
+ id <<= 2;
+ tiled_map.tiles[x_c][y_c].data[2] &= 0x00f0;
+ tiled_map.tiles[x_c][y_c].data[2] |= HIBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[3] &= 0x0003;
+ tiled_map.tiles[x_c][y_c].data[3] |= LOBYTE(id);
+ }
}
-/** Return tile ID */
unsigned short get_tile(short x_c, short y_c, char layer) {
- unsigned short id;
- if(layer==0) {
+ unsigned short id = 0;
+ if (layer == 0) {
id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[1] & 0x00c0,
tiled_map.tiles[x_c][y_c].data[0]);
id >>= 6;
- } else if(layer==1) {
- id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[2] & 0x00f0,
- tiled_map.tiles[x_c][y_c].data[1] & 0x003f);
- id >>= 4;
- } else if(layer==2) {
- id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[3] & 0x00fc,
- tiled_map.tiles[x_c][y_c].data[2] & 0x000f);
- id >>=2;
- }
+ } else if (layer == 1) {
+ id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[2] & 0x00f0,
+ tiled_map.tiles[x_c][y_c].data[1] & 0x003f);
+ id >>= 4;
+ } else if (layer == 2) {
+ id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[3] & 0x00fc,
+ tiled_map.tiles[x_c][y_c].data[2] & 0x000f);
+ id >>= 2;
+ }
return id;
}
diff --git a/src/map.h b/src/map.h
index 02dba1c3..323a00d0 100644
--- a/src/map.h
+++ b/src/map.h
@@ -17,6 +17,8 @@
* You should have received a copy of the GNU General Public License
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
*/
#ifndef _TMW_MAP_H
@@ -67,12 +69,25 @@ struct MAP {
char bg_music[20];
};
+/** Loads a map file */
bool load_map(char *map_file);
+
+/** Set walkability flag for a tile */
void set_walk(short x_c, short y_c, bool walkable);
+
+/** Tell if a tile is walkable or not */
bool get_walk(short x_c, short y_c);
+
+/** Tell if a tile is walkable or not (0=walkable,1=not walkable) */
unsigned char get_path_walk(unsigned short x, unsigned short y);
+
+/** Tell if a tile is animated or not */
bool get_anim(short x_c, short y_c, char layer);
+
+/** Set tile ID */
void set_tile(short x_c, short y_c, char layer, unsigned short id);
+
+/** Return tile ID */
unsigned short get_tile(short x_c, short y_c, char layer);
/** Return tile x coordinate in tileset */
diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp
index e1c1af9a..7b4c9ced 100644
--- a/src/net/protocol.cpp
+++ b/src/net/protocol.cpp
@@ -17,12 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
*/
#include "protocol.h"
short packet_lengths[] = {
-
10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -64,186 +65,165 @@ short packet_lengths[] = {
-1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
// #0x200
26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19,
-
};
-/** Packet length by id */
short get_length(short id) {
- return packet_lengths[id];
+ return packet_lengths[id];
}
-/** Decodes dest x coord */
-unsigned short get_dest_x(char *data) {
- short temp;
- temp = MAKEWORD(data[3], data[2] & 0x000f);
- temp >>= 2;
- return temp;
+unsigned short get_dest_x(const char *data) {
+ short temp;
+ temp = MAKEWORD(data[3], data[2] & 0x000f);
+ temp >>= 2;
+ return temp;
}
-/** Decodes dest y coord */
-unsigned short get_dest_y(char *data) {
- short temp;
- temp = MAKEWORD(data[4], data[3] & 0x0003);
- return temp;
+unsigned short get_dest_y(const char *data) {
+ return MAKEWORD(data[4], data[3] & 0x0003);
}
-/** Decodes src x coord */
-unsigned short get_src_x(char *data) {
- short temp;
- temp = MAKEWORD(data[1], data[0]);
- temp >>= 6;
- return temp;
+unsigned short get_src_x(const char *data) {
+ short temp;
+ temp = MAKEWORD(data[1], data[0]);
+ temp >>= 6;
+ return temp;
}
-/** Decodes src y coord */
-unsigned short get_src_y(char *data) {
- short temp;
- temp = MAKEWORD(data[2], data[1] & 0x003f);
- temp >>= 4;
- return temp;
+unsigned short get_src_y(const char *data) {
+ short temp;
+ temp = MAKEWORD(data[2], data[1] & 0x003f);
+ temp >>= 4;
+ return temp;
}
-/** Decodes src direction */
unsigned char get_src_direction(char data) {
- data >>= 4;
+ data >>= 4;
return data;
}
-/** Decodes dest direction */
unsigned char get_dest_direction(char data) {
- return data & 0x000f;
-}
-
-/** Decodes x coord */
-unsigned short get_x(char *data) {
- short temp;
- temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff);
- temp >>= 6;
- return temp;
-}
-
-/** Decodes y coord */
-unsigned short get_y(char *data) {
- short temp;
- if(!data)error("Corrupted data");
- temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f);
- if(!temp)error("Corrupted data");
- temp >>= 4;
- return temp;
-}
-
-/** Decodes direction */
-unsigned char get_direction(char *data) {
- char temp;
- temp = data[2] & 0x000f;
- return temp;
-}
-
-/** Encodes coords and direction in 3 bytes data */
-void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction) {
- short temp;
- temp = x;
- temp <<= 6;
- data[0] = 0;
- data[1] = 1;
- data[2] = 2;
- data[0] = HIBYTE(temp);
- data[1] = LOBYTE(temp);
- temp = y;
- temp <<= 4;
- data[1] |= HIBYTE(temp);
- data[2] = LOBYTE(temp);
- data[2] |= direction;
-}
-
-/** Initialize connection with map server */
+ return data & 0x000f;
+}
+
+unsigned short get_x(const char *data) {
+ short temp;
+ temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff);
+ temp >>= 6;
+ return temp;
+}
+
+unsigned short get_y(const char *data) {
+ short temp;
+ if(!data)error("Corrupted data");
+ temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f);
+ if(!temp)error("Corrupted data");
+ temp >>= 4;
+ return temp;
+}
+
+unsigned char get_direction(const char *data) {
+ return data[2] & 0x000f;
+}
+
+void set_coordinates(char *data, unsigned short x, unsigned short y,
+ unsigned char direction)
+{
+ short temp;
+ temp = x;
+ temp <<= 6;
+ data[0] = 0;
+ data[1] = 1;
+ data[2] = 2;
+ data[0] = HIBYTE(temp);
+ data[1] = LOBYTE(temp);
+ temp = y;
+ temp <<= 4;
+ data[1] |= HIBYTE(temp);
+ data[2] = LOBYTE(temp);
+ data[2] |= direction;
+}
+
void map_start() {
- // Connect to map server
- if(open_session(iptostring(map_address), map_port)==SOCKET_ERROR) {
- warning("Unable to connect to map server");
- state = LOGIN;
- ok("Error", "Unable to connect to map server");
- return;
- }
-
- // Send login infos
- WFIFOW(0) = net_w_value(0x0072);
- WFIFOL(2) = net_l_value(account_ID);
- WFIFOL(6) = net_l_value(char_ID);
- WFIFOL(10) = net_l_value(session_ID1);
- WFIFOL(14) = net_l_value(session_ID2);
- WFIFOB(18) = net_b_value(sex);
- WFIFOSET(19);
-
- while((in_size<4)||(out_size>0))flush();
- RFIFOSKIP(4);
-
- while(in_size<2)flush();
-
- if(RFIFOW(0)==0x0073) {
- while(in_size<11)flush();
- x = get_x(RFIFOP(6));
- y = get_y(RFIFOP(6));
- //direction = get_direction(RFIFOP(6));
- log("Protocol", "Player position: (%d, %d), Direction: %d",
- x, y, direction);
- RFIFOSKIP(11);
- } else if(0x0081) {
- warning("Map server D/C");
- } else error("Unknown packet: map_start");
- // Send "map loaded"
- WFIFOW(0) = net_w_value(0x007d);
- WFIFOSET(2);
- while(out_size>0)flush();
-}
-
-/** Requests to walk */
+ // Connect to map server
+ if(open_session(iptostring(map_address), map_port)==SOCKET_ERROR) {
+ warning("Unable to connect to map server");
+ state = LOGIN;
+ ok("Error", "Unable to connect to map server");
+ return;
+ }
+
+ // Send login infos
+ WFIFOW(0) = net_w_value(0x0072);
+ WFIFOL(2) = net_l_value(account_ID);
+ WFIFOL(6) = net_l_value(char_ID);
+ WFIFOL(10) = net_l_value(session_ID1);
+ WFIFOL(14) = net_l_value(session_ID2);
+ WFIFOB(18) = net_b_value(sex);
+ WFIFOSET(19);
+
+ while((in_size<4)||(out_size>0))flush();
+ RFIFOSKIP(4);
+
+ while(in_size<2)flush();
+
+ if(RFIFOW(0)==0x0073) {
+ while(in_size<11)flush();
+ x = get_x(RFIFOP(6));
+ y = get_y(RFIFOP(6));
+ //direction = get_direction(RFIFOP(6));
+ log("Protocol", "Player position: (%d, %d), Direction: %d",
+ x, y, direction);
+ RFIFOSKIP(11);
+ } else if(0x0081) {
+ warning("Map server D/C");
+ } else error("Unknown packet: map_start");
+ // Send "map loaded"
+ WFIFOW(0) = net_w_value(0x007d);
+ WFIFOSET(2);
+ while(out_size>0)flush();
+}
+
void walk(unsigned short x, unsigned short y, unsigned char direction) {
- char temp[3];
- set_coordinates(temp, x, y, direction);
- WFIFOW(0) = net_w_value(0x0085);
- memcpy(WFIFOP(2), temp, 3);
- WFIFOSET(5);
+ char temp[3];
+ set_coordinates(temp, x, y, direction);
+ WFIFOW(0) = net_w_value(0x0085);
+ memcpy(WFIFOP(2), temp, 3);
+ WFIFOSET(5);
}
-/** Request to speak */
void speak(char *speech) {
- int len = (int)strlen(speech);
- WFIFOW(0) = net_w_value(0x008c);
- WFIFOW(2) = net_w_value(len+4);
- memcpy(WFIFOP(4), speech, len);
- WFIFOSET(len+4);
+ int len = (int)strlen(speech);
+ WFIFOW(0) = net_w_value(0x008c);
+ WFIFOW(2) = net_w_value(len+4);
+ memcpy(WFIFOP(4), speech, len);
+ WFIFOSET(len + 4);
}
-/** Request action */
void action(char type, int id) {
- WFIFOW(0) = net_w_value(0x0089);
- WFIFOL(2) = net_l_value(id);
- WFIFOB(6) = net_b_value(type);
- WFIFOSET(7);
+ WFIFOW(0) = net_w_value(0x0089);
+ WFIFOL(2) = net_l_value(id);
+ WFIFOB(6) = net_b_value(type);
+ WFIFOSET(7);
}
-
-/** Request to attack */
void attack(unsigned short x, unsigned short y, unsigned char direction) {
- int monster_id = 0;
-
- if(direction==SOUTH) {
- monster_id = find_monster(x, y+1);
- if(monster_id!=0)
- action(0, monster_id);
- } else if(direction==WEST) {
- monster_id = find_monster(x-1, y);
- if(monster_id!=0)
- action(0, monster_id);
- } else if(direction==NORTH) {
- monster_id = find_monster(x, y-1);
- if(monster_id!=0)
- action(0, monster_id);
- } else if(direction==EAST) {
- monster_id = find_monster(x+1, y);
- if(monster_id!=0)
- action(0, monster_id);
- }
+ int monster_id = 0;
+
+ if (direction == SOUTH) {
+ monster_id = find_monster(x, y + 1);
+ if (monster_id != 0)
+ action(0, monster_id);
+ } else if(direction == WEST) {
+ monster_id = find_monster(x - 1, y);
+ if (monster_id != 0)
+ action(0, monster_id);
+ } else if(direction == NORTH) {
+ monster_id = find_monster(x, y - 1);
+ if (monster_id != 0)
+ action(0, monster_id);
+ } else if(direction==EAST) {
+ monster_id = find_monster(x + 1, y);
+ if (monster_id != 0)
+ action(0, monster_id);
+ }
}
-
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 374024e3..3a46e91f 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -17,14 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
*/
+#ifndef _TMW_PROTOCOL_H
+#define _TMW_PROTOCOL_H
+
#ifdef WIN32
#pragma warning (disable:4312)
#endif
-
-#ifndef _TMW_PROTOCOL_H
-#define _TMW_PROTOCOL_H
#include "../main.h"
#include "../being.h"
@@ -38,21 +40,52 @@
#endif
+/** Packet length by id */
short get_length(short id);
-unsigned short get_x(char *data);
-unsigned short get_y(char *data);
-unsigned char get_direction(char *data);
-unsigned short get_src_x(char *data);
-unsigned short get_src_y(char *data);
+
+/** Decodes x coord */
+unsigned short get_x(const char *data);
+
+/** Decodes y coord */
+unsigned short get_y(const char *data);
+
+/** Decodes direction */
+unsigned char get_direction(const char *data);
+
+/** Decodes src x coord */
+unsigned short get_src_x(const char *data);
+
+/** Decodes src y coord */
+unsigned short get_src_y(const char *data);
+
+/** Decodes src direction */
unsigned char get_src_direction(char data);
-unsigned short get_dest_x(char *data);
-unsigned short get_dest_y(char *data);
+
+/** Decodes dest x coord */
+unsigned short get_dest_x(const char *data);
+
+/** Decodes dest y coord */
+unsigned short get_dest_y(const char *data);
+
+/** Decodes dest direction */
unsigned char get_dest_direction(char data);
+
+/** Encodes coords and direction in 3 bytes data */
void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction);
+
+/** Initialize connection with map server */
void map_start();
+
+/** Requests to walk */
void walk(unsigned short x, unsigned short y, unsigned char direction);
+
+/** Request to speak */
void speak(char *speech);
+
+/** Request to attack */
void attack(unsigned short x, unsigned short y, unsigned char direction);
+
+/** Request action */
void action(char type, int id);
#endif