Commit 80699d25 authored by Roque's avatar Roque

Capture the flag game fixes

See merge request !1826
parents 21025d4d 7b79e062
...@@ -28,6 +28,7 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -28,6 +28,7 @@ var EnemyDroneAPI = /** @class */ (function () {
** Function called on start phase of the drone, just before onStart AI script ** Function called on start phase of the drone, just before onStart AI script
*/ */
EnemyDroneAPI.prototype.internal_start = function (drone) { EnemyDroneAPI.prototype.internal_start = function (drone) {
//TODO check, _targetCoordinates is not used. obsolete?
drone._targetCoordinates = drone.getCurrentPosition(); drone._targetCoordinates = drone.getCurrentPosition();
drone._maxAcceleration = this.getMaxAcceleration(); drone._maxAcceleration = this.getMaxAcceleration();
if (drone._maxAcceleration <= 0) { if (drone._maxAcceleration <= 0) {
...@@ -101,10 +102,6 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -101,10 +102,6 @@ var EnemyDroneAPI = /** @class */ (function () {
} }
}; };
EnemyDroneAPI.prototype.setAltitude = function (drone, altitude) {
drone._targetCoordinates.z = altitude;
};
EnemyDroneAPI.prototype.setStartingPosition = function (drone, x, y, z) { EnemyDroneAPI.prototype.setStartingPosition = function (drone, x, y, z) {
if (!drone._canPlay) { if (!drone._canPlay) {
if (z <= 0.05) { if (z <= 0.05) {
...@@ -288,11 +285,11 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -288,11 +285,11 @@ var EnemyDroneAPI = /** @class */ (function () {
}; };
EnemyDroneAPI.prototype.triggerParachute = function (drone) { EnemyDroneAPI.prototype.triggerParachute = function (drone) {
var drone_pos = drone.getCurrentPosition(); var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(drone_pos.x, drone_pos.y, 5); drone.setTargetCoordinates(drone_pos.latitude, drone_pos.longitude, 5);
}; };
EnemyDroneAPI.prototype.landed = function (drone) { EnemyDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition(); var drone_pos = drone.getCurrentPosition();
return Math.floor(drone_pos.z) < 10; return Math.floor(drone_pos.altitude) < 10;
}; };
EnemyDroneAPI.prototype.exit = function () { EnemyDroneAPI.prototype.exit = function () {
return; return;
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.20054.25134.60962</string> </value> <value> <string>1011.46035.33513.61849</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1695397984.38</float> <float>1697031010.99</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -17,7 +17,8 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -17,7 +17,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
MAX_PITCH = 25, MAX_PITCH = 25,
MAX_CLIMB_RATE = 8, MAX_CLIMB_RATE = 8,
MAX_SINK_RATE = 3, MAX_SINK_RATE = 3,
VIEW_SCOPE = 100; VIEW_SCOPE = 100,
MAX_MESSAGE_SIZE = 1024;
//** CONSTRUCTOR //** CONSTRUCTOR
function FixedWingDroneAPI(gameManager, drone_info, flight_parameters, id) { function FixedWingDroneAPI(gameManager, drone_info, flight_parameters, id) {
...@@ -137,11 +138,11 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -137,11 +138,11 @@ var FixedWingDroneAPI = /** @class */ (function () {
}*/ }*/
if (drone_position) { if (drone_position) {
drone_info = { drone_info = {
'altitudeRel' : drone_position.z, 'altitudeRel' : drone_position.altitude,
'altitudeAbs' : _this._mapManager.getMapInfo().start_AMSL + 'altitudeAbs' : _this._mapManager.getMapInfo().start_AMSL +
drone_position.z, drone_position.altitude,
'latitude' : drone_position.x, 'latitude' : drone_position.latitude,
'longitude' : drone_position.y, 'longitude' : drone_position.longitude,
'yaw': drone.getYaw(), 'yaw': drone.getYaw(),
'speed': drone.getAirSpeed(), 'speed': drone.getAirSpeed(),
'climbRate': drone.getClimbRate() 'climbRate': drone.getClimbRate()
...@@ -183,10 +184,10 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -183,10 +184,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
drone._targetCoordinates.z drone._targetCoordinates.z
), ),
bearing = this._computeBearing( bearing = this._computeBearing(
currentGeoCoordinates.x, currentGeoCoordinates.latitude,
currentGeoCoordinates.y, currentGeoCoordinates.longitude,
targetCoordinates.x, targetCoordinates.latitude,
targetCoordinates.y targetCoordinates.longitude
), ),
currentCosLat, currentCosLat,
currentLatRad, currentLatRad,
...@@ -223,10 +224,10 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -223,10 +224,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
} }
newYawRad = this._toRad(newYaw); newYawRad = this._toRad(newYaw);
currentLatRad = this._toRad(currentGeoCoordinates.x); currentLatRad = this._toRad(currentGeoCoordinates.latitude);
currentCosLat = Math.cos(currentLatRad); currentCosLat = Math.cos(currentLatRad);
currentSinLat = Math.sin(currentLatRad); currentSinLat = Math.sin(currentLatRad);
currentLonRad = this._toRad(currentGeoCoordinates.y); currentLonRad = this._toRad(currentGeoCoordinates.longitude);
verticalSpeed = this._getVerticalSpeed(drone); verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt( groundSpeed = Math.sqrt(
...@@ -356,6 +357,10 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -356,6 +357,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
}; };
FixedWingDroneAPI.prototype.sendMsg = function (msg, to) { FixedWingDroneAPI.prototype.sendMsg = function (msg, to) {
if (JSON.stringify(msg).length > MAX_MESSAGE_SIZE) {
//TODO what to do? truncate the msg? log a warning? crash the drone?
msg = {"error": "message too long (max 1024)"};
}
var _this = this, var _this = this,
droneList = _this._gameManager._droneList; droneList = _this._gameManager._droneList;
_this._gameManager.delay(function () { _this._gameManager.delay(function () {
...@@ -366,7 +371,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -366,7 +371,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
try { try {
drone.onGetMsg(msg); drone.onGetMsg(msg);
} catch (error) { } catch (error) {
console.warn('Drone crashed on sendMsg due to error:', error); console.warn('Drone crashed on onGetMsg due to error:', error);
drone._internal_crash(); drone._internal_crash();
} }
} }
...@@ -377,7 +382,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -377,7 +382,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
try { try {
droneList[to].onGetMsg(msg); droneList[to].onGetMsg(msg);
} catch (error) { } catch (error) {
console.warn('Drone crashed on sendMsg due to error:', error); console.warn('Drone crashed on onGetMsg due to error:', error);
droneList[to]._internal_crash(); droneList[to]._internal_crash();
} }
} }
...@@ -414,7 +419,8 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -414,7 +419,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
var context = this, result = { "obstacles": [], "drones": [] }, distance, var context = this, result = { "obstacles": [], "drones": [] }, distance,
other_position, drone_position = drone.getCurrentPosition(); other_position, drone_position = drone.getCurrentPosition();
function calculateDistance(a, b, _this) { function calculateDistance(a, b, _this) {
return _this._mapManager.latLonDistance([a.x, a.y], [b.x, b.y]); return _this._mapManager.latLonDistance([a.latitude, a.longitude],
[b.latitude, b.longitude]);
} }
context._gameManager._droneList.forEach(function (other) { context._gameManager._droneList.forEach(function (other) {
if (other.can_play && drone.id !== other.id) { if (other.can_play && drone.id !== other.id) {
...@@ -537,11 +543,11 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -537,11 +543,11 @@ var FixedWingDroneAPI = /** @class */ (function () {
}; };
FixedWingDroneAPI.prototype.triggerParachute = function (drone) { FixedWingDroneAPI.prototype.triggerParachute = function (drone) {
var drone_pos = drone.getCurrentPosition(); var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(drone_pos.x, drone_pos.y, 5); drone.setTargetCoordinates(drone_pos.latitude, drone_pos.longitude, 5);
}; };
FixedWingDroneAPI.prototype.landed = function (drone) { FixedWingDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition(); var drone_pos = drone.getCurrentPosition();
return Math.floor(drone_pos.z) < 10; return Math.floor(drone_pos.altitude) < 10;
}; };
FixedWingDroneAPI.prototype.exit = function () { FixedWingDroneAPI.prototype.exit = function () {
return; return;
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.5610.25987.56473</string> </value> <value> <string>1011.46032.14056.1553</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1695395371.67</float> <float>1696870145.24</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -149,16 +149,19 @@ var DroneManager = /** @class */ (function () { ...@@ -149,16 +149,19 @@ var DroneManager = /** @class */ (function () {
/** /**
* Set a target point to move * Set a target point to move
*/ */
DroneManager.prototype.setTargetCoordinates = function (x, y, z) { DroneManager.prototype.setTargetCoordinates =
this._internal_setTargetCoordinates(x, y, z); function (latitude, longitude, altitude) {
this._internal_setTargetCoordinates(latitude, longitude, altitude);
}; };
DroneManager.prototype._internal_setTargetCoordinates = DroneManager.prototype._internal_setTargetCoordinates =
function (x, y, z, radius) { function (latitude, longitude, altitude, radius) {
if (!this._canPlay) { if (!this._canPlay) {
return; return;
} }
//convert real geo-coordinates to virtual x-y coordinates //each drone API process coordinates on its needs
this._targetCoordinates = this._API.processCoordinates(x, y, z); //e.g. fixedwing drone converts real geo-coordinates to virtual x-y
this._targetCoordinates =
this._API.processCoordinates(latitude, longitude, altitude);
return this._API.internal_setTargetCoordinates( return this._API.internal_setTargetCoordinates(
this, this,
this._targetCoordinates, this._targetCoordinates,
...@@ -205,6 +208,7 @@ var DroneManager = /** @class */ (function () { ...@@ -205,6 +208,7 @@ var DroneManager = /** @class */ (function () {
return; return;
}; };
DroneManager.prototype._internal_crash = function (error) { DroneManager.prototype._internal_crash = function (error) {
this.last_position = this.position;
this._canCommunicate = false; this._canCommunicate = false;
this._controlMesh = null; this._controlMesh = null;
this._mesh = null; this._mesh = null;
...@@ -324,8 +328,9 @@ var DroneManager = /** @class */ (function () { ...@@ -324,8 +328,9 @@ var DroneManager = /** @class */ (function () {
/** /**
* Make the drone loiter (circle with a set radius) * Make the drone loiter (circle with a set radius)
*/ */
DroneManager.prototype.loiter = function (x, y, z, radius) { DroneManager.prototype.loiter =
this._internal_setTargetCoordinates(x, y, z, radius); function (latitude, longitude, altitude, radius) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, radius);
}; };
DroneManager.prototype.getFlightParameters = function () { DroneManager.prototype.getFlightParameters = function () {
if (this._API.getFlightParameters) { if (this._API.getFlightParameters) {
...@@ -443,9 +448,9 @@ var MapManager = /** @class */ (function () { ...@@ -443,9 +448,9 @@ var MapManager = /** @class */ (function () {
_this.map_info = map_param; _this.map_info = map_param;
Object.assign(_this.map_info, _this.mapUtils.map_info); Object.assign(_this.map_info, _this.mapUtils.map_info);
_this.map_info.initial_position = _this.mapUtils.convertToLocalCoordinates( _this.map_info.initial_position = _this.mapUtils.convertToLocalCoordinates(
_this.map_info.initial_position.x, _this.map_info.initial_position.latitude,
_this.map_info.initial_position.y, _this.map_info.initial_position.longitude,
_this.map_info.initial_position.z); _this.map_info.initial_position.altitude);
max = _this.map_info.width; max = _this.map_info.width;
if (_this.map_info.depth > max) { if (_this.map_info.depth > max) {
max = _this.map_info.depth; max = _this.map_info.depth;
...@@ -494,9 +499,9 @@ var MapManager = /** @class */ (function () { ...@@ -494,9 +499,9 @@ var MapManager = /** @class */ (function () {
enemy = {}; enemy = {};
Object.assign(enemy, geo_enemy); Object.assign(enemy, geo_enemy);
enemy.position = _this.mapUtils.convertToLocalCoordinates( enemy.position = _this.mapUtils.convertToLocalCoordinates(
geo_enemy.position.x, geo_enemy.position.latitude,
geo_enemy.position.y, geo_enemy.position.longitude,
geo_enemy.position.z); geo_enemy.position.altitude);
_this._enemy_list.push(enemy); _this._enemy_list.push(enemy);
}); });
// Obstacles // Obstacles
...@@ -505,9 +510,9 @@ var MapManager = /** @class */ (function () { ...@@ -505,9 +510,9 @@ var MapManager = /** @class */ (function () {
obstacle = {}; obstacle = {};
Object.assign(obstacle, geo_obstacle); Object.assign(obstacle, geo_obstacle);
obstacle.position = _this.mapUtils.convertToLocalCoordinates( obstacle.position = _this.mapUtils.convertToLocalCoordinates(
geo_obstacle.position.x, geo_obstacle.position.latitude,
geo_obstacle.position.y, geo_obstacle.position.longitude,
geo_obstacle.position.z); geo_obstacle.position.altitude);
switch (obstacle.type) { switch (obstacle.type) {
case "box": case "box":
new_obstacle = BABYLON.MeshBuilder.CreateBox("obs_" + count, new_obstacle = BABYLON.MeshBuilder.CreateBox("obs_" + count,
...@@ -563,9 +568,9 @@ var MapManager = /** @class */ (function () { ...@@ -563,9 +568,9 @@ var MapManager = /** @class */ (function () {
flag_info = {}; flag_info = {};
Object.assign(flag_info, geo_flag); Object.assign(flag_info, geo_flag);
flag_info.position = _this.mapUtils.convertToLocalCoordinates( flag_info.position = _this.mapUtils.convertToLocalCoordinates(
geo_flag.position.x, geo_flag.position.latitude,
geo_flag.position.y, geo_flag.position.longitude,
geo_flag.position.z); geo_flag.position.altitude);
flag_material = new BABYLON.StandardMaterial("flag_mat_" + index, scene); flag_material = new BABYLON.StandardMaterial("flag_mat_" + index, scene);
flag_material.alpha = 1; flag_material.alpha = 1;
flag_material.diffuseColor = BABYLON.Color3.Green(); flag_material.diffuseColor = BABYLON.Color3.Green();
...@@ -641,6 +646,7 @@ var MapManager = /** @class */ (function () { ...@@ -641,6 +646,7 @@ var MapManager = /** @class */ (function () {
var GameManager = /** @class */ (function () { var GameManager = /** @class */ (function () {
"use strict"; "use strict";
var BASE_DISTANCE = 30;
// *** CONSTRUCTOR *** // *** CONSTRUCTOR ***
function GameManager(canvas, game_parameters_json) { function GameManager(canvas, game_parameters_json) {
var drone, header_list, drone_count, i; var drone, header_list, drone_count, i;
...@@ -901,7 +907,7 @@ var GameManager = /** @class */ (function () { ...@@ -901,7 +907,7 @@ var GameManager = /** @class */ (function () {
var msg = ''; var msg = '';
drone._tick += 1; drone._tick += 1;
if (drone.can_play) { if (drone.can_play) {
if (drone.getCurrentPosition().z <= 0) { if (drone.getCurrentPosition().altitude <= 0) {
drone._internal_crash(new Error('Drone ' + drone.id + drone._internal_crash(new Error('Drone ' + drone.id +
' touched the floor.')); ' touched the floor.'));
} }
...@@ -931,6 +937,9 @@ var GameManager = /** @class */ (function () { ...@@ -931,6 +937,9 @@ var GameManager = /** @class */ (function () {
.push(function () { .push(function () {
if (_this._timeOut()) { if (_this._timeOut()) {
console.log("TIMEOUT!"); console.log("TIMEOUT!");
_this._droneList.forEach(function (drone) {
if (drone.can_play) drone._internal_crash(new Error('Timeout.'));
});
_this._result_message += "TIMEOUT!"; _this._result_message += "TIMEOUT!";
return _this._finish(); return _this._finish();
} }
...@@ -971,8 +980,9 @@ var GameManager = /** @class */ (function () { ...@@ -971,8 +980,9 @@ var GameManager = /** @class */ (function () {
drone_position.z drone_position.z
); );
game_manager._flight_log[index].push([ game_manager._flight_log[index].push([
game_manager._game_duration, geo_coordinates.x, game_manager._game_duration, geo_coordinates.latitude,
geo_coordinates.y, map_info.start_AMSL + drone_position.z, geo_coordinates.longitude,
map_info.start_AMSL + drone_position.z,
drone_position.z, drone.getYaw(), drone.getGroundSpeed(), drone_position.z, drone.getYaw(), drone.getGroundSpeed(),
drone.getClimbRate() drone.getClimbRate()
]); ]);
...@@ -1033,9 +1043,14 @@ var GameManager = /** @class */ (function () { ...@@ -1033,9 +1043,14 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._calculateUserScore = function () { GameManager.prototype._calculateUserScore = function () {
var score = 0; var score = 0, base = this._mapManager.getMapInfo().initial_position, dist;
this._droneList_user.forEach(function (drone) { this._droneList_user.forEach(function (drone) {
score += drone.score; score += drone.score;
if (drone.last_position) {
dist = Math.sqrt(Math.pow((drone.last_position.x - base.x), 2)
+ Math.pow((drone.last_position.y - base.y), 2));
if (dist < BASE_DISTANCE) score += 1;
}
}); });
return score; return score;
}; };
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.18882.27011.1501</string> </value> <value> <string>1011.46053.12382.23005</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1695327797.6</float> <float>1696871380.85</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
var MapUtils = /** @class */ (function () { var MapUtils = /** @class */ (function () {
"use strict"; "use strict";
var FLAG_EPSILON = 15, R = 6371e3; var FLAG_EPSILON = 15, R = 6371e3, FLAG_WEIGHT = 5, FLAG_SCORE = 5;
//** CONSTRUCTOR //** CONSTRUCTOR
function MapUtils(map_param) { function MapUtils(map_param) {
...@@ -80,6 +80,9 @@ var MapUtils = /** @class */ (function () { ...@@ -80,6 +80,9 @@ var MapUtils = /** @class */ (function () {
this.map_info.min_y; this.map_info.min_y;
lat = 90 - lat / (this.map_info.map_size / 180.0); lat = 90 - lat / (this.map_info.map_size / 180.0);
return { return {
latitude: lat,
longitude: lon,
altitude: z,
x: lat, x: lat,
y: lon, y: lon,
z: z z: z
...@@ -99,8 +102,9 @@ var MapUtils = /** @class */ (function () { ...@@ -99,8 +102,9 @@ var MapUtils = /** @class */ (function () {
for (i = 0; i < list.length; i += 1) { for (i = 0; i < list.length; i += 1) {
el = {"position": el = {"position":
{"x": 0, "y": 0, "z": 0}, {"x": 0, "y": 0, "z": 0},
"score": list[i].score, "score": Math.floor(seed.quick() * FLAG_SCORE) + 1,
"weight": list[i].weight}; "weight": Math.floor(seed.quick() * FLAG_WEIGHT) + 1
};
el.position.x = normalize(list[i].position.x, min_x, max_x); el.position.x = normalize(list[i].position.x, min_x, max_x);
el.position.y = normalize(list[i].position.y, min_y, max_y); el.position.y = normalize(list[i].position.y, min_y, max_y);
//TODO normalize z to map height? //TODO normalize z to map height?
...@@ -332,20 +336,15 @@ var MapUtils = /** @class */ (function () { ...@@ -332,20 +336,15 @@ var MapUtils = /** @class */ (function () {
); );
Object.assign(_this.map_info, _this.map_param); Object.assign(_this.map_info, _this.map_param);
flag_list.forEach(function (flag_info, index) { flag_list.forEach(function (flag_info, index) {
coordinates = _this.convertToGeoCoordinates(
flag_info.position.x,
flag_info.position.y,
flag_info.position.z
);
geo_flag_info = { geo_flag_info = {
'id': flag_info.id, 'id': flag_info.id,
'score': flag_info.score, 'score': flag_info.score,
'weight': flag_info.weight, 'weight': flag_info.weight,
'position': { 'position': _this.convertToGeoCoordinates(
'x': coordinates.x, flag_info.position.x,
'y': coordinates.y, flag_info.position.y,
'z': coordinates.z flag_info.position.z
} )
}; };
_this.map_info.flag_list.push(geo_flag_info); _this.map_info.flag_list.push(geo_flag_info);
}); });
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.18883.7641.45704</string> </value> <value> <string>1011.50252.61779.34440</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1695327563.61</float> <float>1697123604.37</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -55,9 +55,9 @@ ...@@ -55,9 +55,9 @@
<p class="item-param-2">Drones starting point coordinates</p> <p class="item-param-2">Drones starting point coordinates</p>
<p class="item-param-2"> <p class="item-param-2">
{<br> {<br>
&nbsp;&nbsp;x: number, //latitude (in degrees)<br> &nbsp;&nbsp;latitude: number, //in degrees<br>
&nbsp;&nbsp;y: number, //longitude (in degrees)<br> &nbsp;&nbsp;longitude: number, //in degrees<br>
&nbsp;&nbsp;z: number //altitude (in meters)<br> &nbsp;&nbsp;altitude: number //in meters<br>
}<br> }<br>
</p> </p>
</div> </div>
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<p class="item-param-2">List of flags, each element:</p> <p class="item-param-2">List of flags, each element:</p>
<p class="item-param-2"> <p class="item-param-2">
{<br> {<br>
&nbsp;&nbsp;position {x,y,z}:<br>&nbsp;&nbsp;latitude, longitude and altitude<br> &nbsp;&nbsp;position {latitude, longitude, altitude}: dict of floats<br>
&nbsp;&nbsp;score: number<br> &nbsp;&nbsp;score: number<br>
&nbsp;&nbsp;weight: number<br> &nbsp;&nbsp;weight: number<br>
}<br> }<br>
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
<p class="item-param-2">List of obstacles, each element:</p> <p class="item-param-2">List of obstacles, each element:</p>
<p class="item-param-2"> <p class="item-param-2">
{<br> {<br>
&nbsp;&nbsp;position {x,y,z}:<br>&nbsp;&nbsp;latitude, longitude and altitude<br> &nbsp;&nbsp;position {latitude, longitude, altitude}: dict of floats<br>
&nbsp;&nbsp;type: [box, cilinder, sphere]<br> &nbsp;&nbsp;type: [box, cilinder, sphere]<br>
&nbsp;&nbsp;scale: {x,y,z}<br> &nbsp;&nbsp;scale: {x,y,z}<br>
&nbsp;&nbsp;rotation: {x,y,z}<br> &nbsp;&nbsp;rotation: {x,y,z}<br>
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
<p class="item-param-2">List of enemies, each element:</p> <p class="item-param-2">List of enemies, each element:</p>
<p class="item-param-2"> <p class="item-param-2">
{<br> {<br>
&nbsp;&nbsp;position {x,y,z}:<br>&nbsp;&nbsp;latitude, longitude and altitude<br> &nbsp;&nbsp;position {latitude, longitude, altitude}: dict of floats<br>
&nbsp;&nbsp;type: drone-type<br> &nbsp;&nbsp;type: drone-type<br>
&nbsp;&nbsp;id: number<br> &nbsp;&nbsp;id: number<br>
}<br> }<br>
...@@ -136,7 +136,8 @@ ...@@ -136,7 +136,8 @@
<h4 class="item-name" id="scoring"><span>Score</span></h4> <h4 class="item-name" id="scoring"><span>Score</span></h4>
<p class="item-descr">Every flag has a score, every drone hit on the flag will give it that score value.</p> <p class="item-descr">Every flag has a score, every drone hit on the flag will give it that score value.</p>
<p class="item-descr">The number of hits on a flag is determined by its weight.</p> <p class="item-descr">The number of hits on a flag is determined by its weight.</p>
<p class="item-descr">Once the number of hits is equal to the flag weight, no more score will be given on following hits.</p> <p class="item-descr">Once the number of hits is equal to the flag weight, no more score will be given on following hits (the flag is consider captured).</p>
<p class="item-descr">When the game ends (whatever the reason), if a drone has returned to its initial position, it gets an extra point.</p>
<p class="item-descr">Total score is the sum of all drones score when the game finishes.</p> <p class="item-descr">Total score is the sum of all drones score when the game finishes.</p>
<h5 class="item-param-1">Example</h5> <h5 class="item-param-1">Example</h5>
...@@ -305,9 +306,9 @@ ...@@ -305,9 +306,9 @@
<p class="item-descr"> <p class="item-descr">
Get drone current position geo-coordinates.<br> Get drone current position geo-coordinates.<br>
{<br> {<br>
&nbsp;&nbsp;x: number, //latitude (in degrees)<br> &nbsp;&nbsp;latitude: number, //in degrees<br>
&nbsp;&nbsp;y: number, //longitude (in degrees)<br> &nbsp;&nbsp;longitude: number, //in degrees<br>
&nbsp;&nbsp;z: number //altitude (in meters)<br> &nbsp;&nbsp;altitude: number //in meters<br>
}<br> }<br>
</p> </p>
...@@ -351,16 +352,16 @@ ...@@ -351,16 +352,16 @@
</div> </div>
<div> <div>
<p class="item-param-1">X: Float</p> <p class="item-param-1">latitude: Float</p>
<p class="item-param-2">X value - latitude (in degrees).</p> <p class="item-param-2">latitude value (in degrees).</p>
</div> </div>
<div> <div>
<p class="item-param-1">Y: Float</p> <p class="item-param-1">longitude: Float</p>
<p class="item-param-2">Y value - longitude (in degrees).</p> <p class="item-param-2">longitude value (in degrees).</p>
</div> </div>
<div> <div>
<p class="item-param-1">Z: Float</p> <p class="item-param-1">altitude: Float</p>
<p class="item-param-2">Z value - altitude (in meters).</p> <p class="item-param-2">altitude value (in meters).</p>
</div> </div>
<div> <div>
...@@ -408,16 +409,16 @@ ...@@ -408,16 +409,16 @@
</div> </div>
<div> <div>
<p class="item-param-1">X: Float</p> <p class="item-param-1">latitude: Float</p>
<p class="item-param-2">X value - latitude (in degrees).</p> <p class="item-param-2">latitude value (in degrees).</p>
</div> </div>
<div> <div>
<p class="item-param-1">Y: Float</p> <p class="item-param-1">longitude: Float</p>
<p class="item-param-2">Y value - longitude (in degrees).</p> <p class="item-param-2">longitude value (in degrees).</p>
</div> </div>
<div> <div>
<p class="item-param-1">Z: Float</p> <p class="item-param-1">altitude: Float</p>
<p class="item-param-2">Z value - altitude (in meters).</p> <p class="item-param-2">altitude value (in meters).</p>
</div> </div>
<div> <div>
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.7129.2983.29201</string> </value> <value> <string>1011.46157.31778.16247</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -264,7 +264,7 @@ ...@@ -264,7 +264,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1694622336.88</float> <float>1696877684.5</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -48,22 +48,36 @@ var OperatorAPI = /** @class */ (function () { ...@@ -48,22 +48,36 @@ var OperatorAPI = /** @class */ (function () {
"min_lon": MIN_LON, "min_lon": MIN_LON,
"max_lon": MAX_LON, "max_lon": MAX_LON,
"flag_list": [{"position": "flag_list": [{"position":
{"x": 45.6464947316632, {"latitude": 45.6464947316632,
"longitude": 14.270747186236491,
"altitude": 10,
"x": 45.6464947316632,
"y": 14.270747186236491, "y": 14.270747186236491,
"z": 10}, "z": 10},
"score": 1, "score": 1,
"weight": 1}], "weight": 1}],
"obstacle_list": [{"type": "box", "obstacle_list": [{"type": "box",
"position": {"x": 45.6456815316444, "position": {"latitude": 45.6456815316444,
"longitude": 14.274667031215898,
"altitude": 15,
"x": 45.6456815316444,
"y": 14.274667031215898, "y": 14.274667031215898,
"z": 15}, "z": 15},
"scale": {"x": 132, "y": 56, "z": 10}, "scale": {"x": 132, "y": 56, "z": 10},
"rotation": {"x": 0, "y": 0, "z": 0}}], "rotation": {"x": 0, "y": 0, "z": 0}}],
"enemy_list": [{"type": "EnemyDroneAPI", "enemy_list": [{"type": "EnemyDroneAPI",
"position": {"x": 45.6455531, "position": {"latitude": 45.6455531,
"longitude": 14.270747186236491,
"altitude": 15,
"x": 45.6455531,
"y": 14.270747186236491, "y": 14.270747186236491,
"z": 15}}], "z": 15}}],
"initial_position": {"x": 45.642813275, "y": 14.270231599999988, "z": 15} "initial_position": {"latitude": 45.642813275,
"longitude": 14.270231599999988,
"altitude": 15,
"x": 45.642813275,
"y": 14.270231599999988,
"z": 15}
}, },
DEFAULT_SPEED = 16, DEFAULT_SPEED = 16,
MAX_ACCELERATION = 6, MAX_ACCELERATION = 6,
...@@ -86,10 +100,10 @@ var OperatorAPI = /** @class */ (function () { ...@@ -86,10 +100,10 @@ var OperatorAPI = /** @class */ (function () {
'\n' + '\n' +
'function distance2D(a, b) {\n' + 'function distance2D(a, b) {\n' +
' var R = 6371e3, // meters\n' + ' var R = 6371e3, // meters\n' +
' la1 = a.x * Math.PI / 180, // lat, lon in radians\n' + ' la1 = a.latitude * Math.PI / 180, // lat, lon in radians\n' +
' la2 = b.x * Math.PI / 180,\n' + ' la2 = b.latitude * Math.PI / 180,\n' +
' lo1 = a.y * Math.PI / 180,\n' + ' lo1 = a.longitude * Math.PI / 180,\n' +
' lo2 = b.y * Math.PI / 180,\n' + ' lo2 = b.longitude * Math.PI / 180,\n' +
' haversine_phi = Math.pow(Math.sin((la2 - la1) / 2), 2),\n' + ' haversine_phi = Math.pow(Math.sin((la2 - la1) / 2), 2),\n' +
' sin_lon = Math.sin((lo2 - lo1) / 2),\n' + ' sin_lon = Math.sin((lo2 - lo1) / 2),\n' +
' h = haversine_phi + Math.cos(la1) * Math.cos(la2) * sin_lon * sin_lon;\n' + ' h = haversine_phi + Math.cos(la1) * Math.cos(la2) * sin_lon * sin_lon;\n' +
...@@ -98,7 +112,7 @@ var OperatorAPI = /** @class */ (function () { ...@@ -98,7 +112,7 @@ var OperatorAPI = /** @class */ (function () {
'\n' + '\n' +
'function distance(a, b) {\n' + 'function distance(a, b) {\n' +
' return Math.sqrt(\n' + ' return Math.sqrt(\n' +
' Math.pow(a.z - b.z, 2) + Math.pow(distance2D(a, b), 2)\n' + ' Math.pow(a.altitude - b.altitude, 2) + Math.pow(distance2D(a, b), 2)\n' +
' );\n' + ' );\n' +
'}\n' + '}\n' +
'\n' + '\n' +
...@@ -132,9 +146,9 @@ var OperatorAPI = /** @class */ (function () { ...@@ -132,9 +146,9 @@ var OperatorAPI = /** @class */ (function () {
' if (!me.direction_set) {\n' + ' if (!me.direction_set) {\n' +
' if (me.next_checkpoint < me.flag_positions.length) {\n' + ' if (me.next_checkpoint < me.flag_positions.length) {\n' +
' me.setTargetCoordinates(\n' + ' me.setTargetCoordinates(\n' +
' me.flag_positions[me.next_checkpoint].position.x,\n' + ' me.flag_positions[me.next_checkpoint].position.latitude,\n' +
' me.flag_positions[me.next_checkpoint].position.y,\n' + ' me.flag_positions[me.next_checkpoint].position.longitude,\n' +
' me.flag_positions[me.next_checkpoint].position.z + me.id\n' + ' me.flag_positions[me.next_checkpoint].position.altitude + me.id\n' +
' );\n' + ' );\n' +
//' console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);\n' + //' console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);\n' +
' }\n' + ' }\n' +
...@@ -180,7 +194,7 @@ var OperatorAPI = /** @class */ (function () { ...@@ -180,7 +194,7 @@ var OperatorAPI = /** @class */ (function () {
' } else {\n' + ' } else {\n' +
' dodge_point.y = dodge_point.y * -1;\n' + ' dodge_point.y = dodge_point.y * -1;\n' +
' }\n' + ' }\n' +
' me.setTargetCoordinates(dodge_point.x, dodge_point.y, me.getCurrentPosition().z);\n' + ' me.setTargetCoordinates(dodge_point.latitude, dodge_point.longitude, me.getCurrentPosition().altitude);\n' +
' return;\n' + ' return;\n' +
' }\n' + ' }\n' +
'};', '};',
...@@ -719,6 +733,28 @@ var OperatorAPI = /** @class */ (function () { ...@@ -719,6 +733,28 @@ var OperatorAPI = /** @class */ (function () {
sub_gadget.element sub_gadget.element
]); ]);
//Backward compatibility sanitation
function sanitize(position) {
if (!position.latitude) {
position.latitude = position.x;
position.longitude = position.y;
position.altitude = position.z;
}
return position;
}
var map_json = JSON.parse(gadget.state.map_json);
map_json.initial_position = sanitize(map_json.initial_position);
map_json.flag_list.forEach(function (flag, index) {
flag.position = sanitize(flag.position);
});
map_json.obstacle_list.forEach(function (obstacle, index) {
obstacle.position = sanitize(obstacle.position);
});
map_json.enemy_list.forEach(function (enemy, index) {
enemy.position = sanitize(enemy.position);
});
gadget.state.map_json = JSON.stringify(map_json, undefined, 4);
var operator_code = "let operator = function(operator){" + var operator_code = "let operator = function(operator){" +
gadget.state.operator_script + gadget.state.operator_script +
"return operator.getDroneStartMessage();" + "return operator.getDroneStartMessage();" +
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.18818.32686.32580</string> </value> <value> <string>1011.50269.22753.36317</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1695397751.99</float> <float>1697124355.48</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment