Help me design my movement system properly

Started by
10 comments, last by King of Men 16 years, 10 months ago
Just because you need the 'virtual' keyword for some functionality doesn't mean you need to apply it to everything. If the find-next-location algorithm is the same for Provinces as it is for ProvinceBorders (and it should be; you can presumably represent pointers-to-neighbours internally as base Location pointers), then just put that functionality in the base class (and just accept a base Location reference for the destination).

Also, consider using references for the input parameter and return value rather than pointers (although a pointer might be useful for the return value so that a NULL indicates "sorry, can't get there from here"). In general, you prefer references at the interface level, and pointers within the implementation (i.e., as data members of a structure).
Advertisement
Quote:Original post by Zahlman
Just because you need the 'virtual' keyword for some functionality doesn't mean you need to apply it to everything. If the find-next-location algorithm is the same for Provinces as it is for ProvinceBorders (and it should be; you can presumably represent pointers-to-neighbours internally as base Location pointers), then just put that functionality in the base class (and just accept a base Location reference for the destination).


I think you've put your finger on it. The find-next-location is not the same for Provinces and ProvinceBorders, because they have different restrictions on how economic units can move. However, those restrictions are not actually relevant to how military units move. Therefore, I should only expose that particular path-finding to the economic system, and write a different one for the military system, instead of trying to shoehorn everything into the economic pathfinding. Fortunately I wrote my A* to be quite general, it doesn't know anything about Provinces and ProvinceBorders. :)
To win one hundred victories in one hundred battles is not the acme of skill. To subdue the enemy without fighting is the acme of skill.

This topic is closed to new replies.

Advertisement