Pages

Thursday, December 17, 2020

Ancient Star - phase one complete

Diplomacy, vision range, and survival mode are implemented. This concludes phase one of the project where all major game features are implemented in at least rudimentary form. Two weeks ago I wasn't joking about the phase getting nearly over.

Once you get the other player (ship or colony) in your vision range the diplomatic contact is established. From that point, both parties can select the desired relation toward each other. Relations are war, peace, and alliance and the effective one is the worst one the involved parties have selected. If one side has selected peace and the other side wants alliance then the peace will be in effect. So war is the easiest to declare while the alliance requires the will of both sides to ally.

By default, players are at peace and it takes a declaration of war to be able to do any combat action. For now, alliances don't force any relations and military action to third parties. They are purely a peaceful way to end the game. Once every player is in an alliance with each other, the game ends. It sounds cheap but remember, there is a ranking system involved and not everyone will want to end the game while they can still improve their standing.

Once the game ends the player is rewarded with qubits and has an option to start survival mode. Yup, there is a premium currency in the game, and I promise to play nice with it. In the survival mode players fight increasingly stronger waves of enemies coming outside of the map and the goal is to stay alive as long as possible. Also, in this mode qubits can be spent on additional bonuses. For now, the bonuses are bigger industry, ship attack, and ship defense multipliers per technology level.

The next step is phase two, of course :). In the second phase, I'll work on improving the quality of the game, do the preparation work for publication on Google's Play Store, and at the end of the phase have the game available for beta testing.

Friday, December 4, 2020

Ancient Star - basic AI and news screen

With AI infrastructure and news screen, phase one (basic feature implementation) of the project is getting very close to being completed.

Having calculations run in the background and affect UI at the end turned out to be very simple. So now there is AI that controls "bot" players and plays them all in parallel in the background. It has very basic logic for now: build scouts, visit unscouted stars, build colony ships, and colonize everything available. In the future, the logic will be more elaborate and goal oriented.

This required some changes to the code structure. Controller classes players use to read and manipulate the game state have been moved from UI to game core subproject (where game data and game logic is) so in theory, AI can be coded without being a part of an Android application. And the other change was to how a turn is ended. So far the human player had absolute control over the matter but now each player marks their turn as ended. The next turn is processed when all players have ended the turn.

When a certain portion of the map is colonized news screen triggers, informing all players about the event.
 

Again, a simple-looking feature that had more going on under the hood. Now there is a proper concept of player events, uniting tech advances and news items. On a new turn, UI runs through the list of new events, switches to relevant screens, and moves to the galaxy map once all events are cleared.

Monday, November 30, 2020

Ancient Star - autosaving, money, Orion?

The feature "to do" list is getting smaller and smaller. This week three features got implemented: a special star, monetary colony stimulation, and autosaving and continuing a game.

The reason why the game is named the Ancient Star is that there is a special star on a map (for now in the center) which holds remnants of an ancient civilization. Colonizing that star will grant a considerable research bonus to the owner and will be the center of a conflict after the end of a normal game. There is more foundation for future work there, all stars can have a trait and "ancient" is only one of them. In the future there will be more traits, affecting ship movement and colony productivity. I'll come back to this after I implements movement range limits.

Next feature this week: money. Money is gained passively from the population working in factories and can be spent on multiplying colony productivity (both industry and research). For now, numbers are 0.2 credits income per manned factory, and spending 1 credit yields the same amount of industry and research as 1 unit of the population would produce. Money doesn't improve ancient ruins bonus and research during construction. Initially, money can only double colony output but each point of sociology tech improves that multiplier by 10%, exponentially. So later on stimulation can seriously jump-start fledgling colonies. Also stimulating multiple colonies without big enough cash reserve will spend whatever cash there is (tax income + cash reserve) equally over all stimulus receiving colonies. So if you stimulate all of your colonies you'd get a 20% boost.

And finally, I've recovered from serialization burn out and integrated the thing with the rest of the game. Now the game will autosave when you navigate away from the galaxy screen or the game app as a whole. When the autosave file is there, the game can be continued later on.


Friday, November 20, 2020

Ancient Star - game over

Now that there are means to end the game (bombardment and ground combat) it is a good time to make the ending itself.

Many 4X games are about the journey then the destination and some of them tend to have no fanfare at the end because of it. This bugs me more than it should, I like to finish all my games and the lack of acknowledgment at the end feels unsatisfying. That's why I've made it this "early" in my project. It also makes me think more about the overarching question in game design: what is the goal? Usually, 4X games have victory conditions where there can be only one winner, and that in my opinion creates a lot of game design problems. Mainly, if you win by eliminating everyone then the end game is one interesting conflict followed by a long and repetitive mop-up phase. If there are multiple victory conditions then you are likely to get a situation where everyone is playing almost a different game that abruptly ends when someone else reaches their goal.

In the image above you can see players ranked by some score (1, a mock value). Meaning I'm experimenting with something different, instead of trying to be the only winner, players are trying to be ranked as high as possible. I'm also pondering the idea of having a score that doesn't feed directly into military power to have some opportunity cost of being higher ranked. I made a similar system in the Stareater where you directly "sacrifice" your colonies for the score but since the game is not finished yet I still don't know the real downsides to it and I want something less extreme in this game. At first, I thought of using the population as a score but when someone gets eliminated, their population will be zero or, depending on when elimination counts, some low circumstantial value. Also, the population is a direct indicator of economic strength and to an extent military potential. So I thought why not research points? They are the closest to representing the art and culture of a civilization, they are accumulating value so they can't be taken away, and counter-intuitively, having a lot of research doesn't directly indicate a strong military or economy. Heavy research is an investment that trades "now" for "later" and makes you vulnerable in the meantime. 

