Event Tokens

What would you like to see in Freeciv? Do you have a good idea what should be improved or how?
User avatar
GriffonSpade
Elite
Posts: 578
Joined: Mon Apr 29, 2013 4:41 pm

Event Tokens

Postby GriffonSpade » Sat Dec 16, 2017 8:26 pm

Alright, here's the idea for Event Tokens. They are stored in two parts for each player. The First Part stores the turn number of the most recent occurance of an event. The Second Part checks if an event has occured withinin X turns, and can be used in effects.

First Part example:

Code: Select all

[event_turn_unit_victory]
name           = _("Unit Victory")
type           = "unit_win_att"

This records the latest turn a unit has won a battle.
Default stored variable would be -1.
Updated whenever the event type occurs.
The First Part is never checked by anything but Second Part event tokens, never effect requirements.
Should probably be hardcoded to existing events instead.

Second Part example:

Code: Select all

[event_bool_morale_boost]
name           = _("Morale Boost")
type           = "Unit Victory"
value          = 1

This checks if "Unit Victory" event has occured in the past 1 turn or less.
Positive or Null value returns TRUE if First Part's stored variable is between 0 and value. (it happened within value turns)
Negative value always returns TRUE if First Part's stored variable is -1 (it never happened).
Always returns FALSE if First Part's stored variable is greater than value (it did not happen within value turns)

Effect requirements usage example:

Code: Select all

reqs  =
    { "type", "name", "range"
      "Event", "Morale Boost", "Player"
    }

This checks if the "Morale Boost" event token is true for this player.

Thoughts:
Events would ideally be recorded at the City level, not just Player level, where appropriate (ie building, unit, city events).
For unit-based events, the city (including special "None" for unhomed units) would be based on the unit's home city to allow for units' success or failure to affect their home cities.
IE, if a unit is killed, its home city would receive military unhappiness for a few turns, perhaps even /more/ military unhappiness than if they were just out-of-border, since no one likes their neighbors being killed. On the other hand, if a unit successfully kills an enemy unit, perhaps their military unhappiness is reduced.

Event Types:
Essentially, anything that triggers an Event Message to be sent to the player. (There are what, 140 or so of these?)

Lachu
Elite
Posts: 388
Joined: Sat May 04, 2013 2:19 pm

Re: Event Tokens

Postby Lachu » Sat Dec 16, 2017 9:14 pm

I see you suggest to make connection of effect accumulators and effect events (both mechanism was introduced to Progress). Maybe collaborate?

User avatar
dunnoob
Elite
Posts: 326
Joined: Mon Dec 23, 2013 3:13 am
Location: Hamburg
Contact:

Re: Event Tokens

Postby dunnoob » Tue Dec 19, 2017 1:42 am

GriffonSpade wrote:This records the latest turn a unit has won a battle.
Quick sanity check, if what you suggest boils down to XP (experience points) as in Battle for Wesnoth (among others) instead of random chances to gain a veteran level, I'm very much for XPs.

It can't be too hard to implement (=not harder than the nationality tracking), but it might not scale. At the moment 2.6 beta is already on the border to unplayable with my RAM (4 GB, 2011), and I miss a version between 2.5 (fast) and 2.6 (better) minus non-essential stuff like cultural points, e.g., a cultural victory could be triggered by the existing score values instead of cultural points. Besides I'm used to shrink about 2 of 3 conquered AI-cities to size 0, helping to grow the 3rd conquered city, but that loses any (2.6) accumulated cultural points in disbanded cities.

User avatar
GriffonSpade
Elite
Posts: 578
Joined: Mon Apr 29, 2013 4:41 pm

Re: Event Tokens

Postby GriffonSpade » Tue Dec 19, 2017 6:20 am

dunnoob wrote:
GriffonSpade wrote:This records the latest turn a unit has won a battle.
Quick sanity check, if what you suggest boils down to XP (experience points) as in Battle for Wesnoth (among others) instead of random chances to gain a veteran level, I'm very much for XPs.

