Skip to content

Commit

Permalink
Added option to make free tiles/guards cost upkeep.
Browse files Browse the repository at this point in the history
Added option to allow a grace period, during which the village in question will not pay upkeep.
  • Loading branch information
Mthec committed Apr 29, 2021
1 parent 479fb43 commit 59dd7f6
Show file tree
Hide file tree
Showing 22 changed files with 445 additions and 137 deletions.
2 changes: 1 addition & 1 deletion src/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="jar" name="Upkeep Cost Settings">
<target name="jar">
<manifest file="MANIFEST.MF">
<attribute name="Implementation-Version" value="1.4.3"/>
<attribute name="Implementation-Version" value="1.5"/>
</manifest>

<jar manifest="MANIFEST.MF" destfile="../out/jar/mods/upkeepcosts/upkeepcosts.jar">
Expand Down
27 changes: 17 additions & 10 deletions src/com/wurmonline/server/questions/GuardManagementQuestion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.wurmonline.server.economy.Economy;
import com.wurmonline.server.economy.MonetaryConstants;
import com.wurmonline.server.villages.GuardPlan;
import com.wurmonline.server.villages.GuardPlanMethods;
import com.wurmonline.server.villages.Village;
import com.wurmonline.server.villages.Villages;
import mod.wurmonline.mods.upkeepcosts.UpkeepCosts;

