100k visitors and some Projekt "W"

Since relaunching my page with Wordpress back in march 2007, there have been over 100,000 visitors to my page. Although this does not sound much at first, I guess it’s pretty good for a personal page (together with the fact that there were roughly 75,000 visitors to my page before that relaunch) and I hope that all those visitors enjoyed my projects, demos, applications and tutorials. And for those interested in numbers, I just saw that the** traffic generated by my page for the first five months of 2008** (including views and downloads) has topped 1.5 terabytes, with most of the traffic coming form downloads generated by my games. In my eyes this is a nice summary, and I hop that it’ll continue like that!

And now back to my current work, “Phase 2” for Projekt “W”, this time with some stuff from behind the scenes (aka the code, mostly this will only be interesting for programmers) : You may remember the battle selection screen I’ve been showing off that’ll allow you to select if you want to battle it out yourself (on the hex-based battlefield) or if you want to have it simulated. One not-so-easy part in terms of coding was to implement this for when the AI attacks a human region. The AI itself is placed in it’s own unit (ProjektWeltherrscher_AI.pas) and has several procedures and functions for doing construction, army management and so on. As with most AIs out there, the one in Projekt “W” is using a lot of loops (and is basically a finite state-machine) and within one of those loops it attacks enemy nations. In “Phase 1” there was no problem as it would only have to simulate the battle and output a message to the player’s message log. But in “Phase 2” the player should be able to choose whether to fight manually or to simulate the battle, even if he is attacked by the AI (and not only when the player himself is attacking a region), which meant that I somehow had to add a way for the AI to change to the battle selection screen without breaking out of the AI’s loop. But this AI class is now used by the game’s main class (located in ProjektWeltherrscher_Global.pas), which means I can’t access the game’s class from the AI’s unit (this would be a circular reference, something not allowed within Pascal/Delphi), but I didn’t want to sacrifice my clean project structure by just moving the whole AI class into that unit in order to be able to access the game’s class from the AI. So after a lot of thoughts on how to deal with this, I decided to go for a simple callback function. Most programmers should know what a callback is, it’s a function that is declared like a variable which can be assigned. So now the AI class has a callback that is assigned from the game’s class (remember, the game class can assign the AI class, but not otherwise) and that get’s called whenever the AI attacks a human-controlled region. That function now switches to the battle selection screen, waits for the player’s choice and then opts out to give control back to the AI loop. It’s easily implemented, but not often very obvious and a lot of programmers get headaches on how to solve such circular references, so hopefully this will help one or two of you guys out there!