Turn Based Combat

Discussion pertaining to resources, stories/characters and gameplay ideas in this forum dedicated to games that are just a faint glow.
Forum rules
Do not create a topic offering to produce resources. Click here for the reason.

Please use above resources section of site so everyone can have access to the resources you create.
User avatar
evs
001 Admirer
 
Joined: Tue May 08, 2012 5:27 pm
Location: Perth, Australia

Re: Turn Based Combat

Postby evs » Sat Jul 16, 2016 12:47 am

i like that last idea Scaveleon mentioned. cheeky AI.
im using a mouse system, but with old school movement squares. i just ran into the problem of blocked tiles though.. which makes the pathfinding a bit more convoluted, should be fine but i now need to program extra to determine wether you can still get to a tile which is blocked by (beyond) a blocked tile. so Lucifiend are you still using square tiles? if not you could just generate a large circle, and wherever you click on the circle you could just move/shoot there. it works, but i like the squares better, more chesslike. a big advantage of the 'circle' system though is you dont have to use such blocky terrain, you could make it more seamless and modern. again, personally i like the blockiness myself

User avatar
Lucifiend
001 Subscriber
 
Joined: Wed Apr 22, 2009 7:37 am
Location: Layton, UT

Re: Turn Based Combat

Postby Lucifiend » Sat Jul 16, 2016 2:08 am

I'm sticking with the grid format. It can get a little wonky when fighting and moving diagonally but so far I've been able to work around it. My range indicating tiles can be a little laggy when it fires, but it doesn't feel overly long to me. Maybe 2 seconds to scan 100 tiles. I haven't been brave enough to bump it up to the max MP of 20 yet. Not sure if it will like that.

My list of player items yet to complete:
Equipment selection HUD
Combat HUD (next player/end turn and that kind of stuff)
Character HUD (shows stats and such)
Complete attack script (it's about 50% right now)

The only thing slowing me down at the moment is I need to polish some of the combat skills and advantages so I can wrap up the attack scripts. For now I'm not adding magic in because, well, I don't wanna.

[UPDATE]
After a few quick changes to how the game looks at movement, instead of rendering a giant blob of possible movement locations it just creates a single path pointing towards the cursor. There is a lot less clutter to decipher for the player and it runs much faster. I did this after finally taking the plunge and putting in the max movement range of 20. Yeah, things got ugly. I could only go up to 11 movement points before things fell apart. It was taking so long to calculate 001 kept thinking the script was stuck in a loop. It took three 'ignore loop' options to even complete the scan. Now I can crank it up to 20 and it doesn't even blink. Much happier with the results. I left the old video below for reference. Feel free to mock me for not doing this in the first place.


User avatar
evs
001 Admirer
 
Joined: Tue May 08, 2012 5:27 pm
Location: Perth, Australia

Re: Turn Based Combat

Postby evs » Mon Jul 18, 2016 1:02 am

well done mate, much more clean looking, and if it runs much smoother thats a huge bonus.
-or the other way around


im becoming quite envious of your pathfinder script. im doing fine on the ground, and even sorted out the problem of fences and such blocking the way (well testing my solution is going ok) having all sorts of problems going up ramps.. have you had any luck with that?
Last edited by evs on Fri Jul 22, 2016 9:47 am, edited 1 time in total.
Reason: Automatically merged double post.

User avatar
Lucifiend
001 Subscriber
 
Joined: Wed Apr 22, 2009 7:37 am
Location: Layton, UT

Re: Turn Based Combat

Postby Lucifiend » Thu Dec 01, 2016 1:38 am

So, after spending some time frustrated figuring out the AI for turn based, I think I'm ready to take another swing at it. There are just so many 'plays' you have to work through that I got lost in what to tackle first. Every little simple task requires tons of decisions that need to be solved. For example. Your AI has a bow. Just a few issues to work out:

Is the bow a good choice for that action? (Do they have a better chance at melee)
Can the AI see anyone to shoot?
If they can't see anyone, where do they move to see someone without putting them in harm's way?
What is the most optimal distance to fire the bow at a target?
Is the attacker drawing nearer? If so should they move back or switch to melee?

That was a scary list. I shouldn't have done that.

So...I have a dilemma. What is better: action points or movement points?

Action Points (AP): Each actor gets a set amount of actions per turn. So if they have 2 action points, they can move twice or move and attack or heal and move or attack and attack, etc.

Movement Points (MP): Each actor has a pool of points that they pay for their actions with. Say they have 10. Each move cost 1 point. Attacks can be 3-6 points depending on what it is. Switching items is 2. Casting a spell is 1-10 points. Etc.

I've gone back and forth on this all along. Originally I was using Movement Points, but it seems to be trickier to plan out your moves because you have to budget your actions. Where as Action Points is pretty straight forward. But Action Points are bulkier so it's harder to improve your attacks because a whole extra action point can be a major step. For example: If you can move 10 steps per AP, then you go from moving 20 steps a turn (2 AP) to 30 steps (3 AP)! That's a major jump. Whereas Movement Points you gain a Movement Point (say from 10 to 11) it might loosen up some options, but not as dramatically as a whole Action Point. So AP are easier to manage but MP has more gradient for change.

User avatar
evs
001 Admirer
 
Joined: Tue May 08, 2012 5:27 pm
Location: Perth, Australia

Re: Turn Based Combat

Postby evs » Fri Dec 02, 2016 11:48 pm

yeah, im getting back into this too, iv just given them Action Points AND Movement points, in general, these first low lvlers are getting 1 AP per turn and 2-3 Movement Points. i gave up for a while when i thought about Archer AI.. but iv come back renewed, i think it cant be that hard. assesing the situation between each step taken should help him stay in optimum range?

User avatar
Lucifiend
001 Subscriber
 
Joined: Wed Apr 22, 2009 7:37 am
Location: Layton, UT

Re: Turn Based Combat

Postby Lucifiend » Sat Dec 03, 2016 2:13 am

Great, now you've added a hybrid of the two different types to consider. Having moving and actions separate does free up some of the concerns I have about allowing a character to make multiple attacks. I was trying to think of a way that allows you to move well enough and still limits low level characters from having too many attacks available. I thought it would be better to unlock more attacks as a reward for advancing in skill. By making it a separate action, it might be easier to control each portion as completely different operations.

Originally I was coming up with a percentage system for the attacks to compensate for the large movement points vs limited attacks. It would have broke down sort of like (I'm totally just making stuff up here):
50% - Basic attack
100% - Power Attack
30% - Wild attack

As far as the AI, I'm still chewing through the battlefield evaluation scripts. This will assign scores to various courses of action based on the AI's observations. The enemy two steps away with a sword might be more of a threat than an archer 10 steps away, but the wizard might be an even greater risk. That way it can make somewhat logical deductions and react to what is going on around it. Right now I'm working on what kind of data it will need to make a decision. This will probably take some pen and paper to sort out. I've discovered bullying my way through writing AI ends in a tangled mess.

**Update Dec 7**

I spent some time pondering how the AI would assess their enemies and determine who to attack. The system I've got working right now looks at several aspects of each actor that is not on their team and scores each area. The scoring breaks down as follows:

Line of Sight: Can the AI see the actor being evaluated.
10 - points if they can see them
0 - points if they can't see them

Range: Drawing a straight line, how far is it to actor. For every 32 pixels away, subtract 1 from the starting score of 10.
10 pts for 1-32 pixels away. In other words, they are in melee range and an immediate concern.
9 pts for 33-64 pixels away.
8 pts for 65-96 pixels away.
...
1 pt for 289-320 pixels away.
0 pts for anything beyond because they are low threat

Move Distance: A quick movement scan is made to see how far it is for the AI to move to the actor being evaluated. This works exactly like range, but is based on the available movement points of the AI instead of a base score of 10. If the AI has a Prowess of 12, then the count down begins there.

Weapon Threat: I created a weapon scoring system that generates a score based on certain attributes of the weapon. Things such as range, damage, bonuses, magic powers etc or calculated in to create a "threat" score. This bit only looks at the current weapon the actor is wielding at the time. It doesn't snoop through their inventory to see if they might have something better in reserve. For example, a knife gets a threat score of 2 whereas a bow has a 12. The calculation looks like:
Weapon Range /32 + Damage Rating + Bonus to Hit + Magic Bonus + Add Dam Bonus
Knife: (Range 32) 1 pt + (Dam 1) 1 pt = 2 (It has no other ratable areas)
Bow: (Range 256) 8 pts + (Dam 4) 4 pts = 12 (It has no other ratable areas)

Armor Threat: The AI considers how well armored the enemy is. The more armor, the more problematic the actor would be I'd assume. Just like the weapon threat, armor threat looks at key points in the armor and assign value to them. The calculation looks like:
Average Armor Damage Reduction ((Slash+Bash+Puncture)/3) + Elemental Reductions ((Heat+Cold+Electrical)/3) + Magic Bonus

The nice thing is that if I change my mind on what needs to be evaluated, the entire thing is fairly modular. I have one area that I have plugged into the threat analysis but haven't assigned it anything to look at is magic ability. I haven't decided how magic will work, but once I do I have a placeholder for it already in the script. I'm assuming creature special abilities will play into the magic bit, but I haven't thought that far out. I want a hand full of humans to be able to work their way through a simulated battle on their own before I start worrying about broader strokes like that.

User avatar
evs
001 Admirer
 
Joined: Tue May 08, 2012 5:27 pm
Location: Perth, Australia

Re: Turn Based Combat

Postby evs » Fri Dec 09, 2016 1:19 am

thats just so indepth. wow.
i was just thinking of having an actor variable called 'target'. and different enemies would have a different type of friendly they like to target. i know in these games, i like to pick off the weak guys first, but i have a friend Hamed, who says its always best to gang up on the strongest guy. so 'evs' type AIs will target the lowest hp character, while a 'Hamed' type AI should attack the character with the highest strength stat, unless someone else is within swinging distance and he cant reach the first target.
i think your system is better thought out, and will be smarter, but will take more time (and cups of coffee) to program.
i hope you dont mind me airing my ideas comparing them to yours, you always seem to have a complex system and mine seem to be a basic sticky taped together kind of solution, but reading yours will probably help mine and perhaps vice versa.. it is your thread though.
so are you going to tie this system together with your comic book stuff? i think that would be a great way to tell the story in between battles. should be easy enough to put together some 3D models from your mechanical concepts too.. and they'd hardly need any poses at all (not that posing is hard to do, and it takes up extreemly little memory too from what iv seen. a kind of futristic wasteland battle tactics kinda game?

User avatar
Lucifiend
001 Subscriber
 
Joined: Wed Apr 22, 2009 7:37 am
Location: Layton, UT

Re: Turn Based Combat

Postby Lucifiend » Fri Dec 09, 2016 10:25 pm

Honestly it I had it up and running in one night. Most of the scripting was simple, it was the planning that was the hard part. I probably spent two or three nights planning out how all this would come together, but when I sat down to implement it everything went rather smoothly. I'm thinking about adding in a runner up enemy so that their will be some randomness to the AI selections. So there would be a number one pick to attack and possible a number two pick with a lesser chance of being attacked. This way the player can't always read what the AI will plan to do. I'm thinking that the number two pick has to be within close proximity of the first pick. This way I don't have an AI charging after some actor way in the back instead of the two a couple of steps in front of it.

So right now, I have the ability to select a target, move within attack range and determine if they were able to hit the target. I'm really close to being able to have 100% AI controlled battle royal. My goal is to have something up and running by the end of this weekend. It's nice being on a TDY (temporary duty) for 90 days. I have a whole lot of downtime.

This script below might be a little hard to follow because I call in a lot of external custom scripts so I don't have to build the same operation over and over (such as Line Of Sight). Hopefully the naming conventions make it clear what everything does.


User avatar
evs
001 Admirer
 
Joined: Tue May 08, 2012 5:27 pm
Location: Perth, Australia

Re: Turn Based Combat

Postby evs » Sat Dec 10, 2016 12:57 am

hmm, i never did figure out how to use a table

User avatar
Lucifiend
001 Subscriber
 
Joined: Wed Apr 22, 2009 7:37 am
Location: Layton, UT

Re: Turn Based Combat

Postby Lucifiend » Sun Dec 11, 2016 7:13 pm

You could accuse me of overusing tables...If you ever need a tutorial on how to use them let me know. I take way too much joy in using them. If given a chance, I'd probably plug everything into a table.

I'm not going to hit my weekend goal of having a full out AI battle. I went down a rabbit hole and started writing scripts for battlefield conditions and streamlined some other things. I wouldn't have guessed that creating a custom script to determine if someone gets a flanking bonus would be so complicated. I couldn't come up with a better method than:

Find Defender Direction
Find Attacker direction of attack on Defender (which cardinal the defender is being attacked from)
Pass results through a series of direction determination scripts to see if attacker flanking or not:
If Defender Facing Left and-
Attack from RightUp
Attack from Right
Attack from RightDown
Then flanking

I created a check for each possible direction (8) the defender could be facing. It was more tedious than anything, but when I tested it everything went perfect the first time so I guess it was worth it. That was just one battlefield modifier. I plan to have other checks such as lighting, moving, spell effects, etc that can alter an attacker's or defender's score.


You could accuse me of overusing tables...If you ever need a tutorial on how to use them let me know. I take way too much joy in using them. If given a chance, I'd probably plug everything into a table.

I'm not going to hit my weekend goal of having a full out AI battle. I went down a rabbit hole and started writing scripts for battlefield conditions and streamlined some other things. I wouldn't have guessed that creating a custom script to determine if someone gets a flanking bonus would be so complicated. I couldn't come up with a better method than:

Find Defender Direction
Find Attacker direction of attack on Defender (which cardinal the defender is being attacked from)
Pass results through a series of direction determination scripts to see if attacker flanking or not:
If Defender Facing Left and-
Attack from RightUp
Attack from Right
Attack from RightDown
Then flanking

I created a check for each possible direction (8) the defender could be facing. It was more tedious than anything, but when I tested it everything went perfect the first time so I guess it was worth it. That was just one battlefield modifier. I plan to have other checks such as lighting, moving, spell effects, etc that can alter an attacker's or defender's score.

**UPDATED 13 DEC 2016**

After some scripting fun last night, I was able to get everything to cooperate and have AI fight each other without user input. After some tweaks to how the AI understand the battlefield, I was able to get a nice 3 on 3 battle. The AIs are randomly generated. So each get random stats, weapons and armor and get 1 skill level with the assigned weapon. While not the most mind blowing video to watch, it does show 001 can do turn based AI just fine. If you're curious, I put the player actor in prison in the lower left corner just so he's not aimlessly hanging out in the middle of the battle. The AI are actually blind to the player existence, but I put him there regardless. Keeps him out of trouble.

The crash at the end is because I didn't bother to put anything into the combat loop to stop the cycle once all the baddies are gone. Not sure how I want to dump out of combat so I just sort of left it open ended.

One thing I'm contemplating to add is a pile-on awareness routine. Right now, the actors are oblivious to their own team. They pick an enemy and charge in. In theory, all the actors could swarm a single opponent. With 3 on 3 it isn't a big deal. With 20 on 5 it might become a problem. The AI will literally wig out trying to figure out how to get to the assigned enemy. I don't think it would be to rough to work out. There are only 8 possible places a melee opponent can stand on a single target, so I would create a scan around the target and see if there is available space for another attacker.

I need to create a log of the combat rolls and modifiers to see what is going one behind the scenes. It's hard to tell if combat is fair or not for actual gameplay. Considering everything is randomly generated, one set of AI could be totally stacked without looking into the debugger panel.

Last edited by Lucifiend on Tue Dec 13, 2016 11:13 pm, edited 1 time in total.
Reason: Automatically merged double post.

PreviousNext

Return to Resource, Story and Level Design

Who is online

Users browsing this forum: No registered users

cron