use of com.minecolonies.api.colony.ICitizenData in project minecolonies by ldtteam.
the class CitizenHappinessHandler method getSocialModifier.
/**
* Get the social modifier for the colony.
*
* @param colony the colony.
* @return true if so.
*/
private double getSocialModifier(final IColony colony) {
final double total = colony.getCitizenManager().getCitizens().size();
double unemployment = 0;
double homelessness = 0;
double sickPeople = 0;
double hungryPeople = 0;
for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
if (!citizen.isChild() && citizen.getJob() == null) {
unemployment++;
}
if (citizen.getHomeBuilding() == null) {
homelessness++;
}
if (citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().isSick()) {
sickPeople++;
}
if (citizen.getSaturation() <= 1) {
hungryPeople++;
}
}
return (total - (unemployment + homelessness + sickPeople + hungryPeople)) / total;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by ldtteam.
the class CitizenHappinessHandler method getGuardFactor.
/**
* Get the guard security happiness modifier from the colony.
*
* @param colony the colony.
* @return true if so.
*/
private double getGuardFactor(final IColony colony) {
double guards = 1;
double workers = 1;
for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
if (citizen.getJob() instanceof AbstractJobGuard) {
guards++;
} else {
workers++;
}
}
return Math.min(guards / (workers * 2 / 3), 2);
}
use of com.minecolonies.api.colony.ICitizenData in project AdvancedPeripherals by Seniorendi.
the class MineColonies method buildingToObject.
/**
* Returns information about the building like structure data, the citizens and some other values
*
* @param buildingManager The building manager of the colony
* @param building The building as instance
* @param pos The location of the buildings block
* @return information about the building
*/
public static Object buildingToObject(IBuildingManager buildingManager, IBuilding building, BlockPos pos) {
Map<String, Object> structureData = new HashMap<>();
structureData.put("cornerA", building.getCorners().getA());
structureData.put("cornerB", building.getCorners().getB());
structureData.put("rotation", building.getRotation());
structureData.put("mirror", building.isMirrored());
List<Object> citizensData = new ArrayList<>();
for (ICitizenData citizen : building.getAllAssignedCitizen()) {
Map<String, Object> citizenData = new HashMap<>();
citizenData.put("id", citizen.getId());
citizenData.put("name", citizen.getName());
citizensData.add(citizenData);
}
Map<String, Object> map = new HashMap<>();
map.put("location", LuaConverter.posToObject(pos));
map.put("type", building.getSchematicName());
map.put("style", building.getStyle());
map.put("level", building.getBuildingLevel());
map.put("maxLevel", building.getMaxBuildingLevel());
map.put("name", building.getCustomBuildingName());
map.put("built", building.isBuilt());
map.put("isWorkingOn", building.hasWorkOrder());
map.put("priority", building.getPickUpPriority());
map.put("structure", structureData);
map.put("citizens", citizensData);
map.put("storageBlocks", building.getContainers().size());
map.put("storageSlots", getStorageSize(building));
map.put("guarded", buildingManager.hasGuardBuildingNear(building));
return map;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class BuildingManager method removeBuilding.
@Override
public void removeBuilding(@NotNull final IBuilding building, final Set<ServerPlayerEntity> subscribers) {
if (buildings.containsKey(building.getID())) {
final ImmutableMap.Builder<BlockPos, IBuilding> builder = new ImmutableMap.Builder<>();
for (final IBuilding tbuilding : buildings.values()) {
if (tbuilding != building) {
builder.put(tbuilding.getID(), tbuilding);
}
}
buildings = builder.build();
for (final ServerPlayerEntity player : subscribers) {
Network.getNetwork().sendToPlayer(new ColonyViewRemoveBuildingMessage(colony, building.getID()), player);
}
Log.getLogger().info(String.format("Colony %d - removed AbstractBuilding %s of type %s", colony.getID(), building.getID(), building.getSchematicName()));
}
if (building instanceof BuildingTownHall) {
townHall = null;
} else if (building instanceof BuildingWareHouse) {
wareHouses.remove(building);
} else if (building instanceof BuildingMysticalSite) {
mysticalSites.remove(building);
}
// Allow Citizens to fix up any data that wasn't fixed up by the AbstractBuilding's own onDestroyed
for (@NotNull final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
citizen.onRemoveBuilding(building);
building.cancelAllRequestsOfCitizen(citizen);
}
colony.getRequestManager().onProviderRemovedFromColony(building);
colony.getRequestManager().onRequesterRemovedFromColony(building.getRequester());
colony.getCitizenManager().calculateMaxCitizens();
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class BuildingBuilder method searchWorkOrder.
@Override
public void searchWorkOrder() {
final ICitizenData citizen = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
if (citizen == null) {
return;
}
final List<IWorkOrder> list = getColony().getWorkManager().getOrderedList(wo -> wo.canBeMadeBy(citizen.getJob()), getPosition());
list.sort((a, b) -> {
if (a.getWorkOrderType() == WorkOrderType.REMOVE) {
return -1;
}
if (b.getWorkOrderType() == WorkOrderType.REMOVE) {
return 1;
}
return 0;
});
final IWorkOrder order = list.stream().filter(w -> w.getClaimedBy() != null && w.getClaimedBy().equals(getPosition())).findFirst().orElse(null);
if (order != null) {
citizen.getJob(JobBuilder.class).setWorkOrder(order);
order.setClaimedBy(citizen);
return;
}
if (getManualMode()) {
return;
}
for (final IWorkOrder wo : list) {
double distanceToBuilder = Double.MAX_VALUE;
if (wo instanceof WorkOrderBuilding && wo.getWorkOrderType() != WorkOrderType.REMOVE && !wo.canBuild(citizen)) {
continue;
}
for (@NotNull final ICitizenData otherBuilder : getColony().getCitizenManager().getCitizens()) {
final JobBuilder job = otherBuilder.getJob(JobBuilder.class);
if (job == null || otherBuilder.getWorkBuilding() == null || citizen.getId() == otherBuilder.getId()) {
continue;
}
if (!job.hasWorkOrder() && wo instanceof WorkOrderBuilding && wo.canBuild(otherBuilder)) {
final double distance = otherBuilder.getWorkBuilding().getID().distSqr(wo.getLocation());
if (distance < distanceToBuilder) {
distanceToBuilder = distance;
}
}
}
if (citizen.getWorkBuilding().getID().distSqr(wo.getLocation()) < distanceToBuilder) {
citizen.getJob(JobBuilder.class).setWorkOrder(wo);
wo.setClaimedBy(citizen);
return;
}
}
}
Aggregations