Skip to content

Commit 9f03050

Browse files
committed
Allow launch/landing pads outside of campaign as voids/sources
1 parent 0afa47c commit 9f03050

File tree

2 files changed

+77
-17
lines changed

2 files changed

+77
-17
lines changed

core/src/mindustry/world/blocks/campaign/LandingPad.java

+72-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package mindustry.world.blocks.campaign;
22

33
import arc.*;
4+
import arc.Graphics.*;
5+
import arc.Graphics.Cursor.*;
46
import arc.graphics.*;
57
import arc.graphics.g2d.*;
68
import arc.math.*;
@@ -62,8 +64,16 @@ public LandingPad(String name){
6264
emitLight = true;
6365
lightRadius = 90f;
6466

65-
config(Item.class, (LandingPadBuild build, Item item) -> build.config = item);
66-
configClear((LandingPadBuild build) -> build.config = null);
67+
config(Item.class, (LandingPadBuild build, Item item) -> {
68+
if(!accessible()) return;
69+
70+
build.config = item;
71+
});
72+
configClear((LandingPadBuild build) -> {
73+
if(!accessible()) return;
74+
75+
build.config = null;
76+
});
6777
}
6878

6979
@Override
@@ -109,6 +119,10 @@ public static void landingPadLanded(Tile tile){
109119
build.handleLanding();
110120
}
111121

122+
public boolean accessible(){
123+
return state.rules.editor || state.rules.allowEditWorldProcessors || state.isCampaign();
124+
}
125+
112126
public class LandingPadBuild extends Building{
113127
public @Nullable Item config;
114128
//priority collisions are possible, but should be extremely rare
@@ -120,14 +134,16 @@ public class LandingPadBuild extends Building{
120134
public float liquidRemoved;
121135

122136
public void handleLanding(){
123-
if(!state.isCampaign() || config == null) return;
137+
if(config == null) return;
124138

125139
cooldown = 1f;
126140
arriving = config;
127141
arrivingTimer = 0f;
128142
liquidRemoved = 0f;
129143

130-
state.rules.sector.info.importCooldownTimers.put(config, 0f);
144+
if(state.isCampaign() && !isFake()){
145+
state.rules.sector.info.importCooldownTimers.put(config, 0f);
146+
}
131147
}
132148

133149
public void updateTimers(){
@@ -276,7 +292,9 @@ public void updateTile(){
276292
Effect.shake(3f, 3f, this);
277293

278294
items.set(arriving, itemCapacity);
279-
state.getSector().info.handleItemImport(arriving, itemCapacity);
295+
if(!isFake()){
296+
state.getSector().info.handleItemImport(arriving, itemCapacity);
297+
}
280298

281299
arriving = null;
282300
arrivingTimer = 0f;
@@ -292,29 +310,70 @@ public void updateTile(){
292310
cooldown = Mathf.clamp(cooldown);
293311
}
294312

295-
if(config != null && state.isCampaign() && !state.getPlanet().campaignRules.legacyLaunchPads){
313+
if(config != null && (isFake() || (state.isCampaign() && !state.getPlanet().campaignRules.legacyLaunchPads))){
296314

297-
if(cooldown <= 0f && efficiency > 0f && items.total() == 0 && state.rules.sector.info.getImportRate(state.getPlanet(), config) > 0f && state.rules.sector.info.importCooldownTimers.get(config, 0f) >= 1f){
315+
if(cooldown <= 0f && efficiency > 0f && items.total() == 0 && (isFake() || (state.rules.sector.info.getImportRate(state.getPlanet(), config) > 0f && state.rules.sector.info.importCooldownTimers.get(config, 0f) >= 1f))){
298316

299-
//queue landing for next frame
300-
waiting.get(config, Seq::new).add(this);
317+
if(isFake()){
318+
//there is no queue for enemy team blocks, it's all fake
319+
Call.landingPadLanded(tile);
320+
}else{
321+
//queue landing for next frame
322+
waiting.get(config, Seq::new).add(this);
323+
}
301324
}
302325
}
303326
}
304327

328+
/** @return whether this pad should receive items forever, essentially acting as an item source for maps. */
329+
public boolean isFake(){
330+
return team != state.rules.defaultTeam || !state.isCampaign();
331+
}
332+
305333
@Override
306334
public boolean canDump(Building to, Item item){
307335
//hack: canDump is only ever called right before item offload, so count the item as "produced" before that.
308-
//TODO: is this necessary?
309336
produced(item);
310337
return true;
311338
}
312339

340+
@Override
341+
public void drawSelect(){
342+
if(config != null){
343+
float dx = x - size * tilesize/2f, dy = y + size * tilesize/2f, s = iconSmall / 4f;
344+
Draw.mixcol(Color.darkGray, 1f);
345+
Draw.rect(config.fullIcon, dx, dy - 1, s, s);
346+
Draw.reset();
347+
Draw.rect(config.fullIcon, dx, dy, s, s);
348+
}
349+
}
350+
351+
@Override
352+
public Cursor getCursor(){
353+
return !accessible() ? SystemCursor.arrow : super.getCursor();
354+
}
355+
356+
@Override
357+
public boolean shouldShowConfigure(Player player){
358+
return accessible();
359+
}
360+
361+
@Override
362+
public boolean onConfigureBuildTapped(Building other){
363+
if(this == other || !accessible()){
364+
deselect();
365+
return false;
366+
}
367+
368+
return super.onConfigureBuildTapped(other);
369+
}
370+
313371
@Override
314372
public void buildConfiguration(Table table){
373+
315374
ItemSelection.buildTable(LandingPad.this, table, content.items(), () -> config, this::configure, selectionRows, selectionColumns);
316375

317-
if(!net.client()){
376+
if(!net.client() && !isFake()){
318377
table.row();
319378

320379
table.table(t -> {
@@ -340,11 +399,11 @@ public void buildConfiguration(Table table){
340399
public void display(Table table){
341400
super.display(table);
342401

343-
if(!state.isCampaign() || net.client() || team != player.team()) return;
402+
if(!state.isCampaign() || net.client() || team != player.team() || isFake()) return;
344403

345404
table.row();
346405
table.label(() -> {
347-
if(!state.isCampaign()) return "";
406+
if(!state.isCampaign() || isFake()) return "";
348407

349408
if(state.getPlanet().campaignRules.legacyLaunchPads){
350409
return Core.bundle.get("landingpad.legacy.disabled");

core/src/mindustry/world/blocks/campaign/LaunchPad.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ public void draw(){
104104

105105
super.draw();
106106

107-
if(!state.isCampaign()) return;
108-
109107
if(lightRegion.found()){
110108
Draw.color(lightColor);
111109
float progress = Math.min((float)items.total() / itemCapacity, launchCounter / launchTime);
@@ -136,7 +134,6 @@ public boolean acceptItem(Building source, Item item){
136134

137135
@Override
138136
public void updateTile(){
139-
if(!state.isCampaign()) return;
140137

141138
//increment launchCounter then launch when full and base conditions are met
142139
if((launchCounter += edelta()) >= launchTime && items.total() >= itemCapacity){
@@ -172,9 +169,13 @@ public void display(Table table){
172169
}).pad(4).wrap().width(200f).left();
173170
}
174171

172+
@Override
173+
public boolean shouldShowConfigure(Player player){
174+
return state.isCampaign();
175+
}
176+
175177
@Override
176178
public void buildConfiguration(Table table){
177-
//TODO: this UI should be on landing pads
178179
if(!state.isCampaign() || net.client()){
179180
deselect();
180181
return;

0 commit comments

Comments
 (0)