Skip to content

Commit

Permalink
Define action enablers in the rule sets.
Browse files Browse the repository at this point in the history
See patch #4078

[[originally from svn r23247]]
  • Loading branch information
kvilhaugsvik committed Aug 31, 2013
1 parent 6965aea commit 8de924f
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 23 deletions.
27 changes: 27 additions & 0 deletions client/packhand.c
Expand Up @@ -28,6 +28,7 @@

/* common */
#include "achievements.h"
#include "actions.h"
#include "capstr.h"
#include "citizens.h"
#include "events.h"
Expand Down Expand Up @@ -3314,6 +3315,32 @@ void handle_ruleset_road(const struct packet_ruleset_road *p)
tileset_setup_road(tileset, proad);
}

/****************************************************************************
Handle a packet about a particular action enabler.
****************************************************************************/
void
handle_ruleset_action_enabler(const struct packet_ruleset_action_enabler *p)
{
struct action_enabler *enabler;
int i;

enabler = action_enabler_new();

enabler->action = p->enabled_action;

for (i = 0; i < p->actor_reqs_count; i++) {
requirement_vector_append(&enabler->actor_reqs, p->actor_reqs[i]);
}
fc_assert(enabler->actor_reqs.size == p->actor_reqs_count);

for (i = 0; i < p->target_reqs_count; i++) {
requirement_vector_append(&enabler->target_reqs, p->target_reqs[i]);
}
fc_assert(enabler->target_reqs.size == p->target_reqs_count);

action_enabler_add(enabler);
}

/****************************************************************************
Handle a packet about a particular disaster type.
****************************************************************************/
Expand Down
16 changes: 0 additions & 16 deletions common/actions.c
Expand Up @@ -27,25 +27,9 @@ static struct action_enabler_list *action_enablers_by_action[ACTION_COUNT];
**************************************************************************/
void actions_init(void)
{
struct action_enabler *hardCoded;

action_iterate(act) {
action_enablers_by_action[act] = action_enabler_list_new();
} action_iterate_end;

hardCoded = action_enabler_new();
hardCoded->action = ACTION_SPY_POISON;
requirement_vector_append(
&hardCoded->actor_reqs,
req_from_str("UnitFlag", "Local", FALSE, TRUE, "Spy"));
action_enabler_add(hardCoded);

hardCoded = action_enabler_new();
hardCoded->action = ACTION_SPY_SABOTAGE_UNIT;
requirement_vector_append(
&hardCoded->actor_reqs,
req_from_str("UnitFlag", "Local", FALSE, TRUE, "Spy"));
action_enabler_add(hardCoded);
}

/**************************************************************************
Expand Down
1 change: 1 addition & 0 deletions common/actions.h
Expand Up @@ -22,6 +22,7 @@
extern "C" {
#endif /* __cplusplus */