Anyway, nothing is set in stone yet and a mock score of 1 will stay for a while :).

Thursday, November 19, 2020

Ancient Star - ground combat

I'm back to adding features to the Ancient Star, and ground combat is done. Including bombardment and invasion controls UI.

It was a simple feature and I was saving it up when I get burned up with the serialization business. Numbers, for now, are straightforward, each troopship carries one ground combat unit, colony defenders grow by one unit every turn, up to population limit. Combat itself is similar to space combat but with troop attack and defense values being the same.

Saturday, November 14, 2020

Ancient Star - serialization

The nice convention about mobile applications is that you can turn them "off" at any moment and continue where you've left off later. Yeah, some apps don't work that way but developers are generally encouraged to make apps tolerant to being paused and resumed at any moment. In order to pull this off in the Ancient Star I need a solid system for saving and loading game data.

There are other things to do to make an app lifecycle aware (handle pausing, stopping, and resuming) but Android SDK does a very good job of covering the usual parts. Built-in UI components take care of themselves, custom components (like one where galaxy map is drawn) are fairly easy to make persistent and it's easy to move data around in a lifecycle aware manner. But in comparison getting game data into a format that can be written to a file and back is significantly more work. You might be fooled by built-in JSON converter and open source solutions that this is an already solved problem but I haven't found a solution with both low maintenance overhead and the ability to cope with complex data structures.

When serializing data there are two parts of the process, picking up data from objects and converting data. Think of it as answering "what" and "how" questions. Serializers like built-in Android one expect from app developer to answer "what" question so the code ends up handling the same piece of an object in three different places: declaration, serialization, and deserialization. This incurs considerable code maintenance overhead. Whenever you add a new data member to an object, you have to remember to include it in serialization and deserialization functions. Forgetting to do so is still legal code, the compiler will not complain about it and the app might run for a good while until the issue becomes apparent. And even then it's not trivial to figure out which member did have you forgotten to serialize or deserialize. Better libraries ask you only to put a special annotation next to member declaration so it is very easy to keep serialization coverage in sync with the actual object structure.

As long the structure is simple (tree). Such serializers work by dereferencing each reference and embedding values behind it inside the object that held the reference. So if there is an object referenced by multiple objects its data will get serialized multiple times, producing unnecessary data duplication in a save file, and what is worse, deserialization would not be able to deduplicate it, potentially producing a faulty game state. Cyclical references are even worse, they'll make a serializer run in an infinite loop. And it's easy to have data with such structures. For instance, in the Ancient Star, each Star object can have a reference to a Colony object, Colony has a reference to a Player who owns it and the Player has a list of scouted Stars. That's an example of both a cycle and multiple references to the same Player object since each colony references its owner. It is possible to swap direct references with indirect ones and make data simpler in the eyes of a serializer but it comes with the price of more complicated code. And besides, in the Stareater I did develop a serializer that both utilizes annotations and can work with complex reference networks.

The first "trick" I used there is to have the serializer make indirect references out of real ones. It generates a unique "name" for each object and references are substituted with those names. The second "trick" was to gradually build a reference network while deserializing, similar to how in the normal course of the game the complexity of data gradually increases. For instance, initially, stars don't have colonies, are not scouted, and during the game each player scouts and colonize more and more stars. Similarly, the deserializer can first create objects with only bare necessary data (primitives and references required by a constructor) and fill them with remaining data in the second pass. So how long it took to port the code from the Stareater? 30% of the total development time so far!

I expected it would take some time because I wanted to learn and use Java's annotation processor stack for code generation but I expected it to take half as much. Stareater is written in C# and runs on .Net (CRL actually) while Ancient Star runs in Java Virtual Machine (or something close to it). Certain metadata (generic parameters) which is available in CRL is not available in JVM and Stareater code depends on it. I didn't know that until I ported most of the code and give it a spin. I had to scrap and rebuild the serialization code two more times until I arrived at a workable solution. It was a frustrating road but I'm glad I have done it. It will pay off in the future.

Monday, November 9, 2020

Ancient Star - introduction


Wouldn't it be awesome to have a 4X game on a phone? Now that I mention it, yes? Then I recommend Uciana, it's worth the price. It's so easy to turn on while on break, play a turn or ten, turn it off, and continue later. Do you need more such games? Well, Ancient Star is going to be one.

The ambition level for the Ancient Star project is to make a simple game, akin to Master of Orion 1, but unlike Stareater, to have a complete product. Published by the end of the year, with working AI and multiplayer. That's right, completed, and published in two months. Or at least have a beta version by then. I've been developing it for two months already and about 75% of core game logic is finished. When the app as a whole is considered (UI polish, graphics, writing, AI, multiplayer, tests, publishing), the completion level is about 45%. Here is how looks at the moment:

Galaxy map functions similar to Google Maps map, pan by dragging with one finger, zoom by pinching with two fingers, tap to get information about an object in the panel at the bottom. Colony management is a simple focus setting and a building queue. Features implemented so far:

  • Colony development
  • Ship construction
  • Fleet movement
  • Colonization
  • Space combat
  • Bombardment
  • Turn reports

For now, graphics are minimal, either stock Android SDK images or basic shapes, UI is not styled, and so on. The idea is to get core game features in and then work on polish and visuals. Hopefully, that second phase will come soon, at the end of this month. Stay tuned for more development news about Ancient Star on this blog.