It can't be too hard to implement (=not harder than the nationality tracking), but it might not scale. At the moment 2.6 beta is already on the border to unplayable with my RAM (4 GB, 2011), and I miss a version between 2.5 (fast) and 2.6 (better) minus non-essential stuff like cultural points, e.g., a cultural victory could be triggered by the existing score values instead of cultural points. Besides I'm used to shrink about 2 of 3 conquered AI-cities to size 0, helping to grow the 3rd conquered city, but that loses any (2.6) accumulated cultural points in disbanded cities.


Ah, it's not experience points. It isn't attached to individual units, and it doesn't 'accumulate' beyond the latest event (at each level of granularity, ie world, player, city), but rather overwrites/records the turn when an event occurs and can then be used to check if an event has occured in the past W turns. Ideally with city-level granularity.

So, Event X, Player Y, City Z, and Turn T would be recorded like this:

(World Granularity)
Event = X
Turn = T

(Player Granularity)
Event = X
Player = Y
Turn = T

(City Granularity)
Event = X
Player = Y
City = Z
Turn = T

Each time Event X occurs, it would update all these values to the latest turn. And create new tokens for Player and City granularity as necessary. (Though these would certainly be recorded with arrays of some sort)
(Three levels of granularity are written here to cut down search times for higher granularities, as checking every city when checking world seems onerous. Team and Alliance would use the Player-level granularity to search.)

Then, when you search for them, it would search through the values at the appropriate granularity level.

If you want to know if Event A occurred for Player B in City C within the past N turns.

Note that these events already occur, as you get event messages for them. Here is the list of events provided for in the tilespec in 2.6:

Code: Select all

  0,  0, "e_city_cantbuild"
  0,  1, "e_city_lost"
  0,  2, "e_city_love"
  0,  3, "e_city_disorder"
  0,  4, "e_city_famine"
  0,  5, "e_city_famine_feared"
  0,  5, "e_unit_built_pop_cost"
  0,  6, "e_city_growth"
  0,  7, "e_city_may_soon_grow"
  0,  8, "e_city_aqueduct"
  0,  9, "e_city_aq_building"
  0, 10, "e_city_normal"
  0, 11, "e_city_nuked"
  0, 12, "e_city_cma_release"
  0, 13, "e_city_gran_throttle"
  0, 14, "e_city_transfer"
  0, 15, "e_city_build"
  0, 16, "e_city_production_changed"
  0, 17, "e_disaster"
  0, 18, "e_city_plague"
  0, 12, "e_worklist" ; (0, 19) unused
  0, 12, "e_city_radius_sq" ; (0, 20) unused

  1,  0,  "e_treaty_shared_vision"
  1,  1,  "e_treaty_alliance"
  1,  2,  "e_treaty_peace"
  1,  3,  "e_treaty_ceasefire"
  1,  4,  "e_treaty_broken"
  1,  5,  "e_treaty_embassy"

  1,  6, "e_imp_buy"
  1,  7, "e_imp_build"
  1,  8, "e_imp_auctioned"
  1,  9, "e_imp_sold"
  1,  10, "e_imp_auto"
;  1,  11, "e_imp_destroyed"

  1, 12,  "e_wonder_build"
  1, 13,  "e_wonder_started"
  1, 14,  "e_wonder_stopped"
  1, 15,  "e_wonder_will_be_built"
  1, 16,  "e_wonder_obsolete"

  2,  0, "e_hut_barb"
  2,  1, "e_hut_city"
  2,  2, "e_hut_gold"
  2,  3, "e_hut_barb_killed"
  2,  4, "e_hut_merc"
  2,  5, "e_hut_settler"
  2,  6, "e_hut_tech"
  2,  7, "e_hut_barb_city_near"

  2,  8, "e_tech_gain"
  2,  9, "e_tech_learned"
  2, 10, "e_tech_lost"
  2, 11, "e_tech_embassy"
  2, 11, "e_tech_goal"
 
  3,  0,  "e_unit_lost_att"
  3,  1,  "e_unit_win_att"
  3,  2,  "e_unit_buy"
  3,  3,  "e_unit_built"
  3,  4,  "e_unit_lost_def"
  3,  5,  "e_unit_lost_misc"
  3,  6,  "e_unit_became_vet"
  3,  7,  "e_unit_upgraded"
  3,  8,  "e_unit_relocated"
  3,  9,  "e_unit_orders"
  3, 10,  "e_unit_illegal_action"
  3, 11,  "e_caravan_action"
  3, 12,  "e_unit_win"
