95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
// This file has been automatically generated by writeMessageClasses.js
|
|
|
|
import { MessageFlags } from '../../enums/MessageFlags';
|
|
import { MessageBase } from '../MessageBase';
|
|
import { Message } from '../../enums/Message';
|
|
|
|
export class SimulatorLoadMessage implements MessageBase
|
|
{
|
|
name = 'SimulatorLoad';
|
|
messageFlags = MessageFlags.Trusted | MessageFlags.FrequencyLow;
|
|
id = Message.SimulatorLoad;
|
|
|
|
SimulatorLoad: {
|
|
TimeDilation: number;
|
|
AgentCount: number;
|
|
CanAcceptAgents: boolean;
|
|
};
|
|
AgentList: {
|
|
CircuitCode: number;
|
|
X: number;
|
|
Y: number;
|
|
}[];
|
|
|
|
getSize(): number
|
|
{
|
|
return ((6) * this.AgentList.length) + 10;
|
|
}
|
|
|
|
writeToBuffer(buf: Buffer, pos: number): number
|
|
{
|
|
const startPos = pos;
|
|
buf.writeFloatLE(this.SimulatorLoad['TimeDilation'], pos);
|
|
pos += 4;
|
|
buf.writeInt32LE(this.SimulatorLoad['AgentCount'], pos);
|
|
pos += 4;
|
|
buf.writeUInt8((this.SimulatorLoad['CanAcceptAgents']) ? 1 : 0, pos++);
|
|
const count = this.AgentList.length;
|
|
buf.writeUInt8(this.AgentList.length, pos++);
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
buf.writeUInt32LE(this.AgentList[i]['CircuitCode'], pos);
|
|
pos += 4;
|
|
buf.writeUInt8(this.AgentList[i]['X'], pos++);
|
|
buf.writeUInt8(this.AgentList[i]['Y'], pos++);
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
|
|
readFromBuffer(buf: Buffer, pos: number): number
|
|
{
|
|
const startPos = pos;
|
|
let varLength = 0;
|
|
const newObjSimulatorLoad: {
|
|
TimeDilation: number,
|
|
AgentCount: number,
|
|
CanAcceptAgents: boolean
|
|
} = {
|
|
TimeDilation: 0,
|
|
AgentCount: 0,
|
|
CanAcceptAgents: false
|
|
};
|
|
newObjSimulatorLoad['TimeDilation'] = buf.readFloatLE(pos);
|
|
pos += 4;
|
|
newObjSimulatorLoad['AgentCount'] = buf.readInt32LE(pos);
|
|
pos += 4;
|
|
newObjSimulatorLoad['CanAcceptAgents'] = (buf.readUInt8(pos++) === 1);
|
|
this.SimulatorLoad = newObjSimulatorLoad;
|
|
if (pos >= buf.length)
|
|
{
|
|
return pos - startPos;
|
|
}
|
|
const count = buf.readUInt8(pos++);
|
|
this.AgentList = [];
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
const newObjAgentList: {
|
|
CircuitCode: number,
|
|
X: number,
|
|
Y: number
|
|
} = {
|
|
CircuitCode: 0,
|
|
X: 0,
|
|
Y: 0
|
|
};
|
|
newObjAgentList['CircuitCode'] = buf.readUInt32LE(pos);
|
|
pos += 4;
|
|
newObjAgentList['X'] = buf.readUInt8(pos++);
|
|
newObjAgentList['Y'] = buf.readUInt8(pos++);
|
|
this.AgentList.push(newObjAgentList);
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
}
|
|
|