Atrinik Server 2.5
commands/move.c
Go to the documentation of this file.
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 
00038 static int move_internal(object *op, char *params, int dir)
00039 {
00040     if (params)
00041     {
00042         if (params[0] == 'f')
00043         {
00044             if (!CONTR(op)->fire_on)
00045             {
00046                 CONTR(op)->fire_on = 1;
00047                 move_player(op, dir);
00048                 CONTR(op)->fire_on = 0;
00049                 return 0;
00050             }
00051         }
00052         else if (params[0] == 'r' && !CONTR(op)->run_on)
00053         {
00054             CONTR(op)->run_on = 1;
00055         }
00056     }
00057 
00058     move_player(op, dir);
00059     return 0;
00060 }
00061 
00067 int command_east(object *op, char *params)
00068 {
00069     return move_internal(op, params, 3);
00070 }
00071 
00077 int command_north(object *op, char *params)
00078 {
00079     return move_internal(op, params, 1);
00080 }
00081 
00087 int command_northeast(object *op, char *params)
00088 {
00089     return move_internal(op, params, 2);
00090 }
00091 
00097 int command_northwest(object *op, char *params)
00098 {
00099     return move_internal(op, params, 8);
00100 }
00101 
00107 int command_south(object *op, char *params)
00108 {
00109     return move_internal(op, params, 5);
00110 }
00111 
00117 int command_southeast(object *op, char *params)
00118 {
00119     return move_internal(op, params, 4);
00120 }
00121 
00127 int command_southwest(object *op, char *params)
00128 {
00129     return move_internal(op, params, 6);
00130 }
00131 
00137 int command_west(object *op, char *params)
00138 {
00139     return move_internal(op, params, 7);
00140 }
00141 
00147 int command_stay(object *op, char *params)
00148 {
00149     if (!CONTR(op)->fire_on && (!params || params[0] != 'f'))
00150     {
00151         return 0;
00152     }
00153 
00154     fire(op, 0);
00155     return 0;
00156 }
00157 
00163 int command_turn_right(object *op, char *params)
00164 {
00165     int dir = absdir(op->facing + 1);
00166 
00167     (void) params;
00168 
00169     op->anim_last_facing = op->anim_last_facing_last = op->facing = dir;
00170     SET_ANIMATION(op, dir * (NUM_ANIMATIONS(op) / NUM_FACINGS(op)));
00171 
00172     return 1;
00173 }
00174 
00180 int command_turn_left(object *op, char *params)
00181 {
00182     int dir = absdir(op->facing - 1);
00183 
00184     (void) params;
00185 
00186     op->anim_last_facing = op->anim_last_facing_last = op->facing = dir;
00187     SET_ANIMATION(op, dir * (NUM_ANIMATIONS(op) / NUM_FACINGS(op)));
00188 
00189     return 1;
00190 }
00191 
00197 int command_push_object(object *op, char *params)
00198 {
00199     object *tmp;
00200     mapstruct *m;
00201     int xt, yt, dir = op->facing;
00202 
00203     (void) params;
00204 
00205     /* We check for all conditions where player can't push anything. */
00206     if (dir <= 0 || QUERY_FLAG(op, FLAG_PARALYZED))
00207     {
00208         new_draw_info(0, COLOR_WHITE, op, "You are unable to push anything.");
00209         return 0;
00210     }
00211 
00212     xt = op->x + freearr_x[dir];
00213     yt = op->y + freearr_y[dir];
00214 
00215     if (!(m = get_map_from_coord(op->map, &xt, &yt)))
00216     {
00217         return 0;
00218     }
00219 
00220     for (tmp = GET_MAP_OB(m, xt, yt); tmp; tmp = tmp->above)
00221     {
00222         if (QUERY_FLAG(tmp, FLAG_CAN_ROLL))
00223         {
00224             break;
00225         }
00226     }
00227 
00228     if (tmp == NULL || !QUERY_FLAG(tmp, FLAG_CAN_ROLL))
00229     {
00230         new_draw_info(0, COLOR_WHITE, op, "You fail to push anything.");
00231         return 0;
00232     }
00233 
00234     tmp->direction = dir;
00235 
00236     /* Try to push the object. */
00237     if (!push_ob(tmp, dir, op))
00238     {
00239         new_draw_info_format(0, COLOR_WHITE, op, "You fail to push the %s.", query_name(tmp, NULL));
00240         return 0;
00241     }
00242 
00243     /* Now we move the player who was pushing the object. */
00244     move_ob(op, dir, op);
00245     new_draw_info_format(0, COLOR_WHITE, op, "You push the %s.", query_name(tmp, NULL));
00246 
00247     return 1;
00248 }