Skip to content

Commit

Permalink
Placing Exp Turrets in sandbox/editor (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith authored Sep 13, 2022
1 parent 2335c1f commit 5d3dfd9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions main/src/unity/world/blocks/exp/ExpTurret.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void drawPlace(int x, int y, int rotation, boolean valid){
if(rangeStart != rangeEnd) Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, rangeEnd, UnityPal.exp);
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, rangeStart, Pal.placing);

if(!valid && pregrade != null) drawPlaceText(Core.bundle.format("exp.pregrade", pregradeLevel, pregrade.localizedName), x, y, false);
if(!valid && checkPregrade()) drawPlaceText(Core.bundle.format("exp.pregrade", pregradeLevel, pregrade.localizedName), x, y, false);
}

@Override
Expand All @@ -194,11 +194,14 @@ public boolean canPlaceOn(Tile tile, Team team, int rotation){
if(tile == null) return false;
if(pregrade == null) return super.canPlaceOn(tile, team, rotation);

//don't bother checking requirements in sandbox or editor
if(!checkPregrade()) return true;

CoreBlock.CoreBuild core = team.core();
//must have all requirements
if(core == null || (!state.rules.infiniteResources && !core.items.has(requirements, state.rules.buildCostMultiplier))) return false;
if(core == null || (!core.items.has(requirements, state.rules.buildCostMultiplier))) return false;

//check is there is ONLY a single pregrade block INSIDE all the tiles it will replace - by tracking SEQS. This protocol is also known as UWAGH standard.
//check is there is ONLY a single pregrade block INSIDE all the tiles it will replace - by tracking SEGGS. This protocol is also known as UWAGH standard.
seqs.clear();
tile.getLinkedTilesAs(this, inside -> {
if(inside.build == null || seqs.contains(inside.build) || seqs.size > 1) return; //no point of checking if there are already two in seqs
Expand All @@ -207,6 +210,10 @@ public boolean canPlaceOn(Tile tile, Team team, int rotation){
return seqs.size == 1; //no more, no less; a healthy monogamous relationship.
}

public boolean checkPregrade(){
return pregrade != null && !state.rules.infiniteResources && !state.isEditor();
}

@Override
public void placeBegan(Tile tile, Block previous){
//finish placement immediately when a block is replaced.
Expand Down

0 comments on commit 5d3dfd9

Please sign in to comment.