Save unit variables in processors
This commit is contained in:
@@ -75,8 +75,8 @@ public class PayloadConveyor extends Block{
|
||||
public int step = -1, stepAccepted = -1;
|
||||
|
||||
@Override
|
||||
public boolean canControlSelect(Unit player){
|
||||
return this.item == null && !player.spawnedByCore && player.hitSize / tilesize <= payloadLimit && player.tileOn() != null && player.tileOn().build == this;
|
||||
public boolean canControlSelect(Unit unit){
|
||||
return this.item == null && unit.type.allowedInPayloads && !unit.spawnedByCore && unit.hitSize / tilesize <= payloadLimit && unit.tileOn() != null && unit.tileOn().build == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -525,19 +525,18 @@ public class LogicBlock extends Block{
|
||||
write.b(compressed);
|
||||
|
||||
//write only the non-constant variables
|
||||
int count = Structs.count(executor.vars, v -> !v.constant);
|
||||
int count = Structs.count(executor.vars, v -> !v.constant || v == executor.vars[LExecutor.varUnit]);
|
||||
|
||||
write.i(count);
|
||||
for(int i = 0; i < executor.vars.length; i++){
|
||||
Var v = executor.vars[i];
|
||||
|
||||
if(v.constant) continue;
|
||||
if(v.constant && i != LExecutor.varUnit) continue;
|
||||
|
||||
//write the name and the object value
|
||||
write.str(v.name);
|
||||
|
||||
Object value = v.isobj ? v.objval : v.numval;
|
||||
if(value instanceof Unit) value = null; //do not save units.
|
||||
TypeIO.writeObject(write, value);
|
||||
}
|
||||
|
||||
@@ -585,8 +584,12 @@ public class LogicBlock extends Block{
|
||||
//load up the variables that were stored
|
||||
for(int i = 0; i < varcount; i++){
|
||||
BVar dest = asm.getVar(names[i]);
|
||||
if(dest != null && !dest.constant){
|
||||
dest.value = values[i] instanceof BuildingBox box ? world.build(box.pos) : values[i];
|
||||
|
||||
if(dest != null && (!dest.constant || dest.id == LExecutor.varUnit)){
|
||||
dest.value =
|
||||
values[i] instanceof BuildingBox box ? box.unbox() :
|
||||
values[i] instanceof UnitBox box ? box.unbox() :
|
||||
values[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,8 +81,8 @@ public class PayloadBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlSelect(Unit player){
|
||||
return !player.spawnedByCore && this.payload == null && acceptUnitPayload(player) && player.tileOn() != null && player.tileOn().build == this;
|
||||
public boolean canControlSelect(Unit unit){
|
||||
return !unit.spawnedByCore && unit.type.allowedInPayloads && this.payload == null && acceptUnitPayload(unit) && unit.tileOn() != null && unit.tileOn().build == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -87,7 +87,8 @@ public class PayloadDeconstructor extends PayloadBlock{
|
||||
|
||||
@Override
|
||||
public boolean acceptUnitPayload(Unit unit){
|
||||
return payload == null && deconstructing == null && !unit.spawnedByCore && unit.type.getTotalRequirements().length > 0 && unit.hitSize / tilesize <= maxPayloadSize;
|
||||
return payload == null && deconstructing == null && unit.type.allowedInPayloads && !unit.spawnedByCore
|
||||
&& unit.type.getTotalRequirements().length > 0 && unit.hitSize / tilesize <= maxPayloadSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user