Crossfire Server, Branches 1.12  R18729
duplicator.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2008 Crossfire Development Team
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20  The authors can be reached via e-mail at crossfire-devel@real-time.com
21 */
22 
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 duplicator_type_trigger(ob_methods *context, object *op, object *cause, int state);
35 
41 }
42 
54 void move_duplicator(object *op) {
55  object *tmp;
56 
57  if (!op->other_arch) {
58  LOG(llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap");
59  return;
60  }
61 
62  if (op->above == NULL)
63  return;
64  for (tmp = op->above; tmp != NULL; tmp = tmp->above) {
65  if (strcmp(op->other_arch->name, tmp->arch->name) == 0) {
66  if (op->level <= 0) {
67  remove_ob(tmp);
68  free_object(tmp);
69  } else {
70  uint64 new_nrof = (uint64)tmp->nrof*op->level;
71 
72  if (new_nrof >= 1UL<<31)
73  new_nrof = 1UL<<31;
74  tmp->nrof = new_nrof;
75  }
76  break;
77  }
78  }
79 }
80 
89 static method_ret duplicator_type_trigger(ob_methods *context, object *op, object *cause, int state) {
90  move_duplicator(op);
91  return METHOD_OK;
92 }
char path[HUGE_BUF]
Definition: map.h:384
static method_ret duplicator_type_trigger(ob_methods *context, object *op, object *cause, int state)
Definition: duplicator.c:89
void init_type_duplicator(void)
Definition: duplicator.c:39
void move_duplicator(object *op)
Definition: duplicator.c:54
struct obj * above
Definition: object.h:146
sint16 x
Definition: object.h:179
struct archt * other_arch
Definition: object.h:264
char method_ret
Definition: ob_methods.h:41
void remove_ob(object *op)
Definition: object.c:1515
#define METHOD_OK
Definition: ob_methods.h:42
struct mapdef * map
Definition: object.h:155
uint32 nrof
Definition: object.h:184
sint16 y
Definition: object.h:179
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:115
#define DUPLICATOR
Definition: define.h:264
struct archt * arch
Definition: object.h:263
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
void free_object(object *ob)
Definition: object.c:1238
sint16 level
Definition: object.h:202
const char * name
Definition: object.h:322