short move_to_position(struct Thing *creatng) { CreatureStateCheck callback; struct CreatureControl *cctrl; struct StateInfo *stati; long move_result; CrCheckRet state_check; long speed; TRACE_THING(creatng); cctrl = creature_control_get_from_thing(creatng); speed = get_creature_speed(creatng); SYNCDBG(18,"Starting to move %s index %d into (%d,%d)",thing_model_name(creatng),(int)creatng->index,(int)cctrl->moveto_pos.x.stl.num,(int)cctrl->moveto_pos.y.stl.num); // Try teleporting the creature if (creature_move_to_using_teleport(creatng, &cctrl->moveto_pos, speed)) { SYNCDBG(8,"Teleporting %s index %d owner %d into (%d,%d) for %s",thing_model_name(creatng),(int)creatng->index,(int)creatng->owner, (int)cctrl->moveto_pos.x.stl.num,(int)cctrl->moveto_pos.y.stl.num,creature_state_code_name(creatng->continue_state)); return 1; } move_result = creature_move_to(creatng, &cctrl->moveto_pos, speed, cctrl->move_flags, 0); state_check = CrCkRet_Available; stati = get_thing_continue_state_info(creatng); if (!state_info_invalid(stati)) { callback = stati->move_check; if (callback != NULL) { SYNCDBG(18,"Doing move check callback for continue state %s",creature_state_code_name(creatng->continue_state)); state_check = callback(creatng); } } if (state_check == CrCkRet_Available) { // If moving was successful if (move_result == 1) { // Back to "main state" internal_set_thing_state(creatng, creatng->continue_state); return CrStRet_Modified; } // If moving failed, do a reset if (move_result == -1) { CrtrStateId cntstat; cntstat = creatng->continue_state; internal_set_thing_state(creatng, cntstat); set_start_state(creatng); SYNCDBG(8,"Couldn't move %s to place required for state %s; reset to state %s",thing_model_name(creatng),creature_state_code_name(cntstat),creatrtng_actstate_name(creatng)); return CrStRet_ResetOk; } // If continuing the job, check for job stress process_job_stress_and_going_postal(creatng); } switch (state_check) { case CrCkRet_Deleted: return CrStRet_Deleted; case CrCkRet_Available: return CrStRet_Modified; default: return CrStRet_ResetOk; } }
/** * Does a step of researching. * Informs if the research cycle should end. * @param thing */ CrCheckRet process_research_function(struct Thing *creatng) { struct Dungeon *dungeon; struct Room *room; dungeon = get_dungeon(creatng->owner); if (dungeon_invalid(dungeon)) { SYNCDBG(9,"The %s index %d cannot work as player %d has no dungeon", thing_model_name(creatng), (int)creatng->index, (int)creatng->owner); set_start_state(creatng); return CrCkRet_Continue; } if (!creature_can_do_research(creatng)) { set_start_state(creatng); return CrCkRet_Continue; } room = get_room_creature_works_in(creatng); if ( !room_still_valid_as_type_for_thing(room, RoK_LIBRARY, creatng) ) { WARNLOG("Room %s owned by player %d is bad work place for %s index %d owner %d", room_code_name(room->kind), (int)room->owner, thing_model_name(creatng),(int)creatng->index,(int)creatng->owner); set_start_state(creatng); return CrCkRet_Continue; } long work_value; struct CreatureControl *cctrl; cctrl = creature_control_get_from_thing(creatng); struct CreatureStats *crstat; crstat = creature_stats_get_from_thing(creatng); work_value = compute_creature_work_value(crstat->research_value*256, room->efficiency, cctrl->explevel); work_value = process_work_speed_on_work_value(creatng, work_value); SYNCDBG(19,"The %s index %d produced %d research points",thing_model_name(creatng),(int)creatng->index,(int)work_value); dungeon->total_research_points += work_value; dungeon->research_progress += work_value; //TODO CREATURE_JOBS going postal should be possible for all jobs, not only research process_job_stress_and_going_postal(creatng, room); return CrCkRet_Available; }