mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-26 15:27:19 +07:00
Objective flag system
This commit is contained in:
parent
efd30809e8
commit
0f3fc92746
@ -318,6 +318,9 @@ public class Logic implements ApplicationListener{
|
||||
if(!net.client() && first.complete()){
|
||||
state.rules.objectives.remove(0);
|
||||
first.completed();
|
||||
//apply flags.
|
||||
state.rules.objectiveFlags.removeAll(first.flagsRemoved);
|
||||
state.rules.objectiveFlags.addAll(first.flagsAdded);
|
||||
if(!headless){
|
||||
//delete markers
|
||||
for(var marker : first.markers){
|
||||
|
@ -172,9 +172,21 @@ public class MapObjectives{
|
||||
|
||||
/** Base abstract class for any in-map objective. */
|
||||
public static abstract class MapObjective{
|
||||
public String[] flagsAdded = {};
|
||||
public String[] flagsRemoved = {};
|
||||
public ObjectiveMarker[] markers = {};
|
||||
public @Nullable String details;
|
||||
|
||||
public MapObjective withFlags(String... flags){
|
||||
this.flagsAdded = flags;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MapObjective withFlagsRemoved(String... flags){
|
||||
this.flagsRemoved = flags;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MapObjective withMarkers(ObjectiveMarker... markers){
|
||||
this.markers = markers;
|
||||
return this;
|
||||
|
@ -118,6 +118,8 @@ public class Rules{
|
||||
public ObjectSet<Item> hiddenBuildItems = Items.erekirOnlyItems.asSet();
|
||||
/** Campaign-only map objectives. */
|
||||
public Seq<MapObjective> objectives = new Seq<>();
|
||||
/** Flags set by objectives. Used in world processors. */
|
||||
public ObjectSet<String> objectiveFlags = new ObjectSet<>();
|
||||
/** HIGHLY UNSTABLE/EXPERIMENTAL. DO NOT USE THIS. */
|
||||
public boolean fog = false;
|
||||
/** If fog = true, this is whether static (black) fog is enabled. */
|
||||
|
@ -1498,5 +1498,26 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetFlagI implements LInstruction{
|
||||
public int result, flag;
|
||||
|
||||
public GetFlagI(int result, int flag){
|
||||
this.result = result;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public GetFlagI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
if(exec.obj(flag) instanceof String str){
|
||||
exec.setbool(result, state.rules.objectiveFlags.contains(str));
|
||||
}else{
|
||||
exec.setobj(result, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
@ -1514,4 +1514,33 @@ public class LStatements{
|
||||
return new FetchI(type, builder.var(result), builder.var(team), builder.var(index));
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("getflag")
|
||||
public static class GetFlagStatement extends LStatement{
|
||||
public String result = "result", flag = "\"flag\"";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
fields(table, result, str -> result = str);
|
||||
|
||||
table.add(" = flag ");
|
||||
|
||||
fields(table, flag, str -> flag = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean privileged(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color color(){
|
||||
return Pal.logicWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new GetFlagI(builder.var(result), builder.var(flag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user