Contents Back |
Appendix C: Miscellaneous functions |
C.1 List of general purpose functions implemented in library There are a couple of functions I've implemented in CSPL which are not strictly related to a game entity (like units or cities and so on), so I don't know where to put their description. I think this appendix is perfect.. I used all these functions in the examples seen in previous chapters, so here's the complete list:
void EmulateKey(char r)This function is used to send virtual keypresses to ToT:If you call EmulateKey('c') then ToT will receive a message from
Windows as if the user has pressed the 'c' key.This can be useful in some situations, for example to force the user to change production in a city by emulating the c(hange) keypress in the city screen. void Refresh()This function emulates a screen refresh:Often changes in ToT memory are not reflected on screen until the screen is repainted. This function usually will force ToT to repaint the screen by emulating a 'c' keypress (in that sense it is equal to EmulateKey('c') ).Unfortunately, since when the city screen is activated the 'c' key means Change and not Center, it cannot be called with the City screen opened. void RefreshMap()This function is a "heavier" version of Refresh(), because Refresh fails to work correctly when CSPL moves a unit from one map to another:In those situations RefreshMap() tries to solve the problem by emulating the following sequence of keypresses: 'c' 'v' 'v'. This is what that does: When ToT receives the 'c' keypress, it centers the current map on the unit coordinates (x,y) but that is the wrong map since CSPL moved the unit to another map. Then when the 'v' key is received the current unit is de-selected and finally, when the last 'v' keypress is received our unit should be re-selected. When ToT re-selects the unit it notices that it's on the wrong map and switches to the correct one. Probably there will be some occasional annoyances, such as when a friendly unit is located on the wrong map at the same (x,y) coordinates as our unit (because that unit will now be selected instead of the moved one), but it will not crash ToT and this is enough for version 1.0. |