Objective flag system

This commit is contained in:
Anuken 2022-04-14 16:23:39 -04:00
parent efd30809e8
commit 0f3fc92746
5 changed files with 67 additions and 0 deletions

View File

@ -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){

View File

@ -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;

View File

@ -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. */

View File

@ -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
}

View File

@ -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));
}
}
}