Crossfire Server, Branch 1.12  R12190
ob_methods.c
Go to the documentation of this file.
00001 /*
00002  * static char *rcsid_ob_methods =
00003  *   "$Id: build_map.c 5057 2006-10-29 07:50:09Z mwedel $";
00004  */
00005 /*
00006     CrossFire, A Multiplayer game for X-windows
00007 
00008     Copyright (C) 2006 Mark Wedel & Crossfire Development Team
00009     Copyright (C) 1992 Frank Tore Johansen
00010 
00011     This program is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     This program is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU General Public License for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with this program; if not, write to the Free Software
00023     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024 
00025     The authors can be reached via e-mail to crossfire-devel@real-time.com
00026 */
00027 
00033 #include <global.h>
00034 #include <ob_methods.h>
00035 #include <ob_types.h>
00036 
00037 #ifndef __CEXTRACT__
00038 #include <sproto.h>
00039 #endif
00040 
00041 /*
00042  * The following functions are meant for calling methods. No actual behavoir
00043  * logic should be contained in this code. Code in the common/ directory should
00044  * be used for logic common to all types, and should always be called by
00045  * individual method code (i.e. all apply methods should call 'can_apply' from
00046  * common/). Defaults for all types should not be put here either, as that code
00047  * belongs in the common/ directory also, referenced to by base_type.
00048  */
00049 
00059 method_ret ob_apply(object *op, object *applier, int aflags) {
00060     method_ret ret;
00061     ob_methods *methods;
00062 
00063     for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
00064         if (methods->apply) {
00065             ret = methods->apply(methods, op, applier, aflags);
00066             if (ret != METHOD_UNHANDLED)
00067                 return ret;
00068         }
00069     }
00070     return METHOD_UNHANDLED;
00071 }
00072 
00079 method_ret ob_process(object *op) {
00080     method_ret ret;
00081     ob_methods *methods;
00082 
00083     for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
00084         if (methods->process) {
00085             ret = methods->process(methods, op);
00086             if (ret != METHOD_UNHANDLED)
00087                 return ret;
00088         }
00089     }
00090     return METHOD_UNHANDLED;
00091 }
00092 
00102 char *ob_describe(const object *op, const object *observer, char *buf, size_t size) {
00103     ob_methods *methods;
00104 
00105     for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
00106         if (methods->describe) {
00107             methods->describe(methods, op, observer, buf, size);
00108             return buf;
00109         }
00110     }
00111     buf[0] = '\0';
00112     return buf;
00113 }
00114 
00122 method_ret ob_move_on(object *op, object *victim, object *originator) {
00123     method_ret ret;
00124     ob_methods *methods;
00125 
00126     for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
00127         if (methods->move_on) {
00128             ret = methods->move_on(methods, op, victim, originator);
00129             if (ret != METHOD_UNHANDLED)
00130                 return ret;
00131         }
00132     }
00133     return METHOD_UNHANDLED;
00134 }
00135 
00144 method_ret ob_trigger(object *op, object *cause, int state) {
00145     method_ret ret;
00146     ob_methods *methods;
00147 
00148     for (methods = &type_methods[op->type]; methods; methods = methods->fallback) {
00149         if (methods->trigger) {
00150             ret = methods->trigger(methods, op, cause, state);
00151             if (ret != METHOD_UNHANDLED)
00152                 return ret;
00153         }
00154     }
00155     return METHOD_UNHANDLED;
00156 }