Crossfire Server, Trunk  1.75.0
duplicator.cpp
Go to the documentation of this file.
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 <crossfire@metalforge.org>.
12  */
13 
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(object *op, object *cause, int state);
29 
35 }
36 
49 static void move_duplicator(object *op) {
50  object *tmp;
51 
52  if (!op->other_arch) {
53  LOG(llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap");
54  return;
55  }
56 
57  if (op->above == NULL)
58  return;
59  int count = op->nrof;
60  for (tmp = op->above; tmp != NULL; tmp = tmp->above) {
61  if (strcmp(op->other_arch->name, tmp->arch->name) == 0) {
62  if (op->level <= 0) {
63  object_remove(tmp);
65  tmp = op; // Old tmp was removed, so we can't follow that linked list
66  } else {
67  uint64_t new_nrof = (uint64_t)tmp->nrof*op->level;
68 
69  if (new_nrof >= 1UL<<31)
70  new_nrof = 1UL<<31;
71  tmp->nrof = new_nrof;
72  }
73  if (op->stats.food) {
74  --op->stats.food;
75  if (!op->stats.food) {
76  object_remove(op);
78  return;
79  }
80  }
81  if (count <= 1)
82  break;
83  --count;
84  }
85  }
86 }
87 
95 static method_ret duplicator_type_trigger(object *op, object *cause, int state) {
96  (void)cause;
97  (void)state;
98  move_duplicator(op);
99  return METHOD_OK;
100 }
global.h
LOG
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:58
object::arch
struct archetype * arch
Pointer to archetype.
Definition: object.h:424
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
if
if(!(yy_init))
Definition: loader.cpp:36428
object::x
int16_t x
Definition: object.h:335
object::map
struct mapstruct * map
Pointer to the map in which this object is present.
Definition: object.h:305
mapstruct::path
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:355
object::level
int16_t level
Level of creature or object.
Definition: object.h:361
object::above
object * above
Pointer to the object stacked above this one.
Definition: object.h:296
duplicator_type_trigger
static method_ret duplicator_type_trigger(object *op, object *cause, int state)
A duplicator is triggered.
Definition: duplicator.cpp:95
move_duplicator
static void move_duplicator(object *op)
Trigger for duplicator.
Definition: duplicator.cpp:49
object::y
int16_t y
Position in the map for this object.
Definition: object.h:335
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects,...
Definition: object.cpp:1560
living::food
int32_t food
How much food in stomach.
Definition: living.h:48
init_type_duplicator
void init_type_duplicator(void)
Initializer for the duplicator object type.
Definition: duplicator.cpp:33
sproto.h
object::other_arch
struct archetype * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
Definition: object.h:425
register_trigger
void register_trigger(int ob_type, trigger_func method)
Registers the trigger method for the given type.
Definition: ob_types.cpp:98
method_ret
char method_ret
Define some standard return values for callbacks which don't need to return any other results.
Definition: ob_methods.h:14
ob_types.h
sounds.h
llevInfo
@ llevInfo
Information.
Definition: logger.h:12
DUPLICATOR
@ DUPLICATOR
Duplicator/multiplier object.
Definition: object.h:207
object_remove
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to.
Definition: object.cpp:1833
archetype::name
sstring name
More definite name, like "generate_kobold".
Definition: object.h:484
object::nrof
uint32_t nrof
Number of objects.
Definition: object.h:342
ob_methods.h
object::stats
living stats
Str, Con, Dex, etc.
Definition: object.h:378