Added unit stances

This commit is contained in:
Anuken
2023-09-20 21:55:06 -04:00
parent 0d1c56fb60
commit 3e15f70efa
11 changed files with 206 additions and 30 deletions

View File

@@ -314,6 +314,16 @@ public class TypeIO{
return val == 255 ? null : UnitCommand.all.get(val);
}
public static void writeStance(Writes write, @Nullable UnitStance stance){
write.b(stance == null ? 255 : stance.id);
}
public static UnitStance readStance(Reads read){
int val = read.ub();
//never returns null
return val == 255 ? UnitStance.shootStance : UnitStance.all.get(val);
}
public static void writeEntity(Writes write, Entityc entity){
write.i(entity == null ? -1 : entity.id());
}
@@ -472,7 +482,7 @@ public class TypeIO{
write.b(3);
write.i(logic.controller.pos());
}else if(control instanceof CommandAI ai){
write.b(7);
write.b(8);
write.bool(ai.attackTarget != null);
write.bool(ai.targetPos != null);
@@ -507,6 +517,8 @@ public class TypeIO{
write.b(3);
}
}
writeStance(write, ai.stance);
}else if(control instanceof AssemblerAI){ //hate
write.b(5);
}else{
@@ -538,8 +550,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
}else if(type == 4 || type == 6 || type == 7){
//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){
CommandAI ai = prev instanceof CommandAI pai ? pai : new CommandAI();
boolean hasAttack = read.bool(), hasPos = read.bool();
@@ -562,13 +574,13 @@ public class TypeIO{
ai.attackTarget = null;
}
if(type == 6 || type == 7){
if(type == 6 || type == 7 || type == 8){
byte id = read.b();
ai.command = id < 0 ? null : UnitCommand.all.get(id);
}
//command queue only in type 7
if(type == 7){
if(type == 7 || type == 8){
ai.commandQueue.clear();
int length = read.ub();
for(int i = 0; i < length; i++){
@@ -590,6 +602,10 @@ public class TypeIO{
}
}
if(type == 8){
ai.stance = readStance(read);
}
return ai;
}else if(type == 5){
//augh