How did you do that, if I may ask?
I assume you were talking to me?
for (int i = 0; i < Tiles.size(); i++) {
Side0Densities[i] = 0;
}
for (int i = 0; i < Tiles.size(); i++) {
int x = i%50;
int y = i/50;
for (int& ID: Tiles[i].Inhabitant_IDs) {
if (EntitySides[ID] == 0) {
for (int j = 0; j < Tiles.size(); j++) {
Side0Densities[j] += B_InverseSquare[ DistFromHex( x - (j%50), (j/50) - y ) ]; // Precalculated, yay for removing bottlenecks
}
}
}
}
This thing determines the concentration of enemies. Basically it goes through all the enemies, and through all the hexes. It then adds 1/Distance
2 to each tile(so 1 if directly on top, 1/4 on the next tile, and then 1/9 and so on). It was originally actually the basis of my
lighting system(and why it makes a nice red glow right now), but I thought it would actually work for this purpose too. After that it's a simple matter of looking for the neighbouring hex with the greatest concentration.
It's not very complicated, or smart, and I can't really control it very much(except for changing the power a bit), but it is a nice O(n), meaning I can throw exactly as much crap into the game as I want and it seems to have the correct behaviour.
It does have its exploitable faults though. When facing a big army of cannonfodder, units will nearly ignore anyone flanking them. But I think that just adds to the fun.
Oh, and I seem to have forgotten to say what it's for. I'm basically recreating Domnions 4 except with a hex grid. So no player interaction during a battle except for the initial orders. Everything is AI led.
EDIT: Fuck, found a problem.
Look at the arrows in the up and down directions. It finds the shortest path to the centre in this case, but it doesn't do the "correct" way of zig-zagging down, but rather folds into the diagonals. I think I might need to add some special logic.
EDIT2:
Ahh, perfect.