Opened 3 years ago

Last modified 16 months ago

#6254 new enhancement

[PetraAI] - Use more robust dependency injection.

Reported by: Freagarach Owned by:
Priority: Nice to Have Milestone: Backlog
Component: AI Keywords: design, simple
Cc: Patch:

Description

E.g. currently gameState.ai.HQ is called by plenty of "managers". It would increase modularity of the systems if upon creation the manager would receive its commanding HQ and use that. The same can be said of e.g. plans that originate from a manager (e.g. transportPlan querying gameState.ai.HQ.navalManager).

This way, it might be possible (for modders) to have more than one manager of a kind. And at least it is more modular.

Change History (6)

comment:1 by Stan, 3 years ago

Sounds okay. Are there other design alternatives (Other design patterns maybe)? Dependency injection is apretty common thing.

comment:2 by Freagarach, 3 years ago

Well, the current state is also some kind of dependency injection, since the gameState is passed along. One could even argue the current state is a more pure dependency injection. However, our current state of PetraAI is something in between, we save the config at creation but query the gameState later on.

So another approach -- which may be even more DI-like -- would be to save nothing at manager/plan creation time, but always just pass gameState and manager when calling a function. (gameState for querying the current state of affairs and the manager to get e.g. config data).

Since a manager highly depends on the HQ which instantiated it and has a persistent state, I would prefer the approach of saving the HQ on creation/init.

comment:3 by Silier, 3 years ago

Keywords: simple removed
severity: simple

comment:4 by Silier, 3 years ago

Keywords: simple added

comment:5 by Stan, 2 years ago

Milestone: Alpha 26Alpha 27

Unlikely to get done for A26

comment:6 by Freagarach, 16 months ago

Milestone: Alpha 27Backlog

Pushing back.

Note: See TracTickets for help on using tickets.