Debian Codegraph @

types/deep_swamp/deep_swamp.c

raw symbols SCIP
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at [email protected]
22 */
23
24 /** @file deep_swamp.c
25 * The implementation of the Deep Swamp class of objects.
26 */
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sounds.h>
31 #include <sproto.h>
32
33 static method_ret deep_swamp_type_process(ob_methods *context, object *op);
34 static method_ret deep_swamp_type_move_on(ob_methods *context, object *trap, object *victim, object *originator);
35
36 /**
37 * Initializer for the DEEP_SWAMP object type.
38 */
39 void init_type_deep_swamp(void) {
40 register_move_on(DEEP_SWAMP, deep_swamp_type_move_on);
41 register_process(DEEP_SWAMP, deep_swamp_type_process);
42 }
43
44 /**
45 * Processes a Deep Swamp.
46 * @param context The method context
47 * @param op The swamp to process
48 * @return Always METHOD_OK
49 */
50 static method_ret deep_swamp_type_process(ob_methods *context, object *op) {
51 object *above = op->above;
52 object *nabove;
53 int got_player = 0;
54
55 while (above) {
56 nabove = above->above;
57 if (above->type == PLAYER
58 && !(above->move_type&MOVE_FLYING)
59 && above->stats.hp >= 0
60 && !QUERY_FLAG(above, FLAG_WIZ)) {
61 object *woodsman = object_find_by_type_subtype(above, SKILL, SK_WOODSMAN);
62 got_player = 1;
63 if (op->stats.food < 1) {
64 LOG(llevDebug, "move_deep_swamp(): player is here, but state is %d\n", op->stats.food);
65 op->stats.food = 1;
66 }
67 if (op->stats.food < 10) {
68 if (rndm(0, 2) == 0) {
69 draw_ext_info_format(NDI_UNIQUE, 0, above, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SWAMP,
70 "You are down to your waist in the wet %s.",
71 op->name);
72 op->stats.food = woodsman ? op->stats.food+1 : 10;
73 above->speed_left -= op->move_slow_penalty;
74 }
75 } else if (op->stats.food < 20) {
76 if (rndm(0, 2) == 0) {
77 draw_ext_info_format(NDI_UNIQUE|NDI_RED, 0, above, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SWAMP,
78 "You are down to your NECK in the dangerous %s.",
79 op->name);
80 op->stats.food = woodsman ? op->stats.food+1 : 20;
81 snprintf(above->contr->killer, sizeof(above->contr->killer), "drowning in a %s", op->name);
82 above->stats.hp--;
83 above->speed_left -= op->move_slow_penalty;
84 }
85 } else if (rndm(0, 4) == 0) {
86 op->stats.food = 0;
87 draw_ext_info_format(NDI_UNIQUE|NDI_ALL, 1, NULL, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER,
88 "%s disappeared into a %s.", above->name, op->name);
89 snprintf(above->contr->killer, sizeof(above->contr->killer), "drowning in a %s", op->name);
90 above->stats.hp = -1;
91 kill_player(above, op); /* player dies in the swamp */
92 }
93 } else if (!QUERY_FLAG(above, FLAG_ALIVE)
94 && !(above->move_type&MOVE_FLYING)
95 && !(QUERY_FLAG(above, FLAG_IS_FLOOR))
96 && !(QUERY_FLAG(above, FLAG_OVERLAY_FLOOR))
97 && !(QUERY_FLAG(above, FLAG_NO_PICK))) {
98 if (rndm(0, 2) == 0)
99 object_decrease_nrof_by_one(above);
100 }
101 above = nabove;
102 }
103 if (!got_player)
104 op->stats.food = 1;
105 return METHOD_OK;
106 }
107
108 /**
109 * Move on this Deep Swamp object.
110 * @param context The method context
111 * @param trap The Deep Swamp we're moving on
112 * @param victim The object moving over this one
113 * @param originator The object that caused the move_on event
114 * @return METHOD_OK
115 */
116 static method_ret deep_swamp_type_move_on(ob_methods *context, object *trap, object *victim, object *originator) {
117 if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
118 return METHOD_OK;
119 if (victim->type == PLAYER
120 && victim->stats.hp >= 0
121 && !(victim->move_type&MOVE_FLYING)) {
122 draw_ext_info_format(NDI_UNIQUE, 0, victim, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SWAMP,
123 "You are down to your knees in the %s.", trap->name);
124 trap->stats.food = 1;
125 victim->speed_left -= trap->move_slow_penalty;
126 }
127 common_post_ob_move_on(trap, victim, originator);
128 return METHOD_OK;
129 }