/* Used in the network protocol. */
#define SPECENUM_NAME gen_action
#define SPECENUM_VALUE0 ACTION_SPY_POISON
#define SPECENUM_VALUE0NAME "Poison City"
Expand Down
1 change: 1 addition & 0 deletions common/generate_packets.py
Expand Up @@ -1585,6 +1585,7 @@ def main():
#endif /* __cplusplus */
/* common */
#include "actions.h"
#include "disaster.h"
''')
Expand Down
11 changes: 10 additions & 1 deletion common/packets.def
Expand Up @@ -3,7 +3,7 @@
Max used id:
============

Max id: 234
Max id: 235

Packets are not ordered by their id, but by their category. New packet
with higher id may get added to existing category, and not to the end of file.
Expand Down Expand Up @@ -232,6 +232,7 @@ type UTYF = uint8(enum unit_type_flag_id)
type CBONUS_TYPE = uint8(enum combat_bonus_type)
type TRI = uint8(enum traderoute_illegal_cancelling)
type MOVE_MODE = uint8(enum road_move_mode)
type GEN_ACTION = uint8(enum gen_action)

# typedefs for bit vectors
type BV_EXTRA_FLAGS = bitvector(bv_extra_flags)
Expand Down Expand Up @@ -1510,6 +1511,14 @@ PACKET_RULESET_TRADE = 227; sc, lsend
TRI cancelling;
end

PACKET_RULESET_ACTION_ENABLER = 235; sc, lsend
GEN_ACTION enabled_action;
UINT8 actor_reqs_count;
REQUIREMENT actor_reqs[MAX_NUM_REQS:actor_reqs_count];
UINT8 target_reqs_count;
REQUIREMENT target_reqs[MAX_NUM_REQS:target_reqs_count];
end

/**************************************************************************
Ruleset control values: single values, all of which are needed before
sending other ruleset data. After sending this packet, resend every
Expand Down
2 changes: 1 addition & 1 deletion data/alien/units.ruleset
Expand Up @@ -240,7 +240,7 @@ flags = "Missile", "DoesntOccupyTile"
; units other than missiles
; "Settlers" = can irrigate and build roads
; "Diplomat" = can do diplomat actions (see diplchance server option)
; "Spy" = can do poison and sabotage, _must_ be "Diplomat" also
; "Spy" = enhanced diplomat actions. _Must_ be "Diplomat" also
; "Trireme" = (sea only) cannot leave shoreline
; "Nuclear" = nuke!
; "Paratroopers"= (land only) can paradrop
Expand Down
37 changes: 37 additions & 0 deletions data/civ2/game.ruleset
Expand Up @@ -154,6 +154,43 @@ total_factor = 100
; strength even if they have only fractional moves left.
tired_attack = TRUE

; /* <-- avoid gettext warnings
;
; Action enablers:
;
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
;
; An action enabler is active when its actor_reqs AND its target_reqs are
; satisfied.
;
; actions and their hard coded requirements
; - "Poison City" = Kill a citizen in the target city.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target city must be size 2 or larger.
; - "Sabotage Unit" = Halve the target unit's hit points.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target must have > 1 hp.
; * target must be alone at its tile.
;
; */ <-- avoid gettext warnings
[actionenabler_poison_city]
action = "Poison City"
actor_reqs =
{ "type", "name", "range"
"UnitFlag", "Spy", "Local"
}

[actionenabler_sabotage_unit]
action = "Sabotage Unit"
actor_reqs =
{ "type", "name", "range"
"Unitflag", "Spy", "Local"
}

[borders]
; Base border radius from city.
radius_sq_city = 17
Expand Down
37 changes: 37 additions & 0 deletions data/civ2civ3/game.ruleset
Expand Up @@ -190,6 +190,43 @@ slow_invasions = TRUE
; strength even if they have only fractional moves left.
tired_attack = FALSE

; /* <-- avoid gettext warnings
;
; Action enablers:
;
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
;
; An action enabler is active when its actor_reqs AND its target_reqs are
; satisfied.
;
; actions and their hard coded requirements
; - "Poison City" = Kill a citizen in the target city.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target city must be size 2 or larger.
; - "Sabotage Unit" = Halve the target unit's hit points.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target must have > 1 hp.
; * target must be alone at its tile.
;
; */ <-- avoid gettext warnings
[actionenabler_poison_city]
action = "Poison City"
actor_reqs =
{ "type", "name", "range"
"UnitFlag", "Spy", "Local"
}

[actionenabler_sabotage_unit]
action = "Sabotage Unit"
actor_reqs =
{ "type", "name", "range"
"Unitflag", "Spy", "Local"
}

[borders]
; Base border radius from city.
radius_sq_city = 5
Expand Down
2 changes: 1 addition & 1 deletion data/civ2civ3/units.ruleset
Expand Up @@ -282,7 +282,7 @@ flags = "Unreachable", "DoesntOccupyTile"
; units other than missiles
; "Settlers" = can irrigate and build roads
; "Diplomat" = can do diplomat actions (see diplchance server option)
; "Spy" = can do poison and sabotage, _must_ be "Diplomat" also
; "Spy" = enhanced diplomat actions. _Must_ be "Diplomat" also
; "Trireme" = (sea only) cannot leave shoreline
; "Nuclear" = nuke!
; "Paratroopers"= (land only) can paradrop
Expand Down
37 changes: 37 additions & 0 deletions data/classic/game.ruleset
Expand Up @@ -182,6 +182,43 @@ slow_invasions = TRUE
; strength even if they have only fractional moves left.
tired_attack = FALSE

; /* <-- avoid gettext warnings
;
; Action enablers:
;
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
;
; An action enabler is active when its actor_reqs AND its target_reqs are
; satisfied.
;
; actions and their hard coded requirements
; - "Poison City" = Kill a citizen in the target city.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target city must be size 2 or larger.
; - "Sabotage Unit" = Halve the target unit's hit points.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target must have > 1 hp.
; * target must be alone at its tile.
;
; */ <-- avoid gettext warnings
[actionenabler_poison_city]
action = "Poison City"
actor_reqs =
{ "type", "name", "range"
"UnitFlag", "Spy", "Local"
}

[actionenabler_sabotage_unit]
action = "Sabotage Unit"
actor_reqs =
{ "type", "name", "range"
"Unitflag", "Spy", "Local"
}

[borders]
; Base border radius from city.
radius_sq_city = 17
Expand Down
2 changes: 1 addition & 1 deletion data/classic/units.ruleset
Expand Up @@ -258,7 +258,7 @@ flags = "Unreachable", "DoesntOccupyTile"
; units other than missiles
; "Settlers" = can irrigate and build roads
; "Diplomat" = can do diplomat actions (see diplchance server option)
; "Spy" = can do poison and sabotage, _must_ be "Diplomat" also
; "Spy" = enhanced diplomat actions. _Must_ be "Diplomat" also
; "Trireme" = (sea only) cannot leave shoreline
; "Nuclear" = nuke!
; "Paratroopers"= (land only) can paradrop
Expand Down
37 changes: 37 additions & 0 deletions data/experimental/game.ruleset
Expand Up @@ -188,6 +188,43 @@ slow_invasions = TRUE
; strength even if they have only fractional moves left.
tired_attack = FALSE

; /* <-- avoid gettext warnings
;
; Action enablers:
;
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
;
; An action enabler is active when its actor_reqs AND its target_reqs are
; satisfied.
;
; actions and their hard coded requirements
; - "Poison City" = Kill a citizen in the target city.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target city must be size 2 or larger.
; - "Sabotage Unit" = Halve the target unit's hit points.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target must have > 1 hp.
; * target must be alone at its tile.
;
; */ <-- avoid gettext warnings
[actionenabler_poison_city]
action = "Poison City"
actor_reqs =
{ "type", "name", "range"
"UnitFlag", "Spy", "Local"
}

[actionenabler_sabotage_unit]
action = "Sabotage Unit"
actor_reqs =
{ "type", "name", "range"
"Unitflag", "Spy", "Local"
}

[borders]
; Base border radius from city.
radius_sq_city = 17
Expand Down
2 changes: 1 addition & 1 deletion data/experimental/units.ruleset
Expand Up @@ -272,7 +272,7 @@ flags = "Unreachable", "DoesntOccupyTile"
; units other than missiles
; "Settlers" = can irrigate and build roads
; "Diplomat" = can do diplomat actions (see diplchance server option)
; "Spy" = can do poison and sabotage, _must_ be "Diplomat" also
; "Spy" = enhanced diplomat actions. _Must_ be "Diplomat" also
; "Trireme" = (sea only) cannot leave shoreline
; "Nuclear" = nuke!
; "Paratroopers"= (land only) can paradrop
Expand Down
37 changes: 37 additions & 0 deletions data/multiplayer/game.ruleset
Expand Up @@ -186,6 +186,43 @@ slow_invasions = TRUE
; strength even if they have only fractional moves left.
tired_attack = FALSE

; /* <-- avoid gettext warnings
;
; Action enablers:
;
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
;
; An action enabler is active when its actor_reqs AND its target_reqs are
; satisfied.
;
; actions and their hard coded requirements
; - "Poison City" = Kill a citizen in the target city.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target city must be size 2 or larger.
; - "Sabotage Unit" = Halve the target unit's hit points.
; * actor and target must be at war.
; * actor must have the diplomat flag.
; * target must have > 1 hp.
; * target must be alone at its tile.
;
; */ <-- avoid gettext warnings
[actionenabler_poison_city]
action = "Poison City"
actor_reqs =
{ "type", "name", "range"
"UnitFlag", "Spy", "Local"
}

[actionenabler_sabotage_unit]
action = "Sabotage Unit"
actor_reqs =
{ "type", "name", "range"
"Unitflag", "Spy", "Local"
}

[borders]
; Base border radius from city.
radius_sq_city = 17
Expand Down
2 changes: 1 addition & 1 deletion data/multiplayer/units.ruleset
Expand Up @@ -258,7 +258,7 @@ flags = "Unreachable", "DoesntOccupyTile"
; units other than missiles
; "Settlers" = can irrigate and build roads
; "Diplomat" = can do diplomat actions (see diplchance server option)
; "Spy" = can do poison and sabotage, _must_ be "Diplomat" also
; "Spy" = enhanced diplomat actions. _Must_ be "Diplomat" also
; "Trireme" = (sea only) cannot leave shoreline
; "Nuclear" = nuke!
; "Paratroopers"= (land only) can paradrop
Expand Down
2 changes: 1 addition & 1 deletion fc_version
Expand Up @@ -30,7 +30,7 @@ DEFAULT_FOLLOW_TAG=stable
# - Avoid adding a new mandatory capability to the development branch for
# as long as possible. We want to maintain network compatibility with
# the stable branch for as long as possible.
NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2013.Aug.30"
NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2013.Aug.31"
NETWORK_CAPSTRING_OPTIONAL=""

FREECIV_DISTRIBUTOR=""
Expand Down

0 comments on commit 8de924f

Please sign in to comment.