Debian Codegraph @

types/peacemaker/peacemaker.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 peacemaker/peacemaker.c
25 * The implementation of the Peacemaker class of objects.
26 * @todo Consider merging Peacemaker with Spell Effects
27 */
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33
34 static method_ret peacemaker_type_process(ob_methods *context, object *op);
35
36 /**
37 * Initializer for the peacemaker object type.
38 */
39 void init_type_peacemaker(void) {
40 register_process(PEACEMAKER, peacemaker_type_process);
41 }
42
43 /**
44 * Handle ob_process for all peacemaker objects. Makes monster it passes
45 * peaceful.
46 * @param context The method context
47 * @param op The peacemaker that's being processed.
48 * @return METHOD_OK
49 */
50 static method_ret peacemaker_type_process(ob_methods *context, object *op) {
51 object *owner;
52
53 owner = object_get_owner(op);
54 if (owner == NULL) {
55 LOG(llevError, "peacemaker_type_process: peacemaker object %s has no owner\n", op->name);
56 object_remove(op);
57 object_free(op, 1);
58 return METHOD_OK;
59 }
60
61 FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
62 int atk_lev, def_lev;
63 object *victim;
64
65 victim = HEAD(tmp);
66 if (!QUERY_FLAG(victim, FLAG_MONSTER))
67 continue;
68 if (QUERY_FLAG(victim, FLAG_UNAGGRESSIVE))
69 continue;
70 if (victim->stats.exp == 0)
71 continue;
72
73 def_lev = MAX(1, victim->level);
74 atk_lev = MAX(1, op->level);
75
76 if (rndm(0, atk_lev-1) > def_lev) {
77 /* make this sucker peaceful. */
78
79 change_exp(owner, victim->stats.exp, op->skill, 0);
80 victim->stats.exp = 0;
81 victim->attack_movement = RANDO2;
82 SET_FLAG(victim, FLAG_UNAGGRESSIVE);
83 SET_FLAG(victim, FLAG_RUN_AWAY);
84 SET_FLAG(victim, FLAG_RANDOM_MOVE);
85 CLEAR_FLAG(victim, FLAG_MONSTER);
86 if (victim->name) {
87 draw_ext_info_format(NDI_UNIQUE, 0, owner, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS,
88 "%s no longer feels like fighting.",
89 victim->name);
90 }
91 }
92 } FOR_MAP_FINISH();
93 return METHOD_OK;
94 }