TbBool attempt_job_move_to_event_for_player(struct Thing *creatng, PlayerNumber plyr_idx, CreatureJob new_job) { EventKind evkind; struct Event *event; evkind = get_event_for_job(new_job); event = get_event_of_type_for_player(evkind, creatng->owner); // Treat heart attack as enemy fight, too if (event_is_invalid(event) && (evkind == EvKind_EnemyFight)) { event = get_event_of_type_for_player(EvKind_HeartAttacked, creatng->owner); } if (event_is_invalid(event)) { return false; } if (!setup_person_move_to_position(creatng, coord_subtile(event->mappos_x), coord_subtile(event->mappos_y), NavRtF_Default)) { return false; } creatng->continue_state = get_initial_state_for_job(new_job); return true; }
void play_thing_walking(struct Thing *thing) { struct PlayerInfo *myplyr; myplyr = get_my_player(); struct Camera *cam; cam = myplyr->acamera; { // Skip the thing if its distance to camera is too big MapSubtlDelta dist_x, dist_y; dist_x = coord_subtile(abs(cam->mappos.x.val - (MapCoordDelta)thing->mappos.x.val)); dist_y = coord_subtile(abs(cam->mappos.y.val - (MapCoordDelta)thing->mappos.y.val)); if (dist_x <= dist_y) dist_x = dist_y; if (dist_x >= 10) { return; } } if ((get_creature_model_flags(thing) & CMF_IsSpectator) != 0) { // Spectators don't do sounds return; } long loudness; loudness = (myplyr->view_mode == PVM_CreatureView) ? (FULL_LOUDNESS) : (FULL_LOUDNESS/5); // Flying diptera has a buzzing noise sound if ((get_creature_model_flags(thing) & CMF_IsDiptera) && ((thing->movement_flags & TMvF_Flying) != 0) && (thing->field_60 < (int)thing->mappos.z.val)) { if ( !S3DEmitterIsPlayingSample(thing->snd_emitter_id, 25, 0) ) { thing_play_sample(thing, 25, 100, -1, 2, 0, 2, loudness); } } else { if ( S3DEmitterIsPlayingSample(thing->snd_emitter_id, 25, 0) ) { S3DDeleteSampleFromEmitter(thing->snd_emitter_id, 25, 0); } struct CreatureControl *cctrl; cctrl = creature_control_get_from_thing(thing); if ((cctrl->field_9) && get_foot_creature_has_down(thing)) { int smpl_variant; smpl_variant = foot_down_sound_sample_variant[4 * ((cctrl->mood_flags & 0x1C) >> 2) + (cctrl->field_67 & 0x1F)]; long smpl_idx; if ((thing->movement_flags & TMvF_Unknown80) != 0) { smpl_idx = 181 + smpl_variant; } else { struct CreatureSound *crsound; crsound = get_creature_sound(thing, CrSnd_Foot); smpl_idx = crsound->index + smpl_variant; } cctrl->field_67 = (cctrl->field_67 ^ (cctrl->field_67 ^ (cctrl->field_67 + 1))) & 0x1F; if ((cctrl->field_67 & 0x1F) >= 4) { cctrl->mood_flags &= ~0x1C; cctrl->mood_flags |= (UNSYNC_RANDOM(4) << 2); cctrl->field_67 &= ~0x1F; } int v15; unsigned short smpl_delay; //TODO CONFIG creature model dependency; remove, add config file option for this v15 = thing->model; if ( v15 == 19 || v15 == 24 ) {//FLY or BUG smpl_delay = 400; } else if ( v15 == 27 ) {//HELL_HOUND smpl_delay = 300; } else { smpl_delay = 100; } thing_play_sample(thing, smpl_idx, smpl_delay, 0, 3, 3, 1, loudness); if ((thing->movement_flags & TMvF_IsOnWater) != 0) { thing_play_sample(thing, 21+SOUND_RANDOM(4), 90+SOUND_RANDOM(20), 0, 3, 3, 1, FULL_LOUDNESS); } } }
TbBool update_trap_trigger_line_of_sight_90(struct Thing *traptng) { static const MapSubtlDelta line_of_sight_90_range = 20; MapSubtlCoord stl_x_beg, stl_x_end; MapSubtlCoord stl_y_beg, stl_y_end; { MapCoord coord_x, coord_y; MapCoordDelta trap_radius; trap_radius = traptng->clipbox_size_xy / 2; coord_x = traptng->mappos.x.val; stl_x_beg = coord_subtile(coord_x - trap_radius); if (stl_x_beg <= 0) stl_x_beg = 0; stl_x_end = coord_subtile(coord_x + trap_radius); if (stl_x_end >= map_subtiles_x) stl_x_end = map_subtiles_x; coord_y = traptng->mappos.y.val; stl_y_beg = coord_subtile(coord_y - trap_radius); if (stl_y_beg <= 0) stl_y_beg = 0; stl_y_end = coord_subtile(coord_y + trap_radius); if (stl_y_end >= map_subtiles_y) stl_y_end = map_subtiles_y; } MapSubtlCoord stl_x_pre, stl_x_aft; MapSubtlCoord stl_y_pre, stl_y_aft; { stl_y_pre = stl_y_beg - line_of_sight_90_range; if (stl_y_pre <= 0) stl_y_pre = 0; stl_y_aft = stl_y_end + line_of_sight_90_range; if (stl_y_aft >= map_subtiles_y+1) stl_y_aft = map_subtiles_y+1; stl_x_pre = stl_x_beg - line_of_sight_90_range; if (stl_x_pre <= 0) stl_x_pre = 0; stl_x_aft = stl_x_end + line_of_sight_90_range; if (stl_x_aft >= map_subtiles_x+1) stl_x_aft = map_subtiles_x+1; } MapSubtlCoord stl_x, stl_y; // Find a limit of where the trap will fit in negative Y for (stl_x=stl_x_beg; stl_x <= stl_x_end; stl_x++) { for (stl_y = stl_y_beg; stl_y >= stl_y_pre; stl_y--) { struct Map *mapblk; mapblk = get_map_block_at(stl_x, stl_y); if ((mapblk->flags & SlbAtFlg_Blocking) != 0) { stl_y_pre = stl_y + 1; break; } } } // Check the area for activation for (stl_x=stl_x_beg; stl_x <= stl_x_end; stl_x++) { for (stl_y = stl_y_beg; stl_y >= stl_y_pre; stl_y--) { if (update_trap_trigger_line_of_sight_90_on_subtile(traptng, stl_x, stl_y)) { return true; } } } // Find a limit of where the trap will fit in positive Y for (stl_x=stl_x_beg; stl_x <= stl_x_end; stl_x++) { for (stl_y = stl_y_end; stl_y <= stl_y_aft; stl_y++) { struct Map *mapblk; mapblk = get_map_block_at(stl_x, stl_y); if ((mapblk->flags & SlbAtFlg_Blocking) != 0) { stl_y_aft = stl_y - 1; break; } } } // Check the area for activation for (stl_x=stl_x_beg; stl_x <= stl_x_end; stl_x++) { for (stl_y = stl_y_end; stl_y <= stl_y_aft; stl_y++) { if (update_trap_trigger_line_of_sight_90_on_subtile(traptng, stl_x, stl_y)) { return true; } } } // Find a limit of where the trap will fit in positive X for (stl_y=stl_y_beg; stl_y <= stl_y_end; stl_y++) { for (stl_x=stl_x_end; stl_x <= stl_x_aft; stl_x++) { struct Map *mapblk; mapblk = get_map_block_at(stl_x, stl_y); if ((mapblk->flags & SlbAtFlg_Blocking) != 0) { stl_x_aft = stl_x - 1; break; } } } // Check the area for activation for (stl_y=stl_y_beg; stl_y <= stl_y_end; stl_y++) { for (stl_x=stl_x_end; stl_x <= stl_x_aft; stl_x++) { if (update_trap_trigger_line_of_sight_90_on_subtile(traptng, stl_x, stl_y)) { return true; } } } // Find a limit of where the trap will fit in negative X for (stl_y=stl_y_beg; stl_y <= stl_y_end; stl_y++) { for (stl_x=stl_x_beg; stl_x >= stl_x_pre; stl_x--) { struct Map *mapblk; mapblk = get_map_block_at(stl_x, stl_y); if ((mapblk->flags & SlbAtFlg_Blocking) != 0) { stl_x_pre = stl_x + 1; break; } } } // Check the area for activation for (stl_y=stl_y_beg; stl_y <= stl_y_end; stl_y++) { for (stl_x=stl_x_beg; stl_x >= stl_x_pre; stl_x--) { if (update_trap_trigger_line_of_sight_90_on_subtile(traptng, stl_x, stl_y)) { return true; } } } return false; }