Debian Codegraph @

types/duplicator/duplicator.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * The implementation of @ref page_type_83 "duplicator" objects.
17 */
18
19 #include "global.h"
20
21 #include <string.h>
22
23 #include "ob_methods.h"
24 #include "ob_types.h"
25 #include "sounds.h"
26 #include "sproto.h"
27
28 static method_ret duplicator_type_trigger(ob_methods *context, object *op, object *cause, int state);
29
30 /**
31 * Initializer for the @ref page_type_83 "duplicator" object type.
32 */
33 void init_type_duplicator(void) {
34 register_trigger(DUPLICATOR, duplicator_type_trigger);
35 }
36
37 /**
38 * Trigger for @ref page_type_83 "duplicator".
39 *
40 * Will duplicate a specified object placed on top of it.
41 * - connected: what will trigger it.
42 * - level: multiplier. 0 to destroy.
43 * - other_arch: the object to look for and duplicate.
44 *
45 * @param op
46 * duplicator.
47 */
48 static void move_duplicator(object *op) {
49 object *tmp;
50
51 if (!op->other_arch) {
52 LOG(llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap");
53 return;
54 }
55
56 if (op->above == NULL)
57 return;
58 int count = op->nrof;
59 for (tmp = op->above; tmp != NULL; tmp = tmp->above) {
60 if (strcmp(op->other_arch->name, tmp->arch->name) == 0) {
61 if (op->level <= 0) {
62 object_remove(tmp);
63 object_free_drop_inventory(tmp);
64 tmp = op; // Old tmp was removed, so we can't follow that linked list
65 } else {
66 uint64_t new_nrof = (uint64_t)tmp->nrof*op->level;
67
68 if (new_nrof >= 1UL<<31)
69 new_nrof = 1UL<<31;
70 tmp->nrof = new_nrof;
71 }
72 if ( count <= 1 ) break;
73 --count;
74 }
75 }
76 }
77
78 /**
79 * A @ref page_type_83 "duplicator" is triggered.
80 * @param context Ignored.
81 * @param op The duplicator being triggered
82 * @param cause Ignored.
83 * @param state Ignored.
84 * @retval METHOD_OK
85 */
86 static method_ret duplicator_type_trigger(ob_methods *context, object *op, object *cause, int state) {
87 move_duplicator(op);
88 return METHOD_OK;
89 }