[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]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=725 >
Some new thoughts.
First, I want to call a portion of a turn a "phase". Someone (Per?)
used this term before and it is clearer.
I also define the "active" players for a phase as the players allowed to
move this phase. This may be no players (maybe), one player, all
players on one team, or all players.
At the beginning of a turn & a phase we must init data and perform
actions. However when loading a savegame we should init the data but
not perform any actions. Thus we need 6 different operations:
turn_iterate {
init_turn();
if (...) begin_turn();
phase_iterate {
init_phase();
if (...) begin_phase();
/* ... do phase */
end_phase();
}
end_turn();
}
Attached is a new version of the turn list. At the top is my idea how
how the breakdown "should" be. There are a few undecided points.
I have left off (clumped together) unit restoration, city updates, and
unit activities (except orders which must be moved). All of these
should go into end_phase(). The order of these is very important but I
think we should deal with it separately from the global ordering.
Please review this. I'd like to start making some patches to carefully
move toward this goal.
Note that this design encompasses PR#576 and PR#4733.
jason
*** New Method ***
init turn (before each turn)
- Reset FoW
- Tell clients the turn has started
begin turn (at the start of each turn - but not if we just loaded a game) :
- Reshuffle players (if enabled)
init player phase : do these actions for the active player(s)
- "Refresh" all cities
- Send updated city info to owner
- AI init data
- Reset all sorts of AI/advisor data
- Update phase, and tell clients.
[ In alternating movement only after this will the player be allowed
to move. Without alternating movement this step can be skipped. ]
begin player phase : Do these actions for each player, except on load.
- AI beginning-of-turn activities:
- Do AI diplomacy
- Do AI danger assessment
- Do AI unit management
- Kill dying/dead players
- Execute orders for units.
- "Thaw" clients
- Autosave
end player turn (after each phase) : Do these actions for each player.
- "Freeze" clients.
- Move autosettlers.
- Do autoattack (this player only):
- For each city:
- For each unit in the city:
- Auto-attack, if applicable.
- For each owned unit:
- Return auto-attack unit to city, if applicable.
- Freeze sending of cities
- Do AI end-of-turn activities:
- Manage AI government.
- Manage AI taxes.
- Manage AI cities.
- Manage AI tech.
- Manage AI spaceship.
- Reset AI data (ai_data_turn_done).
- Great library.
- Decrement anarchy turn count.
- Restore units & update cities (very complicated!)
- Reset research "changed from" value.
- Kill any dead or dying players.
- "Thaw" sending of cities.
- Send owner info about all their cities.
- Update "diplomatics":
- For all players:
- For all other players
- Decrement ceasefire, contact, reason_to_cancel
- Break ceasefire or notify of impending expiration.
[ A treaty that lasts 1 turn should last exactly 1 turn. So
either the treaty length gets multiplied by the number of
phases or the treaty tells exactly which turn and phase it is
broken in. Same thing with contact and has_reason_to_cancel.
Otherwise it's not fair to one of the players. ]
- Update player reputation
- Handle apollo & marco pollo
- City notifications:
- For each city:
- Notify owner of throttling growth, impending growth, impending famine
- Notify everyone of nearly-built wonders
[ This gives everyone a single turn to do something about it. But
because of the strict phase ordering, there's now no way to beat
this player to the wonder. You may however interrupt its
production. ]
- Update unit activities, EXCEPT orders executiong (complicated)
- Update timeout. [???]
- Check for spaceship arrivals.
[ Maybe this should be done once a turn only? ]
- Send out player, game, and year info.
end turn (after each turn) :
- Update global warming from map pollution.
- Update nuclear winter from map fallout.
- Update civ scores, and make history report every 20 turns.
[ Maybe this should be done each phase? ]
- Advance the year and increment the turn #
- Send new info to the metaserver.
*** Old Method ***
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. For each shuffled AI player:
- Assess dangers.
- Manage units.
- kill dying/dead players (killed by AI).
- 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.
- AI end-turn activities. For all AI players:
- Manage AI government.
- Manage AI taxes.
- Manage AI cities.
- Manage AI tech.
- Manage AI spaceship.
- 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 (ai_data_turn_done).
- 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.
|
|