2020-12-07 12:51:31 -05:00
|
|
|
package mindustry.logic;
|
|
|
|
|
|
|
|
import arc.struct.*;
|
|
|
|
import mindustry.*;
|
|
|
|
import mindustry.content.*;
|
|
|
|
import mindustry.logic.LExecutor.*;
|
|
|
|
import mindustry.type.*;
|
|
|
|
import mindustry.world.*;
|
|
|
|
|
|
|
|
/** Stores global constants for logic processors. */
|
|
|
|
public class GlobalConstants{
|
|
|
|
private ObjectIntMap<String> namesToIds = new ObjectIntMap<>();
|
|
|
|
private Seq<Var> vars = new Seq<>(Var.class);
|
|
|
|
|
|
|
|
public void init(){
|
|
|
|
put("the end", null);
|
|
|
|
//add default constants
|
|
|
|
put("false", 0);
|
|
|
|
put("true", 1);
|
|
|
|
put("null", null);
|
|
|
|
|
2021-02-21 12:28:00 -05:00
|
|
|
//special enums
|
|
|
|
|
2021-02-22 10:18:42 -05:00
|
|
|
put("@ctrlProcessor", 1);
|
|
|
|
put("@ctrlPlayer", 2);
|
|
|
|
put("@ctrlFormation", 3);
|
2021-02-21 12:28:00 -05:00
|
|
|
|
2020-12-07 12:51:31 -05:00
|
|
|
//store base content
|
|
|
|
|
|
|
|
for(Item item : Vars.content.items()){
|
|
|
|
put("@" + item.name, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Liquid liquid : Vars.content.liquids()){
|
|
|
|
put("@" + liquid.name, liquid);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Block block : Vars.content.blocks()){
|
|
|
|
if(block.synthetic()){
|
|
|
|
put("@" + block.name, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//used as a special value for any environmental solid block
|
|
|
|
put("@solid", Blocks.stoneWall);
|
|
|
|
put("@air", Blocks.air);
|
|
|
|
|
|
|
|
for(UnitType type : Vars.content.units()){
|
|
|
|
put("@" + type.name, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
//store sensor constants
|
|
|
|
for(LAccess sensor : LAccess.all){
|
|
|
|
put("@" + sensor.name(), sensor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return a constant ID > 0 if there is a constant with this name, otherwise -1. */
|
|
|
|
public int get(String name){
|
|
|
|
return namesToIds.get(name, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return a constant variable by ID. ID is not bound checked and must be positive. */
|
|
|
|
public Var get(int id){
|
|
|
|
return vars.items[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Adds a constant value by name. */
|
|
|
|
public Var put(String name, Object value){
|
|
|
|
Var var = new Var(name);
|
|
|
|
var.constant = true;
|
|
|
|
if(value instanceof Number num){
|
|
|
|
var.numval = num.doubleValue();
|
|
|
|
}else{
|
|
|
|
var.isobj = true;
|
|
|
|
var.objval = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = vars.size;
|
|
|
|
namesToIds.put(name, index);
|
|
|
|
vars.add(var);
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
}
|