| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
void init_type_creator(void) { |
| 41 |
register_process(CREATOR, creator_type_process); |
| 42 |
register_trigger(CREATOR, creator_type_trigger); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 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 |
|
| 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); |
| 86 |
CLEAR_FLAG(new_ob, FLAG_IS_A_TEMPLATE); |
| 87 |
object_unset_flag_inv(new_ob, FLAG_IS_A_TEMPLATE); |
| 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 |
|
| 99 |
if (new_ob->arch->more && ob_blocked(new_ob, creator->map, creator->x, creator->y)) { |
| 100 |
object_free_drop_inventory(new_ob); |
| 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 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
static method_ret creator_type_process(ob_methods *context, object *op) { |
| 126 |
move_creator(op); |
| 127 |
return METHOD_OK; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
static method_ret creator_type_trigger(ob_methods *context, object *op, object *cause, int state) { |
| 139 |
move_creator(op); |
| 140 |
return METHOD_OK; |
| 141 |
} |