Commit 3a9d947c authored by Roque's avatar Roque

Capture the flag game new features

See merge request nexedi/erp5!1824
parents 41270486 36b5ce60
Pipeline #30188 failed with stage
in 0 seconds
......@@ -6,10 +6,11 @@ var EnemyDroneAPI = /** @class */ (function () {
"use strict";
var DEFAULT_ACCELERATION = 1,
VIEW_SCOPE = 50,
VIEW_SCOPE = 25,
DEFAULT_SPEED = 16.5,
MIN_SPEED = 12,
MAX_SPEED = 26;
MAX_SPEED = 26,
COLLISION_SECTOR = 10;
//** CONSTRUCTOR
function EnemyDroneAPI(gameManager, drone_info, flight_parameters, id) {
......@@ -21,6 +22,7 @@ var EnemyDroneAPI = /** @class */ (function () {
this._drone_info = drone_info;
this._drone_dict_list = [];
this._acceleration = DEFAULT_ACCELERATION;
this._collision_sector = COLLISION_SECTOR;
}
/*
** Function called on start phase of the drone, just before onStart AI script
......@@ -189,15 +191,16 @@ var EnemyDroneAPI = /** @class */ (function () {
EnemyDroneAPI.prototype.getDroneViewInfo = function (drone) {
var context = this, result = [], distance,
drone_position = drone.position, other_position;
function calculateDistance(a, b) {
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) +
Math.pow((a.z - b.z), 2));
function calculateDistance(a, b, _3D) {
var z = (_3D ? Math.pow((a.z - b.z), 2) : 0);
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) + z);
}
context._gameManager._droneList_user.forEach(function (other) {
if (other.can_play) {
other_position = other.position;
distance = calculateDistance(drone_position, other_position);
if (distance <= VIEW_SCOPE) {
//the higher the drone, the easier to detect
if (distance / (other_position.z * 0.05) <= VIEW_SCOPE) {
result.push({
position: other_position,
direction: other.direction,
......@@ -213,8 +216,7 @@ var EnemyDroneAPI = /** @class */ (function () {
};
EnemyDroneAPI.prototype.getDroneAI = function () {
//interception math based on https://www.codeproject.com/Articles/990452/Interception-of-Two-Moving-Objects-in-D-Space
return 'var BASE_DISTANCE = 300;\n' +
'function calculateInterception(hunter_position, prey_position, hunter_speed, prey_speed, prey_velocity_vector) {\n' +
return 'function calculateInterception(hunter_position, prey_position, hunter_speed, prey_speed, prey_velocity_vector) {\n' +
' var vector_from_drone, distance_to_prey, distance_to_prey_vector, a, b, c, t1, t2, interception_time, interception_point;\n' +
' function dot(a, b) {\n' +
' return a.map((x, i) => a[i] * b[i]).reduce((m, n) => m + n);\n' +
......@@ -242,7 +244,6 @@ var EnemyDroneAPI = /** @class */ (function () {
'}\n' +
'\n' +
'me.onStart = function () {\n' +
' me.base = me.position;\n' +
' me.setDirection(0,0,0);\n' +
' return;\n' +
'\n' +
......@@ -251,20 +252,6 @@ var EnemyDroneAPI = /** @class */ (function () {
'me.onUpdate = function (timestamp) {\n' +
' me.current_position = me.position;\n' +
' var drone_position, drone_velocity_vector, interception_point, drone_view,\n' +
' dist = distance(\n' +
' me.current_position,\n' +
' me.base\n' +
' );\n' +
// return to base point if drone is too far
' if (dist >= BASE_DISTANCE) {\n' +
' me.chasing = false;\n' +
' me.setTargetCoordinates(\n' +
' me.base.x,\n' +
' me.base.y,\n' +
' me.base.z\n' +
' );\n' +
' return;\n' +
' }\n' +
' drone_view = me.getDroneViewInfo();\n' +
' if (drone_view.length) {\n' +
' drone_position = drone_view[0].position;\n' +
......@@ -273,13 +260,8 @@ var EnemyDroneAPI = /** @class */ (function () {
' if (!interception_point) {\n' +
' return;\n' +
' }\n' +
' me.chasing = true;\n' +
' me.setTargetCoordinates(interception_point[0], interception_point[1], interception_point[2]);\n' +
' }\n' +
// return to base point if drone is too far
' if (!me.chasing && dist <= 10) {\n' +
' me.setDirection(0,0,0);\n' +
' }\n' +
'};';
};
EnemyDroneAPI.prototype.getMinSpeed = function () {
......@@ -330,5 +312,8 @@ var EnemyDroneAPI = /** @class */ (function () {
EnemyDroneAPI.prototype.getFlightParameters = function () {
return this._flight_parameters;
};
EnemyDroneAPI.prototype.getCollisionSector = function () {
return this._collision_sector;
};
return EnemyDroneAPI;
}());
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1009.37360.49772.3874</string> </value>
<value> <string>1011.20054.25134.60962</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1688571911.82</float>
<float>1695397984.38</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -36,7 +36,6 @@ var FixedWingDroneAPI = /** @class */ (function () {
** Function called on start phase of the drone, just before onStart AI script
*/
FixedWingDroneAPI.prototype.internal_start = function (drone) {
drone._targetCoordinates = drone.getCurrentPosition();
drone._maxDeceleration = this.getMaxDeceleration();
if (drone._maxDeceleration <= 0) {
throw new Error('max deceleration must be superior to 0');
......@@ -194,6 +193,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
distance,
distanceCos,
distanceSin,
distanceToTarget,
currentSinLat,
currentLonRad,
groundSpeed,
......@@ -205,11 +205,19 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed,
yawToDirection;
if (this._loiter_mode && Math.sqrt(
Math.pow(drone._targetCoordinates.x - drone.position.x, 2) +
Math.pow(drone._targetCoordinates.y - drone.position.y, 2)
) <= this._loiter_radius) {
if (this._loiter_mode) {
distanceToTarget = Math.sqrt(
Math.pow(drone._targetCoordinates.x - drone.position.x, 2)
+ Math.pow(drone._targetCoordinates.y - drone.position.y, 2)
);
if (Math.abs(distanceToTarget - this._loiter_radius) <= 1) {
newYaw = bearing - 90;
} else if (distanceToTarget < this._loiter_radius) {
newYaw = bearing - 135;
} else {
newYaw = this._getNewYaw(drone, bearing, delta_time);
}
} else {
newYaw = this._getNewYaw(drone, bearing, delta_time);
}
......@@ -414,16 +422,16 @@ var FixedWingDroneAPI = /** @class */ (function () {
distance = calculateDistance(drone_position, other_position, context);
if (distance <= VIEW_SCOPE) {
result.drones.push({
position: drone.getCurrentPosition(),
direction: drone.direction,
rotation: drone.rotation,
speed: drone.speed,
team: drone.team
position: other.getCurrentPosition(),
direction: other.direction,
rotation: other.rotation,
speed: other.speed,
team: other.team
});
}
}
});
context._map_dict.geo_obstacle_list.forEach(function (obstacle) {
context._map_dict.obstacle_list.forEach(function (obstacle) {
distance = calculateDistance(drone_position, obstacle.position, context);
if (distance <= VIEW_SCOPE) {
result.obstacles.push(obstacle);
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.35063.25322.10700</string> </value>
<value> <string>1011.5610.25987.56473</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1692366624.83</float>
<float>1695395371.67</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.23697.26501.43008</string> </value>
<value> <string>1011.18882.27011.1501</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1691684378.73</float>
<float>1695327797.6</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -29,6 +29,10 @@
margin: 0;
}
.documentation div {
vertical-align: middle !important;
}
.documentation .line {
width: 100%;
height: 1px;
......@@ -54,7 +58,6 @@
.item-name span:last-of-type {
font-style: italic; }
.line {
width: 100%;
height: 1px;
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.15231.63877.58538</string> </value>
<value> <string>1011.7107.64372.12151</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1691176394.73</float>
<float>1694621148.77</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -10,6 +10,141 @@
<div class="documentation">
<h1>Game specifications</h1>
<!-- Map JSON -->
<h3>Map parameter dictionary (JSON)</h3>
<div>
<h5 class="item-param-1">Map dictionary entries</h5>
<p class="item-descr"></p>
</div>
<div>
<h5 class="item-param-1">Key</h5>
<h5 class="item-param-2">Description</h5>
</div>
<div>
<p class="item-param-1">min_lat, max_lat, min_lon, max_lon: Float</p>
<p class="item-param-2">Min and max latitude and longitude coordinates of the map</p>
</div>
<div>
<p class="item-param-1">map_size: Integer</p>
<p class="item-param-2">Map size in meters (calculated from coordinates)</p>
</div>
<div>
<p class="item-param-1">width, depth: Integer</p>
<p class="item-param-2">Map width and depth in meters (calculated from coordinates)</p>
</div>
<div>
<p class="item-param-1">height: Integer</p>
<p class="item-param-2">Map height in meters</p>
</div>
<div>
<p class="item-param-1">start_AMSL: Integer</p>
<p class="item-param-2">Map height above mean sea level in meters</p>
</div>
<div>
<p class="item-param-1">initial_position: dictionary</p>
<p class="item-param-2">Drones starting point coordinates</p>
<p class="item-param-2">
{<br>
&nbsp;&nbsp;x: number, //latitude (in degrees)<br>
&nbsp;&nbsp;y: number, //longitude (in degrees)<br>
&nbsp;&nbsp;z: number //altitude (in meters)<br>
}<br>
</p>
</div>
<div>
<p class="item-param-1">flag_list: list</p>
<p class="item-param-2">List of flags, each element:</p>
<p class="item-param-2">
{<br>
&nbsp;&nbsp;position {x,y,z}:<br>&nbsp;&nbsp;latitude, longitude and altitude<br>
&nbsp;&nbsp;score: number<br>
&nbsp;&nbsp;weight: number<br>
}<br>
</p>
</div>
<div>
<p class="item-param-1">obstacle_list: list</p>
<p class="item-param-2">List of obstacles, each element:</p>
<p class="item-param-2">
{<br>
&nbsp;&nbsp;position {x,y,z}:<br>&nbsp;&nbsp;latitude, longitude and altitude<br>
&nbsp;&nbsp;type: [box, cilinder, sphere]<br>
&nbsp;&nbsp;scale: {x,y,z}<br>
&nbsp;&nbsp;rotation: {x,y,z}<br>
}<br>
</p>
</div>
<div>
<p class="item-param-1">enemy_list: list</p>
<p class="item-param-2">List of enemies, each element:</p>
<p class="item-param-2">
{<br>
&nbsp;&nbsp;position {x,y,z}:<br>&nbsp;&nbsp;latitude, longitude and altitude<br>
&nbsp;&nbsp;type: drone-type<br>
&nbsp;&nbsp;id: number<br>
}<br>
</p>
</div>
<div class="line"></div>
<h3>Operator script</h3>
<!-- Operator script -->
<h4 class="item-name" id="scoring"><span>Operator</span></h4>
<p class="item-descr">The purpose of this script is to set the initial message that all the drones will get at the beginning of the game.</p>
<p class="item-descr">The map parameter dictionary can be accessed to get any relevant info.</p>
<p class="item-descr">An API is provided through the object <em>operator</em> that allows to get the map json and set the intial message.</p>
<h4 class="item-name" id="scoring"><span>API</span></h4>
<div>
<p class="item-param-1">getMapJSON(): dictionary</p>
<p class="item-param-2">Get the map JSON dictionary</p>
</div>
<div>
<p class="item-param-1">sendMsg(msg): void</p>
<p class="item-param-2">Set the initial msg all the drones will get at the start.</p>
<p class="item-param-2">Message parameter msg must be a dictionary</p>
</div>
<h5 class="item-param-1">Example</h5>
<p class="item-example">var map = operator.getMapJSON();<br>
operator.sendMsg({flag_positions: map.flag_list});
</p>
<div class="line"></div>
<h3>Game scoring</h3>
<!-- Scoring -->
<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">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">Total score is the sum of all drones score when the game finishes.</p>
<h5 class="item-param-1">Example</h5>
<p class="item-example">A flag with score=3 and weight=2 will grant 3 score points on every drone hit, up to 2 hits.</p>
<div class="line"></div>
<h1>Fixed Wings Drone API</h1>
<h3>API functions</h3>
......@@ -442,7 +577,7 @@
<!-- id -->
<h4 class="item-name" id="id"><span>id</span><span>: number</span></h4>
<p class="item-descr">Drone unique numeric identifier: from 0 to 9.</p>
<p class="item-descr">Drone unique numeric identifier.</p>
<h5 class="item-param-1">Example</h5>
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.23624.18144.48810</string> </value>
<value> <string>1011.7129.2983.29201</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1691679891.23</float>
<float>1694622336.88</float>
<string>UTC</string>
</tuple>
</state>
......
div[data-gadget-url$="gadget_erp5_page_drone_capture_flag_script_page.html"] .item-label {
background-color: #F8F8F8;
padding: 8px;
margin: 8px 0;
font-size: 1.2em;
font-weight: bold;
}
div[data-gadget-url$="gadget_erp5_page_drone_capture_flag_script_page.html"] button {
color: #212529;
padding: 3pt;
border: 1px solid rgba(0, 0, 0, 0.14);
border-radius: 0.325em;
display: inline-block;
margin-right: 6pt;
}
div[data-gadget-url$="gadget_erp5_page_drone_capture_flag_script_page.html"] button:disabled,
div[data-gadget-url$="gadget_erp5_page_drone_capture_flag_script_page.html"] button[disabled] {
color: #999999;
}
div[data-gadget-url$="gadget_erp5_page_drone_capture_flag_script_page.html"] button:before {
padding-right: 0.2em;
}
<!DOCTYPE html>
<html>
<!--
data-i18n=Others
data-i18n=Tools
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Drone Capture Flag Script Page</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html">
<link rel="stylesheet" type="text/css" href="gadget_erp5_page_drone_capture_flag_script_page.css">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
......@@ -18,24 +15,16 @@
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<script type="text/javascript" src="./libraries/seedrandom.min.js"></script>
<script src="gadget_erp5_page_drone_capture_map_utils.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_capture_flag_script_page.js" type="text/javascript"></script>
</head>
<body>
<form>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
<input name="action_run" class="dialogconfirm" type="submit" value="Run" style="margin-bottom: 20pt;margin-top: 20pt;">
<a data-i18n="Storages"></a> <!-- for zelenium test common macro -->
<div class="simulator_div"></div>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view_babylonjs"
data-gadget-sandbox="public">
</div>
</form>
<div class="captureflagpageheader"></div>
<div class="captureflagpagebody"></div>
</body>
</html>
\ No newline at end of file
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1008.22253.2281.60074</string> </value>
<value> <string>1010.65526.46361.27613</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1683820259.6</float>
<float>1694194019.23</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.23654.50890.20360</string> </value>
<value> <string>1011.18818.32686.32580</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1691681704.91</float>
<float>1695397751.99</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -277,7 +277,7 @@
</item>
<item>
<key> <string>configuration_content_security_policy</string> </key>
<value> <string>default-src \'self\'; img-src \'self\' data:; media-src \'self\' blob:; connect-src \'self\' https://content.dropboxapi.com https://api.dropboxapi.com mail.tiolive.com data: *.host.vifib.net *.node.vifib.com *.erp5.net *.nexedi.net https://netdna.bootstrapcdn.com; script-src \'self\' \'unsafe-eval\' \'unsafe-inline\'; font-src \'self\' netdna.bootstrapcdn.com; style-src \'self\' netdna.bootstrapcdn.com \'unsafe-inline\' data:; frame-src \'self\' data:</string> </value>
<value> <string>default-src \'self\'; img-src \'self\' data:; media-src \'self\' blob:; script-src \'self\' \'unsafe-eval\';</string> </value>
</item>
<item>
<key> <string>configuration_latest_document_version</string> </key>
......@@ -538,7 +538,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1007.63243.40091.31010</string> </value>
<value> <string>1010.35278.59853.35635</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -558,7 +558,7 @@
</tuple>
<state>
<tuple>
<float>1682433351.46</float>
<float>1692976685.9</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>configuration_content_security_policy</string> </key>
<value> <string>default-src \'self\'; img-src \'self\' data:; media-src \'self\' blob:; connect-src \'self\' https://content.dropboxapi.com https://api.dropboxapi.com mail.tiolive.com data: *.host.vifib.net *.node.vifib.com *.erp5.net *.nexedi.net https://netdna.bootstrapcdn.com; script-src \'self\' \'unsafe-eval\' \'unsafe-inline\'; font-src \'self\' netdna.bootstrapcdn.com; style-src \'self\' netdna.bootstrapcdn.com \'unsafe-inline\' data:; frame-src \'self\' data:</string> </value>
<value> <string>default-src \'self\'; img-src \'self\' data:; media-src \'self\' blob:; script-src \'self\' \'unsafe-eval\';</string> </value>
</item>
<item>
<key> <string>configuration_default_view_action_reference</string> </key>
......@@ -502,7 +502,7 @@ WebSection_getDroneCaptureFlagPrecacheManifestList</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1007.63247.30934.52258</string> </value>
<value> <string>1010.35278.59853.35635</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -522,7 +522,7 @@ WebSection_getDroneCaptureFlagPrecacheManifestList</string> </value>
</tuple>
<state>
<tuple>
<float>1682433685.5</float>
<float>1692976699.18</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,8 +4,10 @@ url_list = [
"gadget_erp5_page_drone_capture_flag_logic.js",
"gadget_erp5_page_drone_capture_flag_script_page.html",
"gadget_erp5_page_drone_capture_flag_script_page.js",
"gadget_erp5_page_drone_capture_flag_script_page.css",
"gadget_erp5_panel_drone_capture_flag.html",
"gadget_erp5_panel_drone_capture_flag.js",
"gadget_erp5_page_drone_capture_map_utils.js",
"gadget_erp5_page_drone_capture_flag_fixedwingdrone.js",
"gadget_erp5_page_drone_capture_flag_enemydrone.js",
"gadget_erp5_page_drone_capture_flag_api_page.html",
......
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