Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Making A Turn-based Tactics Advanced Wars-like Game  (Read 4259 times)

bahihs

  • Bay Watcher
    • View Profile
Making A Turn-based Tactics Advanced Wars-like Game
« on: May 15, 2015, 07:45:58 pm »

Greetings forum dwellers,

Recently I've had a sudden need/desire to learn/re-learn python.

First some background (skip if you want): I'm not a programmer by any means, but I'm trying to learn as much as I can. I took an introductory python course at my uni sometime (2 years?) ago, it was an easy class with a rather unorthodox professor (all lectures were in document form and we spent all the class time reading said lectures and doing "programming tests"). I remember a lot of the general concepts (controls structures, looping, variables, OO programming etc.) but not so much the actual syntax. I've also taken a class in Perl, with more or less the same situation as above.

Now, I'd really like to consolidate that understanding and really dig my teeth into the syntax of a language. Python is used widely, and specifically in scientific research (which is where I'm aiming) and I already know a little, so I've chose it as the language to focus on.

Now for the interesting part.

Point of this thread:

Reading through several of the threads here and elsewhere, there seems to be one immutable truth: you learn programming like you learn an instrument, by doing. So I've decided to build a simple computer game, one that I've always wanted to play but have never been able to find in the market. I've written enough code to get it to the "minimal viable product" stage (at least I think have) and I'd like to share it here. I'd love some feedback and help both in the programming (especially in the programming) and the game itself.

The Game

The game is called "Strategos" and its your basic turn-based tactics game. Its in the same vein as Advanced Wars but without any base-building mechanics (in that sense its closer to Fire Emblem) and dealing with medieval/ancient era warfare rather than modern war. It's also a bit more detailed than advanced wars, mixing in ideas from the Total War franchise, like morale and fatigue. Finally its completely ASCII.

Right now the immediate goal is to get the game to a state where one can play hotseat multiplayer. Eventually I hope to build a competent AI that the player can skirmish against, and even more eventually, campaigns based on the lives of real-life generals (Alexander, Caesar, Hannibal etc.). Here is a list of features I hope to eventually have:
Spoiler: Feature List (click to show/hide)

So what do you guys think? Am I biting off too much?

What I have so far:

So, as I've said above, the game is at the "minimal viable product" phase. Right now the program generates a (very) sparse map with two teams with 3 units in one team and 2 in the other. The units can move, have varying movement and attack ranges, can attack each other, can kill each other. There is a turn mechanic in place, so that you can actually play a little hotseat if you are so inclined. The gui is very mouse-friendly: hovering the cursor over a unit shows some info, clicking on units allows you to move and attack with it. Turns can be ended by pressing the <ENTER> key. All in all, I've tried to make the controls as intuitive as possible.

I also have the major stats for each unit worked out, however the only stat that does anything right now is the "unit size" which is basically the HP of each unit and the "power" which determines how much damage the unit can do.

Right now, I'm working on implementing the rest of the stats: morale and fatigue (discussed above) after that I'll be working on generating units in bulk and then random generation of the map and implementation of the terrain. At that point I will have reached my goal of making the hotseat fully playable and will decide whether to continue the game or not.

If you want to take a look at the code look at the next post (I'll be periodically updating that post with the code as I finish certain things). I don't have an executable yet so the only to play it is to compile and run.
« Last Edit: May 15, 2015, 07:48:27 pm by bahihs »
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Game
« Reply #1 on: May 15, 2015, 07:47:07 pm »

Spoiler: The Code (click to show/hide)
« Last Edit: May 25, 2015, 06:59:49 pm by bahihs »
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Game
« Reply #2 on: May 15, 2015, 07:47:56 pm »

Btw, how I do have the code show in a reasonably sized window? It's like a thin sliver, I can barely see the text inside.
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #3 on: May 16, 2015, 09:43:39 pm »

Updated the code.

Added:

  • Fatigue system: So the fatigue system is brutally simple. There is an invisible counter which keeps track of the number of squares a unit has moved in a turn, then based on that count, a proportional amount is deducted from the fatigue counter (which ranges from 0 - infinity, but after 100 has no additional effects). The fatigue counter in turn affects morale (more on that in just a bit) and will eventually affect power (next on to-do list)
  • Morale system: The morale system is a tad more complex. Basically I wanted a realistic simulation of morale by taking into account as many factors as possible. So far I have:
    • Units in sight, either ally or enemy will affect morale
    • Units that are adjacent to you, either enemy or ally will affect morale; in the case of multiple enemies adjacent to a unit, said unit is "flanked" and takes an additonal hit to morale
    • Local superiority (the ratio of allies to enemies adjacent to you; considers the total unit size on both sides) affects morale, both positively (if you outnumber the opponent) and negatively (if he outnumbers you) and proportional to the degree of difference (2:1 gives a bigger bonus/penalty than 1.5:1). This also means that losing units from attacks will lower morale.
    • Fatigue; tired units take morale hits


    There is still a lot left to consider (terrain, types of the nearby units, veterancy, etc.) but those will be added when the pre-req for each is done. Morale works by doing a simple check against the current morale value, if the morale value is higher nothing happens, if lower, then the unit is in a disordered state and cannot take orders this turn (basically its frozen in place for the turn). The morale value works more or less like a percentage, the higher it is the more likely the unit is to obey orders this turn. You can still get lucky of course (or unlucky) but the system balances itself out nicely

Next up is the (basic) implementation of power and then I get into either map generation or exp. It's amazing how accomplishing these little goals is leading to definite (and surprisingly fast) progress.

Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #4 on: May 16, 2015, 10:01:49 pm »

Here's some screenshots for the curious:

Spoiler: Screenshots (click to show/hide)
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #5 on: May 17, 2015, 08:04:24 pm »

Updated the code again.

List of changes:

  • Fixed up some of the old code, especially morale and attacks which were apparently very bugged. Also messed around with the numbers for everything to get some realistic starting values for each of the stats. More play testing is going to have to be done for balance. But that comes later.
  • Power system
    • Power is the amount of "damage" one unit can do to another. It's a measure of the effective fighting force of each unit.
    • There is a base power multiplier which is unique per type of unit (e.g Cavalry have a higher power multiplier than infantry) and will eventually vary by unit experience
    • Power is calculated by taking the multiplier (which is sensitive to morale and fatigue among other things) and multiplying it by the unit size. As you have less units, your power goes down. Simple.
    • Power varies by morale and fatigue; in the case of morale, power will increase if morale is very high and decrease once moral gets below 50 (Steady). The rates of the variability need to be play-tested and balanced.
    • There is still alot left regarding power, such as unit types (spearmen vs cavalry and cavalry vs archers etc.), terrain, unit experience, weapon quality, etc. but will have to wait until after I finish map generation
  • Next up is what I've been waiting for (and need serious help with) map generation! There is going to be several types of terrain: forests, rivers, mountains, hills, and plains, with varying effects. I also intend to simulate weather and temperature which will have a direct effect on morale and fatigue (this is much later though). Right now I'm trying to learn as much as I can about procedural generation, but materials for outdoor map making are sadly sparse. If I can't manage random generation I might just go ahead and make a couple of maps by hand. It would be better than nothing.

Anyway, the game is actually in a moderately playable state right now (albiet with a sparse map). More units can easily be added to the maps by creating instances of the Unit class at the bottom and adding these instances to the team lists. If anyone actually wants to play, please tell me and I can update the code with a decent size army for both sides (or maybe a historical battle?) so its interesting.
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #6 on: May 17, 2015, 09:38:02 pm »

Alright guys, so I need some major help building this map generation code. Does anyone have any advice/materials/resources I can take a look at? Googling has only gotten me dungeon and city generators, which although very cool, are not what i'm looking for.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #7 on: May 17, 2015, 11:36:25 pm »

I don't have any particular articles, but if you google "Perlin noise", it should give you lots of helpful stuff for map generation.

The world needs more Advance-Wars style games.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #8 on: May 18, 2015, 06:44:46 pm »

Thanks Levi, I found some interesting articles but it will take me time to figure everything out, alot of this is out of my depth but its all very interesting!

I am wondering if should skip map gen for now though and work on something else...
Logged

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #9 on: May 20, 2015, 12:06:04 pm »

This and this were the two things I used to get my head around simplex noise, but I think they're both for Java. You might be able to pull out the concepts and adapt the implementations for Python, though.

Good luck!
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #10 on: May 20, 2015, 08:39:06 pm »

With the help of the infinitely gracious breadman (in the self.isCoder thread) I managed to generate some basic height-maps with noise. It's not even close to where I want it yet, of course, but that should be fixed with generous tweaking of the various functions. The main problem was relating the map generation with the noise and that has been fixed (thanks again to breadman). There is a future problem: the path-finding code is currently broken since it depended on how the map was built previously, but hopefully I'll noodle that out later. 

For now, I'm so excited with the possibilities that I'm getting hives! Here are some screenshots of the maps:

Spoiler: Pretty Maps! (click to show/hide)

As you can see they are quite far from the types of maps I want to generate, (they are too zoomed in for one) but I'm hoping that tweaking the noise function will lead to what I need. If any one has any advice please do post.

The types of maps I wish to generate are the ones you might see in the Total War franchise with an interesting mix of hills, forests and the occasional river.
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #11 on: May 20, 2015, 08:40:19 pm »

This and this were the two things I used to get my head around simplex noise, but I think they're both for Java. You might be able to pull out the concepts and adapt the implementations for Python, though.

Good luck!

Thanks! I'm going to check these out when I have the time. The explanation of Simplex noise is something I've been especially looking for (since its the one libtcod uses primarily for noise generation). 
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #12 on: May 21, 2015, 01:13:10 pm »

So after some tweaking I'm getting some decent looking maps (see screenshots below). I still want to zoom the map out a little though (I've also made the screen 25% bigger, which I planned on doing anyway) it seems a bit too close up for my tastes. I don't know. What do you guys think?

