Search in sources :

Example 36 with ICitizenData

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;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 37 with ICitizenData

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);
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 38 with ICitizenData

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 39 with ICitizenData

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();
}
Also used : BuildingMysticalSite(com.minecolonies.coremod.colony.buildings.BuildingMysticalSite) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewRemoveBuildingMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage) NotNull(org.jetbrains.annotations.NotNull) ImmutableMap(com.google.common.collect.ImmutableMap) BuildingTownHall(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Example 40 with ICitizenData

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;
        }
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) JobBuilder(com.minecolonies.coremod.colony.jobs.JobBuilder) ICitizenData(com.minecolonies.api.colony.ICitizenData) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12