Skip to content

Commit

Permalink
-Added a missing 0 check for district distribution (not the cause for…
Browse files Browse the repository at this point in the history
… issue #8 though)

-Added a possible solution for the district overlay on client side
  • Loading branch information
CptCrispyCrunchy committed Aug 8, 2016
1 parent 59cc186 commit 90fe14e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import org.terasology.network.NetworkSystem;
import org.terasology.registry.In;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

@RegisterSystem(RegisterMode.CLIENT)
public class DistrictFacetOverlaySystem extends BaseComponentSystem {
Expand All @@ -55,28 +57,29 @@ public class DistrictFacetOverlaySystem extends BaseComponentSystem {

private EntityRef clientEntity;

private boolean isOverlayAdded;
private Map<EntityRef, Boolean> isOverlayAdded;

@Override
public void initialise() {
if (networkSystem.getMode() == NetworkMode.CLIENT) {
clientEntity = networkSystem.getServer().getClientEntity();
}
isOverlayAdded = new HashMap<>();
}
@ReceiveEvent
public void onAddOverlayEvent(AddDistrictOverlayEvent event, EntityRef entityRef) {
if (networkSystem.getMode() == NetworkMode.CLIENT) {
if (clientEntity.getComponent(ClientComponent.class).character.getId() == entityRef.getId() && !isOverlayAdded) {
if (clientEntity.getComponent(ClientComponent.class).character.getId() == entityRef.getId() && !isOverlayAdded.getOrDefault(entityRef, false)) {
Iterator<EntityRef> entityRefs = entityManager.getEntitiesWith(SettlementsCacheComponent.class).iterator();
if (entityRefs.hasNext()) {
minimapSystem.addOverlay(new DistrictOverlay((entityRefs.next())));
isOverlayAdded = true;
isOverlayAdded.put(entityRef, true);
} else {
logger.error("No SettlementCache found! Unable to create district overlay");
}
}
}
if (networkSystem.getMode() == NetworkMode.DEDICATED_SERVER && !isOverlayAdded) {
if (networkSystem.getMode() == NetworkMode.DEDICATED_SERVER && !isOverlayAdded.getOrDefault(entityRef, false)) {
if (localPlayer.getCharacterEntity() == entityRef) {
Iterator<EntityRef> entityRefs = entityManager.getEntitiesWith(SettlementsCacheComponent.class).iterator();
if (entityRefs.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ else if (tempZoneArea.get(zone) / totalAssignedArea > culturalNeedsPercentage.ge
diff += TeraMath.fastAbs(tempZoneArea.get(zone) / totalAssignedArea - culturalNeedsPercentage.get(zone));
}
}
diff = 1 / diff;

diff = (diff == 0) ? 0 : 1 / diff;
probabilites.put(districtType, diff);
totalDiff += diff;
}
Expand Down

0 comments on commit 90fe14e

Please sign in to comment.