83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
![]() |
// SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
// Author: Sascha Nitsch https://contentnation.net/@grumpydevelop
|
||
|
|
||
|
interface ContactPoint {
|
||
|
dist: number;
|
||
|
angle: number;
|
||
|
}
|
||
|
class RobotStatus {
|
||
|
/**
|
||
|
* current health 0 = death, max depends on robot
|
||
|
*/
|
||
|
health: number;
|
||
|
/**
|
||
|
* x position, range 0..1000
|
||
|
*/
|
||
|
posX: number;
|
||
|
/**
|
||
|
* x position, range 0..1000
|
||
|
*/
|
||
|
posY: number;
|
||
|
/**
|
||
|
* rotation, range 0..360, 0: north, 90: east
|
||
|
*/
|
||
|
orientation: number;
|
||
|
/**
|
||
|
* gun orientation (relative to tank), range 0..360, 0 front, 90 right
|
||
|
*/
|
||
|
gunOrient: number
|
||
|
/**
|
||
|
* radar_position 0..360, 0 front, 90 right
|
||
|
*/
|
||
|
radarPos: number
|
||
|
contactPoints: ContactPoint[];
|
||
|
chainSpeedLeft: number;
|
||
|
chainSpeedRight: number;
|
||
|
simulationTime: number;
|
||
|
causedDamage: number;
|
||
|
|
||
|
constructor() {
|
||
|
this.health = 100;
|
||
|
this.posX = 0;
|
||
|
this.posY = 0;
|
||
|
this.orientation = 0;
|
||
|
this.gunOrient = 0;
|
||
|
this.radarPos = 0;
|
||
|
this.contactPoints = [];
|
||
|
this.chainSpeedLeft = 0;
|
||
|
this.chainSpeedRight = 0;
|
||
|
this.simulationTime = 0;
|
||
|
this.causedDamage = 0;
|
||
|
}
|
||
|
private prec(input: number): number {
|
||
|
return Math.round(input * 100) / 100;
|
||
|
}
|
||
|
toJSON() : string {
|
||
|
return JSON.stringify({
|
||
|
health: this.health,
|
||
|
posX: this.prec(this.posX),
|
||
|
posY: this.prec(this.posY),
|
||
|
orientation: this.prec(this.orientation),
|
||
|
gunOrient: this.prec(this.gunOrient),
|
||
|
radarPos: this.prec(this.radarPos),
|
||
|
contactPoints: this.contactPoints,
|
||
|
chainSpeedLeft: this.prec(this.chainSpeedLeft),
|
||
|
chainSpeedRight: this.prec(this.chainSpeedRight),
|
||
|
simulationTime: this.prec(this.simulationTime),
|
||
|
causedDamage: this.prec(this.causedDamage),
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class RobotStatusExt extends RobotStatus {
|
||
|
radarInc: boolean;
|
||
|
constructor() {
|
||
|
super();
|
||
|
this.radarInc = true;
|
||
|
}
|
||
|
toJSON() : string {
|
||
|
return super.toJSON();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export {RobotStatus, RobotStatusExt};
|