;  3, 13,  "e_unit_escaped"
;  3, 14,  "e_unit_was_expelled"
;  3, 15,  "e_unit_did_expel"
;  3, 16,  "e_unit_action_failed"

  4,  0, "e_my_diplomat_escape" ; base sprite for my diplomats
  4,  1, "e_my_diplomat_bribe"
  4,  1, "e_my_spy_steal_gold"
  4,  2, "e_my_diplomat_incite"
  4,  3, "e_my_diplomat_embassy"
  4,  4, "e_my_diplomat_failed"
  4,  5, "e_my_diplomat_sabotage"
  4,  6, "e_my_diplomat_theft"
  4,  7, "e_diplomatic_incident"
  4,  8, "e_my_diplomat_poison"
;  4,  9, "e_my_spy_nuke"
;  4, 10, "e_my_spy_steal_map"
;  4, 11, "e_embassy_was_expelled"

;  5,  0, "e_enemy_diplomat_escape" ; base sprite for enemy diplomats
  5,  1, "e_enemy_diplomat_bribe"
  5,  1, "e_enemy_spy_steal_gold"
  3,  2, "e_enemy_diplomat_incite"
  3,  3, "e_enemy_diplomat_embassy"
  3,  4, "e_enemy_diplomat_failed"
  3,  5, "e_enemy_diplomat_sabotage"
  3,  6, "e_enemy_diplomat_theft"
;  3,  7, "e_enemy_diplomatic_incident"
  5,  8, "e_enemy_diplomat_poison"
;  5,  9, "e_enemy_spy_nuke"
;  5, 10, "e_enemy_spy_steal_map"
;  5, 11, "e_embassy_did_expel"


  6,  0, "e_achievement"
  6,  1, "e_uprising"
  6,  2, "e_civil_war"
  6,  3, "e_anarchy"
  6,  4, "e_first_contact"
  6,  4, "e_diplomacy"
  6,  4, "e_new_government" ; (4, 5) unused
  6,  4, "e_nation_selected"
  6,  4, "e_setting"
  6,  4, "e_message_wall"
  6,  4, "e_connection"
  6,  5, "e_destroyed"
  6,  6, "e_low_on_funds"
  6,  7, "e_pollution" ; copy from small.png
  6,  8, "e_revolt_done"
  6,  9, "e_revolt_start"
  6, 10, "e_spaceship"
;  6, 11, "e_spontaneous_extra"

  6,  4, "e_vote_new"
  6,  5, "e_vote_aborted"
  6, 11, "e_vote_resolved"

  6, 12, "e_nuke"
;  6, 13, "e_chem"
  6, 14, "e_ai_debug"
  6, 14, "e_script"
  6, 14, "e_broadcast_report"
  6, 14, "e_report"
  6, 14, "e_chat_msg"
  6, 14, "e_log_error"
  6, 14, "e_deprecation_warning"
  6, 15, "e_global_eco"
  6, 15, "e_log_fatal"
  6, 15, "e_chat_error"
  6, 16, "e_bad_command"

  6, 17,  "e_game_start"
  6, 18,  "e_next_year"
  6, 19,  "e_game_end"
  6, 20,  "e_turn_bell"


As for experience points, what's the maximum number of Veteran Levels? You could probably abuse it to some extent.
IE make the levels "green 0/2", "green 1/2", "veteran 0/3", "veteran 1/3", "veteran 2/3", "hardened 0/5", "hardened 1/5", "hardened 2/5", "hardened 3/5", "hardened 4/5", "elite"
Something that might be needed for that, on the other hand, is the ability to declare the veteran sprite for each veteran level.

Lachu
Elite
Posts: 388
Joined: Sat May 04, 2013 2:19 pm

Re: Event Tokens

Postby Lachu » Tue Dec 19, 2017 2:54 pm

Progress records each lua events emitted in current turn. Code is in state_machine.c. Code is very simple. There's also code, which records each activated effect and allow to:
- multiply value of effect by number of turns the effect is activated
- Restrict number of turns the effect is active
- Set minimum number of turns effect should be active
- etc.

Progress is on the same license as Freeciv, so you can use code from it, but I'm not very good in software developing/engineering, so if you create better idea or code, I would be happy.