|
Atrinik Client 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00030 #include <global.h> 00031 00034 #define DIRECTIONS_NUM 9 00035 00038 static const char *const directions_move[DIRECTIONS_NUM] = 00039 { 00040 "/sw", "/s", "/se", "/w", "/stay", "/e", "/nw", "/n", "/ne" 00041 }; 00042 00045 static const char *const directions_run[DIRECTIONS_NUM] = 00046 { 00047 "/run 6", "/run 5", "/run 4", "/run 7", "/run 9", "/run 3", "/run 8", "/run 1", "/run 2" 00048 }; 00049 00052 static const int directions_fire[DIRECTIONS_NUM] = 00053 { 00054 6, 5, 4, 7, 0, 3, 8, 1, 2 00055 }; 00056 00057 void move_keys(int num) 00058 { 00059 /* Runmode on, or ALT key trigger */ 00060 if ((cpl.runkey_on || cpl.run_on) && (!cpl.firekey_on && !cpl.fire_on)) 00061 { 00062 send_command(directions_run[num - 1]); 00063 } 00064 else if (cpl.firekey_on || cpl.fire_on) 00065 { 00066 SockList sl; 00067 char buf[MAX_BUF]; 00068 00069 sl.buf = (unsigned char *) buf; 00070 strcpy((char *) sl.buf, "fire "); 00071 sl.len = 5; 00072 SockList_AddChar(&sl, directions_fire[num - 1]); 00073 SockList_AddChar(&sl, RangeFireMode); 00074 00075 if (RangeFireMode == FIRE_MODE_SKILL) 00076 { 00077 if (!fire_mode_tab[FIRE_MODE_SKILL].skill) 00078 { 00079 draw_info(COLOR_WHITE, "No skill selected."); 00080 return; 00081 } 00082 00083 SockList_AddString(&sl, fire_mode_tab[RangeFireMode].skill->name); 00084 } 00085 else if (RangeFireMode == FIRE_MODE_SPELL) 00086 { 00087 if (!fire_mode_tab[FIRE_MODE_SPELL].spell) 00088 { 00089 draw_info(COLOR_WHITE, "No spell selected."); 00090 return; 00091 } 00092 00093 SockList_AddString(&sl, fire_mode_tab[RangeFireMode].spell->name); 00094 } 00095 else if (RangeFireMode == FIRE_MODE_BOW) 00096 { 00097 if (fire_mode_tab[FIRE_MODE_BOW].item == FIRE_ITEM_NO) 00098 { 00099 draw_info(COLOR_WHITE, "No range weapon selected."); 00100 return; 00101 } 00102 else if (fire_mode_tab[FIRE_MODE_BOW].amun == FIRE_ITEM_NO) 00103 { 00104 draw_info(COLOR_WHITE, "No ammunition selected."); 00105 return; 00106 } 00107 } 00108 else if (RangeFireMode == FIRE_MODE_THROW) 00109 { 00110 if (fire_mode_tab[FIRE_MODE_THROW].item == FIRE_ITEM_NO) 00111 { 00112 draw_info(COLOR_WHITE, "No item selected."); 00113 return; 00114 } 00115 } 00116 else if (RangeFireMode == FIRE_MODE_WAND) 00117 { 00118 if (fire_mode_tab[FIRE_MODE_WAND].item == FIRE_ITEM_NO) 00119 { 00120 draw_info(COLOR_WHITE, "No device selected."); 00121 return; 00122 } 00123 } 00124 00125 send_socklist(sl); 00126 } 00127 else 00128 { 00129 if (num == 5) 00130 { 00131 cs_write_string("clr", 3); 00132 } 00133 else 00134 { 00135 send_command(directions_move[num - 1]); 00136 } 00137 } 00138 } 00139 00147 int dir_from_tile_coords(int tx, int ty) 00148 { 00149 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; 00150 int q, x, y; 00151 00152 if (tx == player_tile_x && ty == player_tile_y) 00153 { 00154 return 5; 00155 } 00156 00157 x = -(tx - player_tile_x); 00158 y = -(ty - player_tile_y); 00159 00160 if (!y) 00161 { 00162 q = -300 * x; 00163 } 00164 else 00165 { 00166 q = x * 100 / y; 00167 } 00168 00169 if (y > 0) 00170 { 00171 /* East */ 00172 if (q < -242) 00173 { 00174 return 6; 00175 } 00176 00177 /* Northeast */ 00178 if (q < -41) 00179 { 00180 return 9; 00181 } 00182 00183 /* North */ 00184 if (q < 41) 00185 { 00186 return 8; 00187 } 00188 00189 /* Northwest */ 00190 if (q < 242) 00191 { 00192 return 7; 00193 } 00194 00195 /* West */ 00196 return 4; 00197 } 00198 00199 /* West */ 00200 if (q < -242) 00201 { 00202 return 4; 00203 } 00204 00205 /* Southwest */ 00206 if (q < -41) 00207 { 00208 return 1; 00209 } 00210 00211 /* South */ 00212 if (q < 41) 00213 { 00214 return 2; 00215 } 00216 00217 /* Southeast */ 00218 if (q < 242) 00219 { 00220 return 3; 00221 } 00222 00223 /* East */ 00224 return 6; 00225 }
1.7.4