struct Thing *create_cave_in(struct Coord3d *pos, unsigned short cimodel, unsigned short owner) { struct MagicStats *magstat; struct Dungeon *dungeon; struct Thing *thing; if ( !i_can_allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots) ) { ERRORDBG(3,"Cannot create cave in %d for player %d. There are too many things allocated.",(int)cimodel,(int)owner); erstat_inc(ESE_NoFreeThings); return INVALID_THING; } thing = allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots); if (thing->index == 0) { ERRORDBG(3,"Should be able to allocate cave in %d for player %d, but failed.",(int)cimodel,(int)owner); erstat_inc(ESE_NoFreeThings); return INVALID_THING; } thing->class_id = TCls_CaveIn; thing->model = 0; thing->parent_idx = thing->index; memcpy(&thing->mappos,pos,sizeof(struct Coord3d)); thing->owner = owner; thing->creation_turn = game.play_gameturn; magstat = &game.keeper_power_stats[PwrK_CAVEIN]; thing->word_15 = magstat->time; thing->byte_13 = pos->x.stl.num; thing->byte_14 = pos->y.stl.num; thing->byte_17 = cimodel; thing->health = magstat->time; if (owner != game.neutral_player_num) { dungeon = get_dungeon(owner); dungeon->camera_deviate_quake = thing->word_15; } add_thing_to_its_class_list(thing); place_thing_in_mapwho(thing); return thing; }
struct Thing *create_ambient_sound(const struct Coord3d *pos, ThingModel model, PlayerNumber owner) { struct Thing *thing; if ( !i_can_allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots) ) { ERRORDBG(3,"Cannot create ambient sound %d for player %d. There are too many things allocated.",(int)model,(int)owner); erstat_inc(ESE_NoFreeThings); return INVALID_THING; } thing = allocate_free_thing_structure(FTAF_FreeEffectIfNoSlots); if (thing->index == 0) { ERRORDBG(3,"Should be able to allocate ambient sound %d for player %d, but failed.",(int)model,(int)owner); erstat_inc(ESE_NoFreeThings); return INVALID_THING; } thing->class_id = TCls_AmbientSnd; thing->model = model; thing->parent_idx = thing->index; memcpy(&thing->mappos,pos,sizeof(struct Coord3d)); thing->owner = owner; thing->field_4F |= TF4F_DoNotDraw; add_thing_to_its_class_list(thing); return thing; }
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; }