Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,18 @@ private IState goToHut()
return SEARCH_HOSPITAL;
}

if (citizen.getCitizenSleepHandler().isAsleep() || EntityNavigationUtils.walkToBuilding(citizen, buildingWorker))
if (citizen.getCitizenSleepHandler().isAsleep())
{
if (isSleepingInHospitalBed())
{
return SEARCH_HOSPITAL;
}

citizen.getCitizenSleepHandler().onWakeUp();
return GO_TO_HUT;
}

if (EntityNavigationUtils.walkToBuilding(citizen, buildingWorker))
{
return SEARCH_HOSPITAL;
}
Expand All @@ -398,13 +409,43 @@ private IState goToHospital()
return SEARCH_HOSPITAL;
}

if (citizen.getCitizenSleepHandler().isAsleep() || EntityNavigationUtils.walkToPos(citizen, bestHospital, MIN_DIST_TO_HOSPITAL, true))
if (citizen.getCitizenSleepHandler().isAsleep())
{
if (isSleepingInHospitalBed())
{
return WAIT_FOR_CURE;
}

citizen.getCitizenSleepHandler().onWakeUp();
return GO_TO_HOSPITAL;
}

if (EntityNavigationUtils.walkToPos(citizen, bestHospital, MIN_DIST_TO_HOSPITAL, true))
{
return WAIT_FOR_CURE;
}
return SEARCH_HOSPITAL;
}

/**
* Check if the citizen is asleep in a hospital bed.
*
* @return true if the current sleeping location belongs to the hospital.
*/
private boolean isSleepingInHospitalBed()
{
final IColony colony = citizenData.getColony();
final BlockPos hospitalPos = colony.getServerBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
if (hospitalPos == null)
{
return false;
}

final IBuilding building = colony.getServerBuildingManager().getBuilding(hospitalPos);

return building instanceof BuildingHospital hospital && hospital.getBedList().contains(citizen.getCitizenSleepHandler().getBedLocation());
}

/**
* Search for a placeToPath within the colony of the citizen.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ private IState calculateNextState()
{
if (citizen.getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard guardJob)
{
if (shouldEat())
{
return CitizenAIState.EATING;
}

// Sick
if (citizen.getCitizenData().getCitizenDiseaseHandler().isSick() && guardJob.canAIBeInterrupted())
{
citizen.getCitizenData().setVisibleStatus(VisibleCitizenStatus.SICK);
return CitizenAIState.SICK;
}

if (shouldEat())
{
return CitizenAIState.EATING;
}

return CitizenAIState.WORK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private IAIState sleepParticles()
*/
protected IAIState sleep()
{
if (worker.getLastHurtByMob() != null || (sleepTimer -= getTickRate()) < 0)
if (job.getCitizen().getCitizenDiseaseHandler().isSick() || worker.getLastHurtByMob() != null || (sleepTimer -= getTickRate()) < 0)
{
stopSleeping();
((EntityCitizen) worker).getThreatTable().removeCurrentTarget();
Expand All @@ -339,7 +339,7 @@ protected IAIState sleep()
*/
private void stopSleeping()
{
if (getState() == GUARD_SLEEP)
if (getState() == GUARD_SLEEP || worker.getVehicle() instanceof SittingEntity)
{
worker.stopRiding();
worker.setPos(worker.getX(), worker.getY() + 1, worker.getZ());
Expand Down Expand Up @@ -778,8 +778,14 @@ private int getPersecutionDistance()
@Override
public boolean canBeInterrupted()
{
if (fighttimer > 0 || getState() == CombatAIStates.ATTACKING || worker.getLastAttacker() != null || buildingGuards.getRallyLocation() != null || buildingGuards.getTask()
.equals(GuardTaskSetting.FOLLOW))
final boolean isSick = job.getCitizen().getCitizenDiseaseHandler().isSick();

if (fighttimer > 0 || getState() == CombatAIStates.ATTACKING || worker.getLastAttacker() != null)
{
return false;
}

if (!isSick && (buildingGuards.getRallyLocation() != null || buildingGuards.getTask().equals(GuardTaskSetting.FOLLOW)))
{
return false;
}
Expand Down
Loading