WIP command queueing

This commit is contained in:
Anuken
2023-09-19 17:25:49 -04:00
parent a7ba018dc3
commit 2e0c5619b1
7 changed files with 136 additions and 14 deletions
+45 -4
View File
@@ -472,7 +472,7 @@ public class TypeIO{
write.b(3);
write.i(logic.controller.pos());
}else if(control instanceof CommandAI ai){
write.b(6);
write.b(7);
write.bool(ai.attackTarget != null);
write.bool(ai.targetPos != null);
@@ -489,6 +489,24 @@ public class TypeIO{
}
}
write.b(ai.command == null ? -1 : ai.command.id);
write.b(ai.commandQueue.size);
for(var pos : ai.commandQueue){
if(pos instanceof Building b){
write.b(0);
write.i(b.pos());
}else if(pos instanceof Unit u){
write.b(1);
write.i(u.id);
}else if(pos instanceof Vec2 v){
write.b(2);
write.f(v.x);
write.f(v.y);
}else{
//who put garbage in the command queue??
write.b(3);
}
}
}else if(control instanceof AssemblerAI){ //hate
write.b(5);
}else{
@@ -520,8 +538,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.
}else if(type == 4 || type == 6){
//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){
CommandAI ai = prev instanceof CommandAI pai ? pai : new CommandAI();
boolean hasAttack = read.bool(), hasPos = read.bool();
@@ -544,11 +562,34 @@ public class TypeIO{
ai.attackTarget = null;
}
if(type == 6){
if(type == 6 || type == 7){
byte id = read.b();
ai.command = id < 0 ? null : UnitCommand.all.get(id);
}
//command queue only in type 7
if(type == 7){
ai.commandQueue.clear();
int length = read.ub();
for(int i = 0; i < length; i++){
int commandType = read.b();
switch(commandType){
case 0 -> {
var build = world.build(read.i());
if(build != null) ai.commandQueue.add(build);
}
case 1 -> {
var unit = Groups.unit.getByID(read.i());
if(unit != null) ai.commandQueue.add(unit);
}
case 2 -> {
ai.commandQueue.add(new Vec2(read.f(), read.f()));
}
//otherwise disregard
}
}
}
return ai;
}else if(type == 5){
//augh