Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#725) Order of end/new-turn activities
Home

[Freeciv-Dev] (PR#725) Order of end/new-turn activities

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ChrisK@xxxxxxxx
Subject: [Freeciv-Dev] (PR#725) Order of end/new-turn activities
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 May 2004 00:28:58 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=725 >

> [ue80@xxxxxxxxxxxxxxxxxxxxx - Tue May 11 09:42:51 2004]:

> We should use shuffled players only when we need it. And every case
> where we can use players_iterate instead of shuffled_players_iterate is
> good.

Why?

> So i think we have to go a step back. Name all action, categorice them,
> search dependencies and after that decide how to solve the dependencies.

The question is what is an "action".  If we break all actions down into
their absolute smallest parts, we will have a huge number of truly
atomic actions.  We'd like to be able to group micro-actions together,
but this is dangerous.

As for unit activities: in my previous e-mail I simplified a few of the
"complicated" actions into one line.  One such was unit activities. 
Another was the city "refresh".  Obviously these should be broken apart
when considering the logic.  However I suspect there will be major
technical problems if we try to actually separate them.  Handling
different unit activities at different times sounds like a recipe for
disaster.

Attached is an updated document.  It's now even more complicated, though
still incomplete.

jason


begin turn (this happens before each turn):
  - Reset fog of war if game.fog_of_war is changed.
  - For each player:
    - Do nothing [1].
    - Reset all sorts of AI/advisor data.
  - For each player:
    - For each city:
      - "Refresh" the city [2].
      - Send updated info about the city to the owner.
  - For each player:
    - If they are a non-barbarian AI player
      - Do diplomacy (threats, war, etc).
  - Reshuffle players.
  - Do AI beginning-of-turn actions (complicated).
  - Tell clients the turn has started.
  - "Thaw" clients.
  - Autosave.

Then the turn happens.

end turn (this happens after each turn):
  - Tell the clients the turn is over.
  - "Freeze" clients.
  - Summon barbarians.
  - Move autosettlers (very complicated).
  - Do autoattack:
    - For each shuffled player:
      - For each city:
        - For each unit in the city:
          - Auto-attack, if applicable.
      - For each unit the player owns:
        - If the unit may have auto-attacked the previous turn, return it
          to the city.
  - Freeze sending of cities.
  - For all ai players:
    - Do AI end-of-turn activities (complicated).
  - For all shuffled players:
    - Give techs for great library.
    - Decrement anarchy turn count.
    - "restore" units:
      - Leonardo's upgrades
      - For all units the player owns:
        - Gain/lose HP for rest, united nations, helicoptor.  Activate
          sentried units that lost HP.
        - Kill units with no HP.
        - Kill or veteran triremes far from the coast.
        - If the unit is an air unit:
          - "Return" planes that are out of fuel to the nearest landing point.
          - Decrease plane fuel
          - Refuel if the plane is landed
      - For all units the player owns:
        - Crash the plane if it's out of fuel.
    - "Update" cities:
      - For each city the player owns:
        - "Refresh" the city [2].
        - Calculate production:
          - Account for unit shield upkeep; kill units if necessary.
          - Increase shield stock from shield surplus.
          - Reset the last-turns-shields values (the values used when
            changing production - there are 6 such values [3]).
          - If the city is building a building:
            - Give money for capitalization.
            - Upgrade building production.
            - Fail if the building isn't buildable (obsolete).
            - Build the building if there's enough shield stock:
              - Remove duplicate palaces.
              - Add space parts, if applicable.
              - And add the improvement to the city.
              - Decrease shield stock.
              - Update "before change shields" and "turn last built".
              - Notify for built wonders.
              - Notify for the built building.
              - Give techs for darwins'.
              - Notify for newly-started spaceships.
              - Send new spaceship info to clients.
              - "Refresh" city [2].
              - Choose new build target from worklist or advisor.
          - If the city is building a unit:
              - Upgrade unit production.
              - Fail if the unit is unbuildable/obsolete.
              - If there's enough sheild stock to complete the production:
                - Disband the city if applicable.
                - Fail if we don't want to disband the city.
                - Update "turn last built".
                - Create the new unit.
                - Reduce population if unit has pop_cost.
                - Update shield stock and "before-change shields".
                - Notify player of built unit.
                - Pick new production from worklist or advisor.
        - If the city has died, skip the rest of the updates.
        - Update celebration:
          - If the city is celebrating [4]:
            - Increase rapture (+1).
            - Notify player if city just started rapture (rapture == 1).
          - If city is not celebrating:
            - Notify player if city just ended rapture (rapture != 0).
            - Reset rapture (to 0).
          - Update was_happy (which is used to determine whether the
            city celebrates next turn).
        - Update population:
          - Increase food stock from food surplus (may be negative).
          - Increase city size for full granary or rapture.
          - If food stock is negative:
            - Kill a single unit if possible.
            - Otherwise famine: reduce city size, reset granary. [5]
        - If the city has died, skip the rest of the updates.
        - Reset is_updated, did_sell, did_buy, airlift.
        - Add bulbs from research in this city:
          - Add bulbs to total (including teammates).
          - Complete research, if possible.
        - Add tax to treasury.
        - Pay for units supported by this city.
        - Pay for buildings in this city.
        - If city is unhappy, put it into anarchy and notify player.
        - If city isn't unhappy, end anarchy and notify player.
        - Add map pollution.
        - Send city info to everyone.
        - If anarchy > 2 and in democracy, drop civ into anarchy.
    - Reset research "changed from" value.
    - Kill any dead or dying players.
    - "Thaw" cities.
    - For all players:
      - Send owner info about all their cities.
      - Reset some AI data.
    - Update global warming from map pollution.
    - Update nuclear winter from map fallout.
    - Update "diplomatics":
      - For all players
        - For all other players
          - Decrement ceasefire, contact, reason_to_cancel.
          - Break ceasefire or notify of impending expiration.
          - update player reputation [6].
    - Reveal map for apollo.
    - Make contact for marco pollo.
    - Update civ scores, and make history report every 20 turns.
    - Send turn notifications:
      - For each player:
        - For each city:
          - Notify owner of throtting growth, impending growth,
            impending famine.
      - For each player:
        - For each city:
          - Notify everyone of nearly-built wonders.
    - Advance the year and increment the turn #.
    - For each shuffled player:
      - For each unit owned by that player, update the unit's activity:
        - Increment the activity "count" for
          certain activities (all except idle, fortified, goto, explore).
          The amount the activity is increased by depends on the number of
          moves left for the unit in some bizarre way.
        - Make settlers veteran, if applicable.
        - Restore the units MP.
        - Do gotos for "connecting" units. [7]
        - For connecting units building railroad, change the activity to
          road if needed. [7]
        - Have the AI handle exploring units.
        - Pillage (if done).
        - Clean pollution (if done).
        - Clean fallout (if done).
        - Build fortress (if done).
        - Build airbase (if done).
        - Build irrigation (if done).
        - Build road (if done.  Work toward rail counts toward road).
        - Build rail (if done).  [8]
        - Build mine (if done).
        - Transform terrain (if done). (Units are not bounced until later!)
        - If one of the above activities was completed:
          - Send tile info.
          - For every unit on the tile doing this activity:
            - Do gotos for any completed connecting units on this tile [9].
            - Idle any other units.
        - Fortify the unit, if done fortifying.
        - Do server goto for units on "goto".  (This includes air goto.)
        - Execute orders for units on "orders" (client-side goto).
        - Check the activity of EVERY other unit on the tile.  If it can't
          continue its activity, idle it.  (Presumably this would come into
          play if you build irrigation and mining at the same time.)
        - If land was changed into ocean:
          - Move all ground units to nearby land or transport, or kill
            them [10].
        - If ocean was changed into land:
          - Move all sailing units into nearby ocean or city, or kill them.
    - Update timeout.
    - Check for spaceship arrivals.
    - Send out player, game, and year info.
    - Send new info to the metaserver.

"Refreshing" a city is a complicated process.  It basically involves
recalculating everything about the city (food, trade, shields, tax, luxury,
science, happy/content/unhappy/angry citizens, upkeep, surpluses, trade
routes (this is recursive!!!), etc.

[1] An empty function call inside another empty function call.  Should be 
removed.
[2] The city refresh is a complicated update.  But it doesn't actually do 
anything, just updates some possibly-stale values.
[3] This is done in 3 different function calls.  Should be merged into a single 
function.
[4] A city celebrates if was_happy is set and it's large enough.
[5] We only kill off one unit _or_ have famine.  With a large negative food
this could be a bug.  Say you have 0 food in the store, with a surplus of -3
and supporting a settlers (upkeep 2).  Now you'll kill the settlers, reset the
surplus to 0, and there will be no famine.  So basically you get a free food.
[6] This is almost certainly a bug, since it means each player's reputation is 
reset many times per turn.
[7] I want to get rid of this code and have connecting be done by client-side 
orders.
[8] It looks like work toward rail may be counted double here.  But I'm not 
quite sure of the logic.  In general, though, there's nothing in this code 
preventing a unit's work from counting toward multiple build targets in a 
single turn.
[9] The logic of this seems extremely complicated.
[10] There's a bug here with ocean cities.  We should allow movement into ocean 
cities.

[Prev in Thread] Current Thread [Next in Thread]