Crossfire Server, Trunk
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(object *op);
35 static method_ret creator_type_trigger(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  int i;
74  object *ob_to_copy;
75 
76  /* select random object from inventory to copy */
77  ob_to_copy = creator->inv;
78  i = 1;
79  FOR_BELOW_PREPARE(creator->inv, ob) {
80  if (rndm(0, i) == 0) {
81  ob_to_copy = ob;
82  }
83  i++;
84  } FOR_BELOW_FINISH();
85  new_ob = object_create_clone(ob_to_copy);
88  } else {
89  if (creator->other_arch == NULL) {
90  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);
91  return;
92  }
93 
94  new_ob = object_create_arch(creator->other_arch);
95  fix_generated_item(new_ob, creator, 0, 0, GT_MINIMAL);
96  }
97 
98  /* Make sure this multipart object fits */
99  if (new_ob->arch->more && ob_blocked(new_ob, creator->map, creator->x, creator->y)) {
101  return;
102  }
103 
104  if (creator->level != 0)
105  new_ob->level = creator->level;
106 
107  object_insert_in_map_at(new_ob, creator->map, creator, 0, creator->x, creator->y);
108  if (QUERY_FLAG(new_ob, FLAG_FREED))
109  return;
110 
111  if (creator->slaying) {
112  FREE_AND_COPY(new_ob->name, creator->slaying);
113  if (new_ob->title) {
114  FREE_AND_CLEAR_STR(new_ob->title);
115  }
116  }
117 }
118 
125  move_creator(op);
126  return METHOD_OK;
127 }
128 
136 static method_ret creator_type_trigger(object *op, object *cause, int state) {
137  (void)cause;
138  (void)state;
139  move_creator(op);
140  return METHOD_OK;
141 }
global.h
llevError
@ llevError
Definition: logger.h:11
object_create_clone
object * object_create_clone(object *asrc)
Definition: object.c:3880
obj::map
struct mapdef * map
Definition: object.h:300
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
register_process
void register_process(int ob_type, process_func method)
Definition: ob_types.c:71
FOR_BELOW_PREPARE
#define FOR_BELOW_PREPARE(op_, it_)
Definition: define.h:704
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
init_type_creator
void init_type_creator(void)
Definition: creator.c:40
guildjoin.ob
ob
Definition: guildjoin.py:42
liv::hp
int16_t hp
Definition: living.h:40
ob_blocked
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.c:488
creator_type_process
static method_ret creator_type_process(object *op)
Definition: creator.c:124
CREATOR
@ CREATOR
Definition: object.h:142
FOR_BELOW_FINISH
#define FOR_BELOW_FINISH()
Definition: define.h:711
move_creator
static void move_creator(object *creator)
Definition: creator.c:64
FLAG_IS_A_TEMPLATE
#define FLAG_IS_A_TEMPLATE
Definition: define.h:366
obj::slaying
sstring slaying
Definition: object.h:322
object_unset_flag_inv
void object_unset_flag_inv(object *op, int flag)
Definition: object.c:3227
creator_type_trigger
static method_ret creator_type_trigger(object *op, object *cause, int state)
Definition: creator.c:136
obj::name
sstring name
Definition: object.h:314
FLAG_FREED
#define FLAG_FREED
Definition: define.h:233
FREE_AND_COPY
#define FREE_AND_COPY(sv, nv)
Definition: global.h:201
obj::x
int16_t x
Definition: object.h:330
object_create_arch
object * object_create_arch(archetype *at)
Definition: arch.cpp:301
obj::other_arch
struct archt * other_arch
Definition: object.h:418
archt::more
struct archt * more
Definition: object.h:472
rndm
int rndm(int min, int max)
Definition: utils.c:162
sproto.h
register_trigger
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:98
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
fix_generated_item
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags)
Definition: treasure.c:876
FREE_AND_CLEAR_STR
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:195
obj::y
int16_t y
Definition: object.h:330
obj::title
sstring title
Definition: object.h:320
obj::arch
struct archt * arch
Definition: object.h:417
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
obj::stats
living stats
Definition: object.h:373
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
give.op
op
Definition: give.py:33
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:2080
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1546
quest.state
state
Definition: quest.py:13
ob_methods.h
mapdef::path
char path[HUGE_BUF]
Definition: map.h:358
GT_MINIMAL
@ GT_MINIMAL
Definition: treasure.h:36
obj::level
int16_t level
Definition: object.h:356
FLAG_LIFESAVE
#define FLAG_LIFESAVE
Definition: define.h:305
obj::inv
struct obj * inv
Definition: object.h:293