Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 CrossFire, A Multiplayer game for X-windows 00003 00004 Copyright (C) 2007 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 00028 #include <global.h> 00029 #include <ob_methods.h> 00030 #include <ob_types.h> 00031 #include <sounds.h> 00032 #include <sproto.h> 00033 00034 static method_ret lamp_type_apply(ob_methods *context, object *lighter, object *applier, int aflags); 00035 00039 void init_type_lamp(void) { 00040 register_apply(LAMP, lamp_type_apply); 00041 } 00042 00054 static void do_turn(object *op, object *who, int aflags, const char *onoff) { 00055 object *tmp2; 00056 00057 if (!(aflags&AP_NOPRINT)) 00058 draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, 00059 "You turn %s your %s.", 00060 NULL, 00061 onoff, op->name); 00062 00063 tmp2 = arch_to_object(op->other_arch); 00064 tmp2->stats.food = op->stats.food; 00065 if (QUERY_FLAG(op, FLAG_APPLIED)) 00066 CLEAR_FLAG(tmp2, FLAG_APPLIED); 00067 else 00068 SET_FLAG(tmp2, FLAG_APPLIED); 00069 if (QUERY_FLAG(op, FLAG_INV_LOCKED)) 00070 SET_FLAG(tmp2, FLAG_INV_LOCKED); 00071 insert_ob_in_ob(tmp2, who); 00072 00073 remove_ob(op); 00074 free_object(op); 00075 00076 fix_object(who); 00077 00078 if (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED)) { 00079 if (who->type == PLAYER) { 00080 if (!(aflags&AP_NOPRINT)) 00081 draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, 00082 "Oops, it feels deadly cold!", NULL); 00083 SET_FLAG(tmp2, FLAG_KNOWN_CURSED); 00084 } 00085 } 00086 00087 if (who->map) { 00088 SET_MAP_FLAGS(who->map, who->x, who->y, P_NEED_UPDATE); 00089 update_position(who->map, who->x, who->y); 00090 update_all_los(who->map, who->x, who->y); 00091 } 00092 } 00093 00108 static method_ret lamp_type_apply(ob_methods *context, object *lamp, object *applier, int aflags) { 00109 object *tmp; 00110 00111 if (get_player_container(lamp) != applier) { 00112 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, 00113 "You must get it first!\n", NULL); 00114 return METHOD_ERROR; 00115 } 00116 00117 if (lamp->nrof > 1) 00118 tmp = get_split_ob(lamp, lamp->nrof-1, NULL, 0); 00119 else 00120 tmp = NULL; 00121 00122 if (QUERY_FLAG(lamp, FLAG_APPLIED)) 00123 do_turn(lamp, applier, aflags, "off"); 00124 else { 00125 if (lamp->stats.food < 1) { 00126 if (!(aflags&AP_NOPRINT)) 00127 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, 00128 "Your %s is out of fuel!", 00129 NULL, 00130 lamp->name); 00131 return METHOD_OK; 00132 } 00133 do_turn(lamp, applier, aflags, "on"); 00134 } 00135 00136 /* insert the portion that was split off. */ 00137 if (tmp != NULL) { 00138 insert_ob_in_ob(tmp, applier); 00139 } 00140 00141 return METHOD_OK; 00142 }