Multiple unit stance support

This commit is contained in:
Anuken
2025-07-01 23:23:45 -04:00
parent b6195cc31e
commit 88fc46fed2
8 changed files with 141 additions and 42 deletions

View File

@@ -523,7 +523,7 @@ public class TypeIO{
write.b(3);
write.i(logic.controller.pos());
}else if(control instanceof CommandAI ai){
write.b(8);
write.b(9);
write.bool(ai.attackTarget != null);
write.bool(ai.targetPos != null);
@@ -559,7 +559,16 @@ public class TypeIO{
}
}
writeStance(write, ai.stance);
int count = content.unitStances().count(ai::hasStance);
write.b(count);
for(var stance : content.unitStances()){
if(ai.hasStance(stance)){
writeStance(write, stance);
}
}
}else if(control instanceof AssemblerAI){ //hate
write.b(5);
}else{
@@ -591,8 +600,8 @@ public class TypeIO{
out.controller = world.build(pos);
return out;
}
//type 4 is the old CommandAI with no commandIndex, type 6 is the new one with the index as a single byte, type 7 is the one with the command queue, 8 adds a stance
}else if(type == 4 || type == 6 || type == 7 || type == 8){
//type 4 is the old CommandAI with no commandIndex, type 6 is the new one with the index as a single byte, type 7 is the one with the command queue, 8 adds a stance, 9 adds multiple stances
}else if(type == 4 || type == 6 || type == 7 || type == 8 || type == 9){
CommandAI ai = prev instanceof CommandAI pai ? pai : new CommandAI();
boolean hasAttack = read.bool(), hasPos = read.bool();
@@ -616,14 +625,14 @@ public class TypeIO{
ai.attackTarget = null;
}
if(type == 6 || type == 7 || type == 8){
if(type == 6 || type == 7 || type == 8 || type == 9){
byte id = read.b();
ai.command = id < 0 ? null : content.unitCommand(id);
if(ai.command == null) ai.command = UnitCommand.moveCommand;
}
//command queue only in type 7/8
if(type == 7 || type == 8){
if(type == 7 || type == 8 || type == 9){
ai.commandQueue.clear();
int length = read.ub();
for(int i = 0; i < length; i++){
@@ -646,7 +655,12 @@ public class TypeIO{
}
if(type == 8){
ai.stance = readStance(read);
ai.setStance(readStance(read));
}else if(type == 9){
int stances = read.ub();
for(int i = 0; i < stances; i++){
ai.setStance(readStance(read));
}
}
return ai;