Skip to content

Commit

Permalink
Merge pull request freeciv#409 from kvilhaugsvik/bugfix
Browse files Browse the repository at this point in the history
Be more careful about interpreting arrow keys while transported as disembark.
  • Loading branch information
kvilhaugsvik authored Jul 8, 2021
2 parents 74d9a1b + 53749ad commit ff71233
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 17 deletions.
29 changes: 14 additions & 15 deletions freeciv-web/src/main/webapp/javascript/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -3154,21 +3154,6 @@ function key_unit_move(dir)
return;
}

if (punit['transported']) {
if (unit_can_do_action(punit, ACTION_TRANSPORT_DISEMBARK1)) {
request_new_unit_activity(punit, ACTIVITY_IDLE, EXTRA_NONE);
request_unit_do_action(ACTION_TRANSPORT_DISEMBARK1, punit['id'],
newtile['index']);
unit_move_sound_play(punit);
} else if (unit_can_do_action(punit, ACTION_TRANSPORT_DISEMBARK2)) {
request_new_unit_activity(punit, ACTIVITY_IDLE, EXTRA_NONE);
request_unit_do_action(ACTION_TRANSPORT_DISEMBARK2, punit['id'],
newtile['index']);
unit_move_sound_play(punit);
}
return;
}

/* Send the order to move using the orders system. */
var order = {
"order" : ORDER_ACTION_MOVE,
Expand All @@ -3179,6 +3164,20 @@ function key_unit_move(dir)
"action" : ACTION_COUNT
};

if (punit['transported']
/* No non domestic units */
&& newtile['units'].every(function(ounit) {
return ounit['owner'] == client.conn.playing.playerno;
})
/* No non domestic cities */
&& (tile_city(newtile) == null
|| tile_city(newtile)['owner'] == client.conn.playing.playerno)
&& !tile_has_extra(newtile, EXTRA_HUT)
&& (newtile['extras_owner'] == client.conn.playing.playerno
|| !tile_has_territory_claiming_extra(newtile))) {
order["order"] = ORDER_MOVE;
}

var packet = {
"pid" : packet_unit_orders,
"unit_id" : punit['id'],
Expand Down
8 changes: 8 additions & 0 deletions freeciv-web/src/main/webapp/javascript/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ function is_extra_removed_by(pextra, rmcause)
{
return pextra.rmcauses.isSet(rmcause);
}

/************************************************************************//**
Does this extra type claim territory?
****************************************************************************/
function territory_claiming_extra(pextra)
{
return pextra['base'] && pextra['base']['border_sq'] > -1;
}
36 changes: 34 additions & 2 deletions freeciv-web/src/main/webapp/javascript/packhand.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,14 +1507,46 @@ function handle_ruleset_extra_flag(packet)
/* TODO: implement */
}

/************************************************************************//**
Handle a packet about a particular base type.
****************************************************************************/
function handle_ruleset_base(packet)
{
/* TODO: Implement */
var i;

for (i = 0; i < MAX_EXTRA_TYPES; i++) {
if (is_extra_caused_by(extras[i], EC_BASE)
&& extras[i]['base'] == null) {
/* This is the first base without base data */
extras[i]['base'] = packet;
extras[extras[i]['name']]['base'] = packet;
return;
}
}

console.log("Didn't find Extra to put Base on");
console.log(packet);
}

/************************************************************************//**
Handle a packet about a particular road type.
****************************************************************************/
function handle_ruleset_road(packet)
{
/* TODO: Implement */
var i;

for (i = 0; i < MAX_EXTRA_TYPES; i++) {
if (is_extra_caused_by(extras[i], EC_ROAD)
&& extras[i]['road'] == null) {
/* This is the first road without road data */
extras[i]['road'] = packet;
extras[extras[i]['name']]['road'] = packet;
return;
}
}

console.log("Didn't find Extra to put Road on");
console.log(packet);
}

/************************************************************************//**
Expand Down
17 changes: 17 additions & 0 deletions freeciv-web/src/main/webapp/javascript/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ function tile_resource(tile)
return null;
}

/************************************************************************//**
Check if tile contains an extra type that claim territory
****************************************************************************/
function tile_has_territory_claiming_extra(ptile)
{
var extra;

for (extra = 0; extra < MAX_EXTRA_TYPES; extra++) {
if (tile_has_extra(ptile, extra)
&& territory_claiming_extra(extra_by_number(extra))) {
return true;
}
}

return false;
}

function tile_owner(tile)
{
return tile['owner'];
Expand Down

0 comments on commit ff71233

Please sign in to comment.