puzzlepaint / freeage

An open-source reimplementation of the game engine of Age of Empires 2: Definitive Edition.
59 stars 4 forks source link

Ability to build a town center if the player does not have one #6

Closed puzzlepaint closed 4 years ago

puzzlepaint commented 4 years ago

In the Dark Age, it should be possible to construct a new town center if the initial town center was lost (or if there is no initial town center, such as on the Nomad map). So, the ability to construct a town center should be added, under the condition that no town center (or town center foundation) exists for the player that wants to build it. (Since the Dark Age is currently the only age that is supported, no check for the age needs to be done yet.)

Edit: The town center presents a special case in the sense that the map area occupied while building differs from the map area occupied while finished. This will need to be handled.

MaanooAk commented 4 years ago

Are you thinking about a keeping track of the number of each building type that the player has or just iterate over all the objects and count whenever its needed?

(I have some free time to write C++ ...)

puzzlepaint commented 4 years ago

Both approaches seem valid. Counting when needed has the advantage that it eliminates the possibility that something goes wrong with keeping track of the count over time (such as if a case where an object can be added or removed is overlooked, or if an addition/removal is wrongly counted twice in rare circumstances). Also, it is probably fast enough to not be a performance concern. But keeping track of the count would still be better performance-wise. Also, something like this is already being done for keeping track of the population space, so the places where buildings are added/removed need to be identified anyway. Given that, I think I would slightly favor to keep track of the count, but both approaches seem fine.

grst commented 4 years ago

At that point, you could also consider that this could be used for the statistics screen at the end of the game (total castles, buildings razed etc.) that might be implemented at some point in the future.

On Thu, 16 Apr 2020 at 14:26, Thomas Schöps notifications@github.com wrote:

Both approaches seem valid. Counting when needed has the advantage that it eliminates the possibility that something goes wrong with keeping track of the count over time (such as if a case where an object can be added or removed is overlooked, or if an addition/removal is wrongly counted twice in rare circumstances). Also, it is probably fast enough to not be a performance concern. But keeping track of the count would still be better performance-wise. Also, something like this is already being done for keeping track of the population count, so the places where buildings are added/removed need to be identified anyway. Given that, I think I would slightly favor to keep track of the count, but both approaches seem fine.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/puzzlepaint/freeage/issues/6#issuecomment-614620355, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVZRV6GYQFASQ3PMM52RSLRM32OZANCNFSM4MGCJ2SQ .

MaanooAk commented 4 years ago

In that case, I would suggest a struct named something like PlayerStats that that keeps track of all that kind of information: population stuff, building counters per type (buildings under construction (for the max check), built (for the max check, the score and the dependency checks), building that have been built at least once (for the dependency check**), unit counts (could be useful to known how many of the villagers are on wood by checking the FemaleVillagerLumberjack and MaleVillagerLumberjack count) and even other thinks like how many idle workers?

Using one thing for all the stats would also make clearer where the code to keep track of things should go.

Also you could keep some snapshots/copies of the struct in a list and at the end create the timeline-graph thing. And also calculate other things, eg. the time that you had idle workers and the "work-hours" lost.

** I'm not sure but I think you don't need a barracks to build an archery, you just needed to had a barracks at some point.

I will give it a go in the next days, if its ok with you.

puzzlepaint commented 4 years ago

Sounds very good to me. Notice that on the server, there is struct PlayerInGame which stores some player-related information. The statistics might be stored as a member there. Only the server will know the full statistics, since clients should eventually only receive the information that they see, not that of all players. The clients however also need their own information, for example to display the worker count on each resource, or in order to know whether to offer the player to build a new town center. On the client, class GameController currently has the role to store related information: the population and resource information is currently stored there.

I'm also not sure, but I think it is correct that a barracks only needs to be constructed once to unlock the dependent buildings. I think that in "Forest Nothing", players sometimes built a mill and then immediately deleted it again to build a farm in the same spot, which probably follows the same mechanism.

puzzlepaint commented 4 years ago

An additional related thought regarding the post-game statistics: Possibly it would be best to store events for making these statistics, for example, events like "at game time 00:37, a villager was created". This allows to have the best possible time resolution for the statistics, allowing for zooming into the graphs. Having the same time resolution with the snapshot-based approach would require to make a snapshot at each frame (or at least at each frame in which something happens), which may take a lot of memory.

Possibly these events don't even need to be stored separately. This is because one way to provide game recordings would be to make the server store all network messages that it would send to a game spectator (who sees the whole map). The receipt of these messages can later be simulated to play back the game recording. At the same time, these messages probably also contain the events already that could be used to make the statistics.

So, if we do it as described above, then the PlayerStats would probably not need the ability for snapshots, since the replay data could be used to make the statistics instead (with the best possible time resolution).

puzzlepaint commented 4 years ago

The ability to build the town center was addressed by #9. Minor things still left to do:

puzzlepaint commented 4 years ago
  • Give the town center the whole 4x4 tile occupancy while under construction

Addressed by: e3298c947c0bf45d2a5e7e4644a3a33bd1dc2c70

  • Add something like MaxElevationDifferenceForBuilding() and set it to zero for town centers, since the game should only allow them to be built on fully flat terrain

Addressed by: 5c47fa587110675f9a7906bc824800c891f087d7