long creature_add_lair_to_room(struct Thing *creatng, struct Room *room) { struct Thing *lairtng; if (!room_has_enough_free_capacity_for_creature(room, creatng)) return 0; //return _DK_creature_add_lair_to_room(thing, room); // Make sure we don't already have a lair on that position lairtng = find_creature_lair_at_subtile(creatng->mappos.x.stl.num, creatng->mappos.y.stl.num, 0); if (!thing_is_invalid(lairtng)) return 0; struct CreatureStats *crstat; struct CreatureControl *cctrl; crstat = creature_stats_get_from_thing(creatng); cctrl = creature_control_get_from_thing(creatng); room->content_per_model[creatng->model]++; room->used_capacity += crstat->lair_size; if ((cctrl->lair_room_id > 0) && (cctrl->lairtng_idx > 0)) { struct Room *room; room = room_get(cctrl->lair_room_id); creature_remove_lair_from_room(creatng, room); } cctrl->lair_room_id = room->index; // Create the lair thing struct CreatureData *crdata; struct Coord3d pos; pos.x.val = creatng->mappos.x.val; pos.y.val = creatng->mappos.y.val; pos.z.val = creatng->mappos.z.val; crdata = creature_data_get_from_thing(creatng); lairtng = create_object(&pos, crdata->field_1, creatng->owner, -1); if (thing_is_invalid(lairtng)) { ERRORLOG("Could not create lair totem"); remove_thing_from_mapwho(creatng); place_thing_in_mapwho(creatng); return 1; // Return that so we won't try to redo the action over and over } lairtng->mappos.z.val = get_thing_height_at(lairtng, &lairtng->mappos); // Associate creature with the lair cctrl->lairtng_idx = lairtng->index; lairtng->word_13 = creatng->index; lairtng->word_15 = 1; // Lair size depends on creature level lairtng->word_17 = 300 * cctrl->explevel / 20 + 300; lairtng->field_52 = ACTION_RANDOM(0x800); struct Objects *objdat; unsigned long i; objdat = get_objects_data_for_thing(lairtng); i = convert_td_iso(objdat->field_5); set_thing_draw(lairtng, i, objdat->field_7, lairtng->word_15, 0, -1, objdat->field_11); thing_play_sample(creatng, 158, NORMAL_PITCH, 0, 3, 1, 2, FULL_LOUDNESS); create_effect(&pos, imp_spangle_effects[creatng->owner], creatng->owner); anger_set_creature_anger(creatng, 0, AngR_NoLair); remove_thing_from_mapwho(creatng); place_thing_in_mapwho(creatng); return 1; }
TbBool update_creature_anim_td(struct Thing *thing, long speed, long td_idx) { unsigned long i; i = convert_td_iso(td_idx); if (i != thing->anim_sprite) { set_thing_draw(thing, i, speed, -1, -1, 0, 2); return true; } return false; }
TbBool update_creature_anim(struct Thing *thing, long speed, long seq_idx) { unsigned long i; i = get_creature_anim(thing, seq_idx); if (i != thing->anim_sprite) { set_thing_draw(thing, i, speed, -1, -1, 0, 2); return true; } return false; }
struct Thing *create_trap(struct Coord3d *pos, ThingModel trpkind, PlayerNumber plyr_idx) { SYNCDBG(7,"Starting"); struct TrapStats *trapstat; trapstat = &trap_stats[trpkind]; if (!i_can_allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots)) { ERRORDBG(3,"Cannot create trap %s for player %d. There are too many things allocated.",trap_code_name(trpkind),(int)plyr_idx); erstat_inc(ESE_NoFreeThings); return INVALID_THING; } struct InitLight ilght; LbMemorySet(&ilght, 0, sizeof(struct InitLight)); struct Thing *thing; thing = allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots); if (thing->index == 0) { ERRORDBG(3,"Should be able to allocate trap %s for player %d, but failed.",trap_code_name(trpkind),(int)plyr_idx); erstat_inc(ESE_NoFreeThings); return INVALID_THING; } thing->class_id = TCls_Trap; thing->model = trpkind; thing->mappos.x.val = pos->x.val; thing->mappos.y.val = pos->y.val; thing->mappos.z.val = pos->z.val; thing->next_on_mapblk = 0; thing->parent_idx = thing->index; thing->owner = plyr_idx; char start_frame; if (trapstat->field_13) { start_frame = -1; } else { start_frame = 0; } set_thing_draw(thing, trapstat->field_4, trapstat->field_D, trapstat->field_8, trapstat->field_C, start_frame, 2); if (trapstat->field_11) { thing->field_4F |= 0x02; } else { thing->field_4F &= ~0x02; } if (trapstat->field_C) { thing->field_4F |= 0x40; } else { thing->field_4F &= ~0x40; } thing->clipbox_size_xy = trapstat->size_xy; thing->clipbox_size_yz = trapstat->field_16; thing->solid_size_xy = trapstat->size_xy; thing->field_5C = trapstat->field_16; thing->creation_turn = game.play_gameturn; thing->health = trapstat->field_0; thing->field_4F &= ~0x10; thing->field_4F |= 0x20; thing->byte_13 = 0; thing->long_14 = game.play_gameturn; if (trapstat->field_1C != 0) { ilght.mappos.x.val = thing->mappos.x.val; ilght.mappos.y.val = thing->mappos.y.val; ilght.mappos.z.val = thing->mappos.z.val; ilght.field_0 = trapstat->field_1C; ilght.field_2 = trapstat->field_1E; ilght.is_dynamic = 1; ilght.field_3 = trapstat->field_1F; thing->light_id = light_create_light(&ilght); if (thing->light_id <= 0) { SYNCDBG(8,"Cannot allocate dynamic light to %s.",thing_model_name(thing)); } } add_thing_to_its_class_list(thing); place_thing_in_mapwho(thing); return thing; }