Atrinik Client  4.0
move.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
30 #include <global.h>
31 #include <toolkit/packet.h>
32 
36 #define DIRECTIONS_NUM 9
37 
41 static const int directions_fire[DIRECTIONS_NUM] = {
42  6, 5, 4, 7, 0, 3, 8, 1, 2
43 };
44 
45 void client_send_fire(int num, tag_t tag)
46 {
47  packet_struct *packet;
48 
49  packet = packet_new(SERVER_CMD_FIRE, 64, 64);
50  packet_append_uint8(packet, directions_fire[num - 1]);
51 
52  if (tag) {
53  packet_append_uint32(packet, tag);
54  }
55 
56  socket_send_packet(packet);
57 }
58 
59 void move_keys(int num)
60 {
61  if (cpl.fire_on) {
62  client_send_fire(num, 0);
63  } else {
64  packet_struct *packet;
65 
66  if (num == 5) {
67  packet = packet_new(SERVER_CMD_CLEAR, 0, 0);
68  socket_send_packet(packet);
69  } else {
70  packet = packet_new(SERVER_CMD_MOVE, 8, 0);
71  packet_append_uint8(packet, num ? directions_fire[num - 1] : 0);
72  packet_append_uint8(packet, cpl.run_on);
73  socket_send_packet(packet);
74  }
75  }
76 }
77 
89 int dir_from_tile_coords(int tx, int ty)
90 {
91  int player_tile_x = setting_get_int(OPT_CAT_MAP, OPT_MAP_WIDTH) / 2, player_tile_y = setting_get_int(OPT_CAT_MAP, OPT_MAP_HEIGHT) / 2;
92  int q, x, y;
93 
94  if (tx == player_tile_x && ty == player_tile_y) {
95  return 5;
96  }
97 
98  x = -(tx - player_tile_x);
99  y = -(ty - player_tile_y);
100 
101  if (!y) {
102  q = -300 * x;
103  } else {
104  q = x * 100 / y;
105  }
106 
107  if (y > 0) {
108  /* East */
109  if (q < -242) {
110  return 6;
111  }
112 
113  /* Northeast */
114  if (q < -41) {
115  return 9;
116  }
117 
118  /* North */
119  if (q < 41) {
120  return 8;
121  }
122 
123  /* Northwest */
124  if (q < 242) {
125  return 7;
126  }
127 
128  /* West */
129  return 4;
130  }
131 
132  /* West */
133  if (q < -242) {
134  return 4;
135  }
136 
137  /* Southwest */
138  if (q < -41) {
139  return 1;
140  }
141 
142  /* South */
143  if (q < 41) {
144  return 2;
145  }
146 
147  /* Southeast */
148  if (q < 242) {
149  return 3;
150  }
151 
152  /* East */
153  return 6;
154 }
static const int directions_fire[DIRECTIONS_NUM]
Definition: move.c:41
uint8_t fire_on
Definition: player.h:155
Client_Player cpl
Definition: client.c:50
int64_t setting_get_int(int cat, int setting)
Definition: settings.c:414
uint8_t run_on
Definition: player.h:158
int dir_from_tile_coords(int tx, int ty)
Definition: move.c:89
#define DIRECTIONS_NUM
Definition: move.c:36