Expand All @@ -30,16 +32,17 @@ public void answer(Properties answers) {

public void sendQuestion() {
StringBuilder buf = new StringBuilder(this.getBmlHeader());
if (this.getResponder().getCitizenVillage() != null) {
if (this.getResponder().getCitizenVillage().plan != null) {
GuardPlan plan = this.getResponder().getCitizenVillage().plan;
if (this.getResponder().getCitizenVillage().isCitizen(this.getResponder())) {
buf.append("text{text=\"The size of " + this.getResponder().getCitizenVillage().getName() + " is " + this.getResponder().getCitizenVillage().getDiameterX() + " by " + this.getResponder().getCitizenVillage().getDiameterY() + ".\"}");
buf.append("text{text=\"The perimeter is " + (5 + this.getResponder().getCitizenVillage().getPerimeterSize()) + " and it has " + plan.getNumHiredGuards() + " guards hired.\"}");
Village village = this.getResponder().getCitizenVillage();
if (village != null) {
GuardPlan plan = village.plan;
if (plan != null) {
if (village.isCitizen(this.getResponder())) {
buf.append("text{text=\"The size of " + village.getName() + " is " + village.getDiameterX() + " by " + village.getDiameterY() + ".\"}");
buf.append("text{text=\"The perimeter is " + (5 + village.getPerimeterSize()) + " and it has " + plan.getNumHiredGuards() + " guards hired.\"}");
}

buf.append("text{text=\"\"}");
if (this.getResponder().getCitizenVillage().isPermanent) {
if (village.isPermanent) {
buf.append("text{text='This village is permanent, and should never run out of money or be drained.'}");
} else {
Change c = Economy.getEconomy().getChangeFor(plan.moneyLeft);
Expand All @@ -48,10 +51,14 @@ public void sendQuestion() {
buf.append("text{text='Upkeep per month is " + upkeep.getChangeString() + ".'}");
long monthlyCost = plan.getMonthlyCost();
float cost = (float)plan.moneyLeft / (float)monthlyCost;
if (monthlyCost == 0)
long grace = GuardPlanMethods.graceTimeRemaining(village);
if (monthlyCost == 0) {
buf.append("text{text=\"This means that the upkeep should last indefinitely.\"}");
else
} else if (UpkeepCosts.upkeep_grace_period > 0 && grace > 0) {
GuardPlanMethods.addGraceTimeRemaining(buf, grace);
} else {
buf.append("text{text=\"This means that the upkeep should last for about " + (cost * 28.0F) + " days.\"}");
}
if (Servers.localServer.PVPSERVER || Servers.localServer.id == 3) {
buf.append("text{text=\"A drain would cost " + new Change(plan.getMoneyDrained()).getChangeShortString() + ".\"};");
long minimumDrain = UpkeepCosts.min_drain;
Expand Down Expand Up @@ -82,7 +89,7 @@ public void sendQuestion() {

freeGuards = Math.max(0, UpkeepCosts.free_guards - plan.getNumHiredGuards());

buf.append("text{text=\"How many guards do you wish to have? You currently have " + plan.getNumHiredGuards() + ", can hire " + freeGuards + " more for free and may hire up to " + GuardPlan.getMaxGuards(this.getResponder().getCitizenVillage()) + ".\"};input{text=\"" + plan.getNumHiredGuards() + "\";id=\"hired\"}; ");
buf.append("text{text=\"How many guards do you wish to have? You currently have " + plan.getNumHiredGuards() + ", can hire " + freeGuards + " more for free and may hire up to " + GuardPlan.getMaxGuards(village) + ".\"};input{text=\"" + plan.getNumHiredGuards() + "\";id=\"hired\"}; ");
buf.append("text{text=\"\"};");

buf.append("harray{label{text=\"Take money from my bank if there is not enough in the coffers\"};checkbox{id=\"use_bank\";selected=\"false\";text=\" \"}}");
Expand Down
67 changes: 50 additions & 17 deletions src/com/wurmonline/server/questions/VillageFoundationQuestion.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,30 @@ private int getFreeGuards() {
return UpkeepCosts.free_guards;
}

private int getNonFreeTiles() {
return this.tiles - getFreeTiles();
}

private int getChargeableTiles() {
int tiles = this.tiles - getFreeTiles();
if (tiles < 0)
return 0;
return tiles;
int tiles;
if (UpkeepCosts.free_tiles_upkeep)
tiles = this.tiles;
else
tiles = this.tiles - getFreeTiles();
return Math.max(tiles, 0);
}

private int getNonFreePerimeter() {
return this.perimeterTiles - getFreePerimeter();
}

private int getChargeablePerimeter() {
int perimeter = this.perimeterTiles - getFreePerimeter();
if (perimeter < 0)
return 0;
return perimeter;
int perimeter;
if (UpkeepCosts.free_perimeter_upkeep)
perimeter = this.perimeterTiles;
else
perimeter = this.perimeterTiles - getFreePerimeter();
return Math.max(perimeter, 0);
}

private int getExpansionDiff(long free, int newSize, int oldSize) {
Expand Down Expand Up @@ -835,9 +847,9 @@ static long getExpandMoneyNeededFromBank(long moneyNeeded, Village village) {
}

private long getFoundingCost() {
long moneyNeeded = this.getChargeableTiles() * Villages.TILE_COST;
moneyNeeded += this.getChargeablePerimeter() * Villages.PERIMETER_COST;
moneyNeeded += (long)Math.max(0, this.selectedGuards - getFreeGuards()) * Villages.GUARD_COST;
long moneyNeeded = this.getNonFreeTiles() * Villages.TILE_COST;
moneyNeeded += this.getNonFreePerimeter() * Villages.PERIMETER_COST;
moneyNeeded += getNonFreeGuards(this.selectedGuards) * Villages.GUARD_COST;
return moneyNeeded;
}

Expand Down Expand Up @@ -1375,7 +1387,7 @@ private void addTileCost(StringBuilder buf) {
buf.append("text{text=\"You selected a size of ").append(this.diameterX).append(" by ").append(this.diameterY).append(".\"}");
if(!this.expanding) {
if(!Servers.localServer.isFreeDeeds()) {
buf.append("text{text=\"The Purchase price for these tiles are ").append((new Change(this.getChargeableTiles() * Villages.TILE_COST)).getChangeString()).append(".\"}");
buf.append("text{text=\"The Purchase price for these tiles are ").append((new Change(this.getNonFreeTiles() * Villages.TILE_COST)).getChangeString()).append(".\"}");
}

if(Servers.localServer.isUpkeep()) {
Expand Down Expand Up @@ -1417,7 +1429,7 @@ private void addPerimeterCost(StringBuilder buf) {
buf.append("text{text=\"You have selected a perimeter of 5").append(Servers.localServer.isFreeDeeds() ? "" : " free").append(" tiles plus ").append(this.initialPerimeter).append(" additional tiles from your settlement boundary.\"}");
if(this.initialPerimeter > 0) {
if(!Servers.localServer.isFreeDeeds()) {
buf.append("text{text=\"The initial cost for the perimeter tiles will be ").append((new Change(this.getChargeablePerimeter() * Villages.PERIMETER_COST)).getChangeString()).append(".\"}");
buf.append("text{text=\"The initial cost for the perimeter tiles will be ").append((new Change(this.getNonFreePerimeter() * Villages.PERIMETER_COST)).getChangeString()).append(".\"}");
}

if(Servers.localServer.isUpkeep()) {
Expand Down Expand Up @@ -1623,6 +1635,10 @@ public void sendQuestion() {
}

buf.append("text{text=\"Please enter in the boxes below the distances in tiles between").append(from).append("and the border of your settlement.").append(" Example: 5, 5, 6, 6 will create a deed 11 tiles by 13 tiles.").append(" Minimum is 5.\"}");
if (UpkeepCosts.free_tiles_upkeep)
buf.append("text{text=\"You get ").append(getFreePerimeter()).append(" tiles for free, but you still have to pay upkeep on them.\"}");
else
buf.append("text{text=\"You get ").append(getFreePerimeter()).append(" tiles for free.\"}");
buf.append("text{text=\"\"}");
buf.append("text{text=\"");
if(!Servers.localServer.isFreeDeeds()) {
Expand Down Expand Up @@ -1733,6 +1749,11 @@ public void sendQuestion2() {

buf.append("text{text=\"\"}");
buf.append("text{text=\"Please enter the number of tiles BEYOND the 5").append(Servers.localServer.isFreeDeeds() ? "" : " initial tiles that you get for free").append(". You can simply leave the number at zero if you are happy with the ").append(5).append(Servers.localServer.isFreeDeeds() ? "" : " free").append(" tiles or extend the perimeter at a later date.\"}");
if (UpkeepCosts.free_perimeter_upkeep)
buf.append("text{text=\"You get ").append(getFreePerimeter()).append(" tiles for free, but you still have to pay upkeep on them.\"}");
else
buf.append("text{text=\"You get ").append(getFreePerimeter()).append(" tiles for free.\"}");
buf.append("text{text=\"\"}");
buf.append("text{text=\"\"}");
buf.append("harray{label{text=\"Perimeter Size: 5").append(Servers.localServer.isFreeDeeds() ? "" : " free").append(" tiles plus: \"}");
buf.append("input{maxchars=\"3\";id=\"perimeter\";text=\"").append(this.initialPerimeter).append("\"};label{text=\" tiles radius\"}}");
Expand Down Expand Up @@ -1838,7 +1859,7 @@ public void sendQuestion4() {
buf.append("text{type=\"bold\";text=\"Do you wish to hire guards?\"}");
buf.append("text{text=\"\"}");
buf.append("text{text=\"For ").append(this.villageName).append(" you may hire up to ").append(this.maxGuards).append(" guards.\"}");
buf.append("text{text=\"You may have up to ").append(getFreeGuards()).append(" free guards.\"}");
buf.append("text{text=\"You may have up to ").append(getFreeGuards()).append(" free guards.").append(UpkeepCosts.free_guards_upkeep ? " Their initial cost is free, however you will still be charged upkeep." : "").append("\"}");
buf.append("text{text=\"\"}");
if(Servers.localServer.isChallengeOrEpicServer() && !Servers.localServer.isFreeDeeds()) {
buf.append("text{text=\"The only guard type is heavy guards. The running upkeep cost increases the more guards you have in a sort of ladder system. The first guards are cheaper than the last.\"};");
Expand Down Expand Up @@ -1911,6 +1932,18 @@ public void sendQuestion5() {
}

this.addTotalUpkeep(buf);
if (UpkeepCosts.upkeep_grace_period > 0) {
if (this.expanding) {
try {
Village village = Villages.getVillage(this.deed.getData2());
GuardPlanMethods.addGraceTimeRemaining(buf, GuardPlanMethods.graceTimeRemaining(village));
} catch (NoSuchVillageException ignored) {
// Handled below.
}
} else {
buf.append("text{text=\"This server has a grace period of ").append(UpkeepCosts.upkeep_grace_period).append(" days before you will start paying upkeep.\"}");
}
}
buf.append("text{text=\"\"}");
buf.append("text{type=\"bold\";text=\"Name and Type\"}");
if(!this.expanding) {
Expand Down Expand Up @@ -1951,20 +1984,20 @@ public void sendQuestion5() {
if (this.willHaveHighay()) {
if (!village.isHighwayAllowed()) {
hasError = true;
buf.append("text{type=\"bold\";color=\"255,0,0\";text=\"Error: The new size covers a highway but highways have not been allowed, see settlment settings to change this option.\"}");
buf.append("text{type=\"bold\";color=\"255,0,0\";text=\"Error: The new size covers a highway but highways have not been allowed, see settlement settings to change this option.\"}");
} else if (village.hasHighway()) {
buf.append("text{text=\"The new size will still cover a highway which is already allowed by settlement settings.\"}");
} else {
buf.append("text{text=\"The new size will now cover a highway which is already allowed by settlement settings.\"}");
}
} else if (village.isHighwayAllowed()) {
buf.append("text{text=\"Note: You will not be able to use KOS as highways have been enabled for this settlment, see settlment settings to change this option.\"}");
buf.append("text{text=\"Note: You will not be able to use KOS as highways have been enabled for this settlement, see settlement settings to change this option.\"}");
} else {
buf.append("label{text=\"Note: To allow KOS or Highways, use the settlement settings.\"}");
}
} else if (this.willHaveHighay()) {
hasError = true;
buf.append("text{type=\"bold\";color=\"255,0,0\";text=\"Error: Cannot expand over a highway if KOS is enabled, see settlment settings to change this option.\"}");
buf.append("text{type=\"bold\";color=\"255,0,0\";text=\"Error: Cannot expand over a highway if KOS is enabled, see settlement settings to change this option.\"}");
} else {
buf.append("text{text=\"Note: You will not be able to have highway through this settlement as KOS is active.\"}");
}
Expand Down
9 changes: 7 additions & 2 deletions src/com/wurmonline/server/questions/VillageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.wurmonline.server.kingdom.Kingdoms;
import com.wurmonline.server.villages.*;
import com.wurmonline.server.zones.FocusZone;
import mod.wurmonline.mods.upkeepcosts.UpkeepCosts;

import java.text.NumberFormat;
import java.util.Arrays;
Expand Down Expand Up @@ -125,10 +126,14 @@ public void sendQuestion() {
monthly = village.plan.getMonthlyCost();
change = new Change(monthly);
buf.append("text{text=\"The monthly cost is " + change.getChangeString() + ".\"}");
if (monthly == 0)
long grace = GuardPlanMethods.graceTimeRemaining(village);
if (monthly == 0) {
buf.append("text{text=\"The upkeep will last indefinitely.\"}");
else
} else if (UpkeepCosts.upkeep_grace_period > 0 && grace > 0) {
GuardPlanMethods.addGraceTimeRemaining(buf, grace);
} else {
buf.append("text{text=\"The upkeep will last approximately " + Server.getTimeFor(village.plan.getTimeLeft()) + " more.\"}");
}
}

buf.append("text{text=\"\"}");
Expand Down
9 changes: 7 additions & 2 deletions src/com/wurmonline/server/questions/VillageUpkeep.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.wurmonline.server.economy.MonetaryConstants;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.villages.*;
import mod.wurmonline.mods.upkeepcosts.UpkeepCosts;

import java.text.NumberFormat;
import java.util.Properties;
Expand Down Expand Up @@ -66,10 +67,14 @@ public void sendQuestion() {
buf1.append("text{text=\'Upkeep per month is " + upkeep.getChangeString() + ".\'}");
long monthlyCost = plan1.getMonthlyCost();
float cost = (float)plan1.moneyLeft / (float)monthlyCost;
if (monthlyCost == 0)
long grace = GuardPlanMethods.graceTimeRemaining(nsv);
if (monthlyCost == 0) {
buf1.append("text{text=\"This means that the upkeep should last indefinitely.\"}");
else
} else if (UpkeepCosts.upkeep_grace_period > 0 && grace > 0) {
GuardPlanMethods.addGraceTimeRemaining(buf1, grace);
} else {
buf1.append("text{text=\"This means that the upkeep should last for about " + (int)(cost * 28.0F) + " days.\"}");
}
if(Servers.localServer.PVPSERVER) {
buf1.append("text{text=\"A drain would cost " + Economy.getEconomy().getChangeFor(plan1.getMoneyDrained()).getChangeString() + ".\"};");
if(plan1.moneyLeft < plan1.getMoneyDrained() * 5) {
Expand Down
Loading

0 comments on commit 59dd7f6

Please sign in to comment.