Crossfire Server, Branches 1.12  R18729
creator.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 creator_type_process(ob_methods *context, object *op);
35 static method_ret creator_type_trigger(ob_methods *context, object *op, object *cause, int state);
36 
40 void init_type_creator(void) {
43 }
44 
64 static void move_creator(object *creator) {
65  object *new_ob;
66 
67  if (!QUERY_FLAG(creator, FLAG_LIFESAVE) && --creator->stats.hp < 0) {
68  creator->stats.hp = -1;
69  return;
70  }
71 
72  if (creator->inv != NULL) {
73  object *ob;
74  int i;
75  object *ob_to_copy;
76 
77  /* select random object from inventory to copy */
78  ob_to_copy = creator->inv;
79  for (ob = creator->inv->below, i = 1; ob != NULL; ob = ob->below, i++) {
80  if (rndm(0, i) == 0) {
81  ob_to_copy = ob;
82  }
83  }
84  new_ob = object_create_clone(ob_to_copy);
87  } else {
88  if (creator->other_arch == NULL) {
89  LOG(llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", creator->name ? creator->name : "(null)", creator->map->path, creator->x, creator->y);
90  return;
91  }
92 
93  new_ob = object_create_arch(creator->other_arch);
94  fix_generated_item(new_ob, creator, 0, 0, GT_MINIMAL);
95  }
96 
97  /* Make sure this multipart object fits */
98  if (new_ob->arch->more && ob_blocked(new_ob, creator->map, creator->x, creator->y)) {
99  free_object(new_ob);
100  return;
101  }
102 
103  if (creator->level != 0)
104  new_ob->level = creator->level;
105 
106  insert_ob_in_map_at(new_ob, creator->map, creator, 0, creator->x, creator->y);
107  if (QUERY_FLAG(new_ob, FLAG_FREED))
108  return;
109 
110  if (creator->slaying) {
111  FREE_AND_COPY(new_ob->name, creator->slaying);
112  FREE_AND_COPY(new_ob->title, creator->slaying);
113  }
114 }
115 
122 static method_ret creator_type_process(ob_methods *context, object *op) {
123  move_creator(op);
124  return METHOD_OK;
125 }
126 
135 static method_ret creator_type_trigger(ob_methods *context, object *op, object *cause, int state) {
136  move_creator(op);
137  return METHOD_OK;
138 }
char path[HUGE_BUF]
Definition: map.h:384
static method_ret creator_type_trigger(ob_methods *context, object *op, object *cause, int state)
Definition: creator.c:135
void unflag_inv(object *op, int flag)
Definition: object.c:2894
object * insert_ob_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:1761
const char * slaying
Definition: object.h:172
sint16 x
Definition: object.h:179
struct archt * other_arch
Definition: object.h:264
sint16 hp
Definition: living.h:81
void init_type_creator(void)
Definition: creator.c:40
char method_ret
Definition: ob_methods.h:41
int rndm(int min, int max)
Definition: utils.c:174
const char * title
Definition: object.h:170
#define CREATOR
Definition: define.h:156
#define METHOD_OK
Definition: ob_methods.h:42
struct mapdef * map
Definition: object.h:155
static void move_creator(object *creator)
Definition: creator.c:64
const char * name
Definition: object.h:167
struct obj * below
Definition: object.h:145
struct archt * more
Definition: object.h:325
#define FLAG_IS_A_TEMPLATE
Definition: define.h:671
object * object_create_clone(object *asrc)
Definition: object.c:3608
sint16 y
Definition: object.h:179
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define CLEAR_FLAG(xyz, p)
Definition: define.h:512
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags)
Definition: treasure.c:1070
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:115
object * object_create_arch(archetype *at)
Definition: arch.c:741
#define FREE_AND_COPY(sv, nv)
Definition: global.h:288
living stats
Definition: object.h:219
struct archt * arch
Definition: object.h:263
static method_ret creator_type_process(ob_methods *context, object *op)
Definition: creator.c:122
#define FLAG_LIFESAVE
Definition: define.h:602
void register_process(int ob_type, process_func method)
Definition: ob_types.c:88
struct obj * inv
Definition: object.h:148
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
int ob_blocked(const object *ob, mapstruct *m, sint16 x, sint16 y)
Definition: map.c:525
#define FLAG_FREED
Definition: define.h:529