Spoiler: Prettier Maps! (click to show/hide)

Now, none of this has been formalized into discrete structures (I'm still playing with the functions and trying to understand their parameters), but once they are, the user will be able to choose the type of map they wish to generate from the given archetypes (desert, forest, etc.). Eventually when (if) a world map is implemented, the maps will be generated based on the position and surroundings of the world map tile, similar to DF.

I am wondering if I should formalize what I already have so far, or delve deeper and try to get exactly the types of maps I'm looking for. Voronoi maps seem to be interesting, but I don't know how to use them. Libtcod has a Voronoi function built in (though according to some stuff I've read its not exactly a "Voronoi" transform) but using it only results in a "hole" in the center of the screen.

One long voyage ended, only begins a second; and a second ended, only begins a third, and so on, for ever and for aye. Such is the endlessness, yea, the intolerableness of all earthly effort!
Logged

bahihs

  • Bay Watcher
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #13 on: May 21, 2015, 09:31:21 pm »

So the everything has been formalized into semi-discrete structures (there is still a bit I need to fix, but it should do for now). I also fixed a bug with the Morale System where a unit's morale would be shattered whenever it moved next to any enemy unit (both the unit itself, and the enemy oddly enough).

Now that I've come this far, there are couple of things I really need to think about in terms of game design. I've been looking through some old wargaming rulesets online (with miniatures and such) and, although I've never played a wargame tabletop myself, I feel like a lot of the ideas could be incorporated into the game. This ruleset in particular has introduced me to some interesting ideas, such as commanders for every unit.

There is also the matter of re-doing the movement system to account for terrain penalties. Here I'm currently debating whether I should create a movement point system (where certain terrain costs more points to cross), this was my original plan, however I don't know if the libtcod pathfinding algorithm can account for different costs for tiles (then again I haven't looked toi deeply at it yet). The other plan is to eliminate movement range completely and replace it with fatigue. Then each unit can move as far as its fatigue takes it, however I feel this breaks the turn-based nature of the game and destroys the sense of time and progression, especially when a unit can bolt across the map in a single turn (and get exhausted, sure, but that shouldn't happen in one turn). I'm really leaning toward the former.

I'm also thinking about ramping up the level of simulation for attacks. Currently its just a RNG taking into account only unit size and an attack multiplier, but maybe I can make something much more robust, say at the level of each individual in the unit. On the other hand, would this really add anything more than what the RNG already gives? Perhaps it makes it more universal? It would allow me to incorporate the commander for every unit, I mentioned above; but I could probably do that with an RNG as well. I don't know.

What do you think?
Logged

FallacyofUrist

  • Bay Watcher
  • Blatant furry. Also a hypnotist.
    • View Profile
Re: Making A Turn-based Tactics Advanced Wars-like Game
« Reply #14 on: May 24, 2015, 05:40:17 pm »

Hmm... hm. About the commander, one thing that seems to be universal in these sorts of games is that the player can see from the perspective of all their units. Changing that would make your game unique and fresh in comparison. Which brings to mind a day-night cycle and weathers...  hm.
Logged
FoU has some twisted role ideas. Screw second-guessing this mechanical garbage spaghetti, I'm basing everything on reads and visible daytime behaviour.

Would you like to play a game of Mafia? The subforum is always open to new players.
Pages: [1] 2