# Game Programming in C, Question about strategic games

Hi,

don't we all love real-time strategic-games like

command&conquer or starquest? I wanted to programm

such a game and coded foundatations, but just i completed this there was the question how to implement

a function that calculates dynamically how an object

must move from a to b via c. Where c can change all

the time.

Can you help me?

Every idea welcome.

Christian Linnemann

[email protected]

GERMANY

• I read your question a few hours ago and pondered it for a while, here's what I came up with:

1) Take your two points, A and B.

2) Calculate the midpoint between them [(Ax + Bx)/2, (Ay + By) /2] and call it point C.

3) Find the normal to vector AB.

4) Move point C in the direction of that vector, or it's opposite direction, until one or the other reaches an empty space that is a pre-defined minimum distance from any obstacles.

You now have two vectors, AC and CB. If either of these overlap with details on the map, the repeat the process describe above on it.

This is a recursive function. you just need to keep breaking down the vector into path and smaller pieces.

NOTE: when repeating this process, you are best to change step four _slightly_. Rather than checking in both directions, try just checking to the direction that points away from the triangle ABC. (eg. you have broken up vector AB into AC and CB, and you have move C away from line AB. If you now have to break up vector AC, you calculate it's midpoint, D, and move it along the normal to AC, but AWAY fro triangle ACB.)

I have only tested this on paper and it's fairly sound, but not perfect.

After you have found a path, you have to clean out redundant steps by checking between any points that are not already connected, and making sure that it actually is impossible to go on a straight line between them. If it is possible, then you can make your path go between them and throw away any points in between.

I hope that helps!