srijeda, 24. veljače 2016.

Hex grid


At last something visible in space combat! Well, by the time I finish this post it might be complete :). Boring stuff first, some more ground work had to be done in order to trigger space battle for right player at the right time. The way how battle events are pushed to GUI had to be more strictly defined and there were some changes in AI handling. Then there was also a question of how to organize ongoing battle data. I started with what there was in CroVar version and after some experimentation I ended up with game within the game structure. Space combat is going to have similar model-view-controller pattern as the main "galaxy" game and will not be entirely stuck inside the main game. It would pop in to existence, run as separate entity and feed the results to the main game.

Now fun stuff, image above is how game looked on paper a year ago. I've been thinking about space combat for a long time, I've decided to abandon one dimensional simplification from CroVar and do proper 2D tactical TBS. And while I'm at it I could do it on hexagons. Math is slightly more complex then it is for square grid but only slightly and there are few tricks for representing hex grid in memory in a same way as square grid. Image below is how it looks like at the moment, a grid, a star, a defender near the star and an attacker's fleet on the edge (exact location deduced from the direction it came from).


More coming soon!

nedjelja, 31. siječnja 2016.

Preparing space combat

On a way to implement space combat I have implemented conflict detection logic and unstubbed some parts of the game. Conflict detection is a mechanism for finding where and when space battle happens. Under the hood a fleet can have multiple waypoints and with advanced enough interstellar drive it can pass through multiple star systems in a same turn. If one of them happens to have an enemy presence, space battle happens and the fleet ends it's turn there. When the conflict begins is also important, it influences a turn limitation. If at the end of player's turn a fleet was 1 light year away from destination, traveled at the speed of 2 ly/turn and battle happened there then it would have 50% of maximum combat turns to resolve the fight. In case the battle doesn't end by then I plan to make persistent battles which can span multiple galaxy turns. I also thought about making a mechanism where a quick enough fleet can fight in multiple systems. For instance if a fleet finishes one battle quickly and is fast enough to travel to next star system it would be able to fight a few more turns there too. The problem is int that case conflicts wouldn't be isolated and players wouldn't be able to play each conflict to the end before moving on to the next one. It might work by making players play all space battles simultaneously, one turn at the time but that doesn't sound like fun. So I'll go with one battle per fleet per turn limitation and keep the idea in the drawer :). There is also a question of what to do with colony ships that retreated from the battle, do they try to reach a marked planet or do they go home and do what exactly? I'll cross that bridge when I come to it.

Next step toward space battles was making AI build ships so a player can have somebody to attack. In order to implement that I had to change how the game rotates players during the turn. So far I had a "current player" number and only one player could interact with a "game core" at the time. On the other hand AI was supposed to do it's work in the background. Since both AI and human player used the same means of communicating with the game core AI could only manipulate the empire of current human player so for a brief moment there was an AI which filled my building queues with random stuff :). To make AI independent I tossed the concept of the current player out of the core so from the it's perspective everybody is playing simultaneously and it is up to a user interface to worry about who has the turn. Interesting consequence of it is that Stareater is now very close to having hot-seat multiplayer.

utorak, 19. siječnja 2016.

Works on my machine

Every time I make Stareater release I find a new program breaking bug. Not just game breaking like improper behaviour of the game but bug that completely crashes the game's executable. Previous release turned out to be no different despite my effort.

Truth to be told I don't have much in a way of release procedure, there are no automated tests, nor alpha, beta and release candidate testing periods. Heck, there is not much in a way of installation package either, just zipped folder. But I do try to check by hand if the zipped stuff works at all before uploading it. And guess what, it did work on my machine. It also worked on the other machine I sometimes use for developing the project. I asked a friend to test it on his computer but Christmas was near, I couldn't wait so I uploaded it anyway. Couple of weeks later I met with him brought the topic up and he gave it a try. Main window appeared over the whole screen but main menu was not there. Second or two later the program crashed with only the most basic and generic "Application crashed unexpectedly" error message.


