Debian Codegraph @

types/mimic/mimic.c

raw symbols SCIP
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2018 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 /**
25 * Implementation of mimics
26 * This should be usable for any item masquerading as a container (or other item, for that matter)
27 * that activates when you try to pick it up or apply it.
28 */
29
30 #include <global.h>
31 #include <ob_methods.h>
32 #include <ob_types.h>
33 #include <sounds.h>
34 #include <sproto.h>
35 #include <string.h>
36
37 static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags);
38
39 /**
40 * Initializer for MIMIC type.
41 */
42 void init_type_mimic(void) {
43 register_apply(MIMIC, mimic_type_apply);
44 }
45
46 /**
47 * Handles applying a mimic.
48 * It just becomes a monster and gains an animation.
49 * @param context The method context
50 * @param op The object being applied
51 * @param applier The object doing the applying
52 * @param aflags Special flags
53 * @retval METHOD_UNHANDLED If a non-player tries to open it.
54 * @retval METHOD_OK If a player does the opening.
55 */
56 static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
57 if (applier->type == PLAYER) {
58
59 draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, "Ah! It's alive!");
60 /* We become a monster */
61 op->type = MONSTER;
62 /* We are animated, too, assuming we have a face right now. */
63 if (op->face)
64 {
65 char anim_name_buf[128];
66 int anim_name_len = strlen(op->face->name);
67 strncpy(anim_name_buf, op->face->name, 128);
68 // Remove the .11x from the end of the face name.
69 anim_name_buf[anim_name_len-4] = '\0';
70 strncat(anim_name_buf, "_mimic", 128-anim_name_len+4);
71 op->animation = find_animation(anim_name_buf);
72 SET_FLAG(op, FLAG_ANIMATE);
73 }
74 SET_FLAG(op, FLAG_ALIVE);
75 SET_FLAG(op, FLAG_MONSTER);
76 op->enemy = applier;
77 // TODO: Should this be able to be set dynamically?
78 FREE_AND_COPY(op->name, "mimic");
79 return METHOD_OK;
80 }
81 return METHOD_UNHANDLED;
82 }