Crossfire Server, Branch 1.12  R12190
thrown_object.c
Go to the documentation of this file.
00001 /*
00002     CrossFire, A Multiplayer game for X-windows
00003 
00004     Copyright (C) 2007 Mark Wedel & Crossfire Development Team
00005     Copyright (C) 1992 Frank Tore Johansen
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 
00021     The authors can be reached via e-mail at crossfire-devel@real-time.com
00022 */
00023 
00027 #include <global.h>
00028 #include <ob_methods.h>
00029 #include <ob_types.h>
00030 #include <sounds.h>
00031 #include <sproto.h>
00032 
00033 static method_ret thrown_object_type_process(ob_methods *context, object *op);
00034 
00038 void init_type_thrown_object(void) {
00039     register_move_on(THROWN_OBJ, common_projectile_move_on);
00040     register_process(THROWN_OBJ, thrown_object_type_process);
00041 }
00042 
00049 static method_ret thrown_object_type_process(ob_methods *context, object *op) {
00050     if (op->map == NULL) {
00051         LOG(llevError, "BUG: Thrown object had no map.\n");
00052         remove_ob(op);
00053         free_object(op);
00054         return METHOD_ERROR;
00055     }
00056 
00057     /* we need to stop thrown objects at some point. Like here. */
00058     if (op->type == THROWN_OBJ) {
00059         /* If the object that the THROWN_OBJ encapsulates disappears,
00060          * we need to have this object go away also - otherwise, you get
00061          * left over remnants on the map.  Where this currently happens
00062          * is if the player throws a bomb - the bomb explodes on its own,
00063          * but this object sticks around.  We could handle the cleanup in the
00064          * bomb code, but there are potential other cases where that could happen,
00065          * and it is easy enough to clean it up here.
00066          */
00067         if (op->inv == NULL) {
00068             remove_ob(op);
00069             free_object(op);
00070             return METHOD_OK;
00071         }
00072         if (op->last_sp-- < 0) {
00073             stop_projectile(op);
00074             return METHOD_OK;
00075         }
00076     }
00077 
00078     return common_process_projectile(context, op);
00079 }