Skip to content

Commit

Permalink
Workday research (ldtteam#5625)
Browse files Browse the repository at this point in the history
Adjust walk home time for miners
Add research to allow citizen work into the night up to +2h
  • Loading branch information
someaddons authored Aug 22, 2020
1 parent 4b452cf commit a0a4980
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ public class CommonConfiguration extends AbstractConfiguration

public final ForgeConfigSpec.ConfigValue<List<? extends String>> circus;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> festival;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> nightowl;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> spectacle;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> nightowl2;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> opera;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> theater;

Expand Down Expand Up @@ -1149,9 +1151,15 @@ protected CommonConfiguration(final ForgeConfigSpec.Builder builder)
this.festival = defineList(builder, "festival",
Collections.singletonList("minecraft:cake*9"),
s -> s instanceof String);
this.nightowl = defineList(builder, "nightowl",
Collections.singletonList("minecraft:golden_carrot*25"),
s -> s instanceof String);
this.spectacle = defineList(builder, "spectacle",
Collections.singletonList("minecraft:cake*18"),
s -> s instanceof String);
this.nightowl2 = defineList(builder, "nightowl2",
Collections.singletonList("minecraft:golden_carrot*75"),
s -> s instanceof String);
this.opera = defineList(builder, "opera",
Collections.singletonList("minecraft:cake*27"),
s -> s instanceof String);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public final class ResearchConstants
public static final String KNIGHT_WHIRLWIND = "Whirldwind ability";
public static final String BLOCK_ATTACKS = "Block Attacks";
public static final String SLEEP_LESS = "Sleep Less";
public static final String WORK_LONGER = "Working day h";

public static final String TEACHING = "Teaching";
public static final String GROWTH = "Growth";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,31 @@ public class EntityCitizen extends AbstractEntityCitizen
/**
* Indicate if the citizen is mourning or not.
*/
private boolean mourning = false;
private boolean mourning = false;
/**
* Indicates if the citizen is hiding from the rain or not.
*/
private boolean hidingFromRain = false;
private boolean hidingFromRain = false;
/**
* IsChild flag
*/
private boolean child = false;
private boolean child = false;
/**
* Whether the citizen is currently running away
*/
private boolean currentlyFleeing = false;
private boolean currentlyFleeing = false;
/**
* Timer for the call for help cd.
*/
private int callForHelpCooldown = 0;
private int callForHelpCooldown = 0;
/**
* Distance walked for consuming food
*/
private float lastDistanceWalked = 0;
/**
* Citizen data view.
*/
private ICitizenDataView citizenDataView;
private ICitizenDataView citizenDataView;

/**
* The location used for requests
Expand Down Expand Up @@ -598,8 +602,9 @@ public boolean canPathOnRails()
*/
private void decreaseWalkingSaturation()
{
if (((int) (distanceWalkedModified + 1.0) % ACTIONS_EACH_BLOCKS_WALKED) == 0)
if (distanceWalkedModified - lastDistanceWalked > ACTIONS_EACH_BLOCKS_WALKED)
{
lastDistanceWalked = distanceWalkedModified;
decreaseSaturationForContinuousAction();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.minecolonies.api.util.BlockPosUtil;
import com.minecolonies.api.util.WorldUtil;
import com.minecolonies.coremod.colony.interactionhandling.SimpleNotificationInteraction;
import com.minecolonies.coremod.colony.jobs.JobMiner;
import com.minecolonies.coremod.research.AdditionModifierResearchEffect;
import net.minecraft.block.BedBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalBlock;
Expand All @@ -24,6 +26,7 @@

import static com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_BED_POS;
import static com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_IS_ASLEEP;
import static com.minecolonies.api.research.util.ResearchConstants.WORK_LONGER;
import static com.minecolonies.api.util.constant.CitizenConstants.NIGHT;
import static com.minecolonies.api.util.constant.Constants.*;

Expand Down Expand Up @@ -299,17 +302,30 @@ public float getRenderOffsetZ()
public boolean shouldGoSleep()
{
final BlockPos homePos = findHomePos();
final BlockPos citizenPos = citizen.getPosition();
BlockPos citizenPos = citizen.getPosition();

int additionalDist = 0;

// Additional distance for miners
if (citizen.getCitizenData().getJob() instanceof JobMiner && citizen.getCitizenData().getWorkBuilding().getPosition().getY() - 20 > citizenPos.getY())
{
final BlockPos workPos = citizen.getCitizenData().getWorkBuilding().getID();
additionalDist = (int) BlockPosUtil.getDistance2D(citizenPos, workPos) + Math.abs(citizenPos.getY() - workPos.getY()) * 3;
citizenPos = workPos;
}

// Calc distance with some y weight
final int xDiff = Math.abs(homePos.getX() - citizenPos.getX());
final int zDiff = Math.abs(homePos.getZ() - citizenPos.getZ());
final int yDiff = (int) (Math.abs(homePos.getY() - citizenPos.getY()) * Y_DIFF_WEIGHT);

final double timeNeeded = Math.sqrt(xDiff * xDiff + zDiff * zDiff + yDiff * yDiff) * TIME_PER_BLOCK;
final double timeNeeded = (Math.sqrt(xDiff * xDiff + zDiff * zDiff + yDiff * yDiff) + additionalDist) * TIME_PER_BLOCK;

final AdditionModifierResearchEffect effect =
citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffect(WORK_LONGER, AdditionModifierResearchEffect.class);

// Estimated arrival is 1hour past night
final double timeLeft = NIGHT - (citizen.world.getDayTime() % 24000);
final double timeLeft = (effect == null ? NIGHT : NIGHT + effect.getEffect() * 1000) - (citizen.world.getDayTime() % 24000);
if (timeLeft <= 0 || (timeLeft - timeNeeded <= 0))
{
if (citizen.getCitizenData().getWorkBuilding() != null)
Expand All @@ -326,5 +342,4 @@ public boolean shouldGoSleep()

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,25 @@ private static void buildCivilianTree(final IGlobalResearchTree researchTree)
final GlobalResearch festival = new GlobalResearch("festival", "civilian", "Festival", 3, new MultiplierModifierResearchEffect("Happiness", 0.1));
festival.setRequirement(new BuildingResearchRequirement(3, "cook"));

final GlobalResearch nightowl = new GlobalResearch("nightowl", "civilian", "Nightowl", 3, new AdditionModifierResearchEffect(WORK_LONGER, 1));
nightowl.setRequirement(new BuildingResearchRequirement(2, "library"));

final GlobalResearch spectacle = new GlobalResearch("spectacle", "civilian", "Spectacle", 4, new MultiplierModifierResearchEffect("Happiness", 0.15));
spectacle.setRequirement(new BuildingResearchRequirement(4, "cook"));

final GlobalResearch nightowl2 = new GlobalResearch("nightowl2", "civilian", "Nightowl II", 4, new AdditionModifierResearchEffect(WORK_LONGER, 2));
nightowl.setRequirement(new BuildingResearchRequirement(3, "townhall"));

final GlobalResearch opera = new GlobalResearch("opera", "civilian", "Opera", 5, new MultiplierModifierResearchEffect("Happiness", 0.2));
opera.setRequirement(new BuildingResearchRequirement(5, "cook"));

final GlobalResearch theater = new GlobalResearch("theater", "civilian", "Theater", 6, new MultiplierModifierResearchEffect("Happiness", 0.5));

firstaid.addChild(circus);
circus.addChild(festival);
circus.addChild(nightowl);
festival.addChild(spectacle);
festival.addChild(nightowl2);
spectacle.addChild(opera);
opera.addChild(theater);

Expand Down Expand Up @@ -548,6 +556,8 @@ private static void buildCivilianTree(final IGlobalResearchTree researchTree)

researchTree.addResearch(circus.getBranch(), circus);
researchTree.addResearch(festival.getBranch(), festival);
researchTree.addResearch(nightowl.getBranch(), nightowl);
researchTree.addResearch(nightowl2.getBranch(), nightowl2);
researchTree.addResearch(spectacle.getBranch(), spectacle);
researchTree.addResearch(opera.getBranch(), opera);
researchTree.addResearch(theater.getBranch(), theater);
Expand Down

0 comments on commit a0a4980

Please sign in to comment.