That puzzled me because I specifically made a logic for trapping run-time errors and displaying the error details in a manner which reasonably competent user could report to developers (me). Since there was no such error message I had to reproduce the problem in the environment where I have some debugging tools. Guess what, I could reproduce it on my own computer on which it worked before upload. Trick was to download a zip file from the Internet, not use the one I uploaded. No, it was not the case of GitHub or SourceForge (for some reason GitHub hosts Stareater releases there despite SoruceForge's shady recent history) injecting something in my file but the case of Windows not trusting downloaded files and .Net security. Such circumstances made the Stareater to reject loading DLLs for AI logic and map generator. These DLLs can be replaced by mods so they are not exactly known to the Stareater's EXE in advance and not trusted because of it. To be honest I'm not the best informed about security surrounding untrusted code but I've been educating myself on one previous projects and it turned out Mono doesn't support it. If I remember correctly Mono simply ignores security related functions, doesn't explode with errors but as we wanted to sandbox 3rd party code we dropped the concept and moved to something else. In the future I could spend more time researching the topic and make some sort of DLL trust checking but for now I'll just allow all.

Sorry for inconvenience, next build will be available when some visible part of space combats is implemented. Or sooner if there is an interest.

ponedjeljak, 28. prosinca 2015.

Preview release v0.4.2

Finally the project has reached some presentable level. It's still rough around the edges, not too user friendly but if you want to see for yourself where Stareater stands, here is a downloadable package.

Download Stareater v0.4.2

Package is a simple zip file, extract it and start Stareater.exe. Since it's .Net application under the hood it should work on Windows out of the box. If you have really old windows machine then you might have to install .Net 4.0 framework. The game should also work on Linux and Mac with Mono. Please report any issue you encounter either in the comment section on this blog or at GitHub. Especially if you encounter graphical bug where objects seam to be drawn in wrong order like star names below wormholes.

Have fun!

srijeda, 16. prosinca 2015.

Colonization

As you might have guessed from previous posts, colonization has been implemented. Like some other features it was not a direct translation from CroVar iteration. In CroVar version colonization followed traditional Master of Orion I steps: bring a colony ship to a star system and land it on an empty planet. Additionally you could bring multiple colony ships and choose how many will land on which planet. Multiple ships on the same planet would establish a bigger colony. This is how the GUI for it looked:

Planets in the system are on the left side, information about a selected planet and estimated productivity are on the right side and a number of ships to land is selected with a slider below it. At first I thought about doing the same in this iteration but certain discussion on Wargaming's Master of Orion forum nudged me to think about other possibilities. In Master of Orion II there was a way to arrange colonization from a planet list. There was a screen with a list of planets which could be filtered and sorted by quality and size. Once you've decided which planet was the best candidate you could select it and press a "colonize" button. If you had available colony ships the game would direct a nearest one to the planet's star system and following turns the ship would fly there and land. Now don't kill me for bringing Master of Orion III up, that game went one step further in not necessarily bad way. There you could zoom in to a star system, mark planets for colonization and your unquenchable AI viceroy would build needed colony ships and send them to the planets.


I've decided to do something similar in the Stareater. Marking an empty planet for colonization creates a colonization project and on colonization screen you can decide which star system will build colony ships for which planet. Once built, colony ships will fly toward to planet and wait until there is enough of them. When minimum population has been accumulated, a colony is established.




GUI could use more work but that would be a job for another time. I've been looking around and there is an interesting GUI library for OpenGL, it's not so well maintained but I'll keep it in mind for that sunny day when I'll be converting Windows forms GUI to OpenGL. Now next on the menu: space battles!

petak, 11. prosinca 2015.

Stareater iterations

Before I move to the next topic I'd like to make a little intermission. Stareater is long running project, it's about 7 years old and yeah, still not done. I admit I have taken on very ambitious goal back then but instead of giving up when things got over my head I have started over. If you have been following this blog you'd noticed just that, the current programming effort is a rewrite of the previous iteration. What might have been lost to time is the fact that there has been one before that. Below is a short description of each iteration and names I made up just now so I can refer to them in future posts: 
  • DIY or "do it yourself" was the very first incarnation of the Stareater where I have literately went by coding everything myself in C++. Only "others" work I took was OpenGL for graphics and GLUT for "windowing" (how application window is started and managed) and mouse and keyboard input. Unfortunately such ambition had to hit a brick wall somewhere and it was in GUI department. Making GUI engine from scratch is science for itself and I've spent more time on it then making an actual game. Since I didn't take robust enough approach it got really tiresome. DIY iteration ended with pretty beautiful galaxy map (stars only, no planets), map navigation and minimal GUI for starting the game.
  • CroVar or "Croatian variables" began as GUI mockup project for DIY iteration. It was C# Windows Forms project and at some point I realized I'd be happier to spend more time on game logic and keep GUI effort to a minimum. So I filled in mockups with a actual game logic from DIY and somewhere along the line I've decided to use Croatian words for class and variable names. That's why I'd call this version CroVar. This iteration got pretty far, stars, planets and colonies were fully functional, planets could be colonized, ships could be designed, built and moved, foundation for AI was laid down and even space battles worked!
  • WhyNot is the current iteration of the Stareater. At some point CroVar code got big enough mess to consider refactoring it. At first wanted only to make better separation of GUI logic and game logic but I figured I could fix many other wrong decisions made in CroVar. And it resulted in a total rewrite with good amount of why not this too additions? In all seriousness "why not" approach saved me a lot more trouble than it has brought me and it improved the quality of the code and final product. Mod files got more intuitive format, OpenGL graphics are back, it got easier to code new features and simplified changing and maintaining old features.

utorak, 24. studenoga 2015.

Fleet movement

Next feature on the completed list was fleet movement. Well sort of completed because it was refactored while doing colonization (more about it next time) and there is an open question of how to propagate information about multiple missions to GUI.

Let me start from the beginning, in the last iteration of the project I made two collections for fleets, one for stationary and the other for moving fleets. Reasons were difference in data structure, moving ones have current, start and destination positions while stationary only have current position; in visualization, stationary fleet marker should appear next to the star instead in the center of it; and in some internal logic. In the current iteration I wanted to unify those two collections for easier handling and I did it by introducing the concept of fleet missions. I started by giving stationary fleets a "stationary" mission and moving fleets a "move" missions and while most parts got simpler, some were not in the best shape. With only two things fleet could do there was no need for spending more time on the topic.

That changed when implementation of colonization started. At first I started by making separate collection for colony ships but then I've realized it won't make stuff simpler. It worked well for colonizing within a star system but when it came to moving ships to remote stars I had to either duplicate the code of normal fleet movement or unify colonizers with regular fleets. Guess which path did I choose, more complicated one with better scalability. And on top of that I've pulled out visitor pattern. It was like climbing uphill a bit be rewarded with relaxing bike ride downhill. I've changed fleet data from having a single mission to having a list of missions which combined with visitor pattern led to simpler code, believe it or not. Missions themselves were changed, descriptor for "stationary" mission was removed, now fleets with empty mission list are considered stationary, "move" missions have reference to star lane they are using instead of starting star (which was used to deduce whether star lane was in use or not), "move" missions also have reference to only one destination instead of all waypoints (not yet implemented on GUI but planned for future) and "colonize" and "skip turn" missions were introduced. "Colonize" missions does what you'd expect, marks ships ready for landing and establishing a colony. "Skip turn" also does what the name says but the reason for introducing it was to prevent colony ships from having unfair advantage over normal ships by taking action on the same turn when they are built.

In the Stareater I aim for having strict rules about what happens when. Construction is an action that takes a whole turn so when a ship is built it should act as if it (or should I say "she", I find it weird to refer to ship as she, partly because it's inanimate genderless object and partly because in my first language and in German the ship is "he") has spent it's turn. Since colonies and stellarises (made up word for star system wide government) are processed before fleets and colony ships are built with non-empty list of missions, colony ship could colonize a planet within a system or move toward destination on the same turn it was built. Explicit "skip turn" mission was a way to prevent that.


Finishing fleet movement allowed for tackling more features. As you might have figured out colonization was next but it's worthy to mention that also brought me one step closer to implementing space combat. And I've decided to make it more interesting then it was in last iteration.