• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How would a combat system like this be accomplished?

flyinian

Member
I'm a little ahead of myself in my development road map but, I decided it may be a good idea to have at least a good idea on how I am going to do my combat system.

I just brain stormed a combat system, the partial logic of it anyways.
(The game is a text based simulation game)

Essentially it'll be something like this:

There will be at least 2 sides fighting. Player VS. A.I.
Both will have their own combat units(could be thousands to trillions of units). It doesn't matter what they are for this.

Each unit will have different stats for combat.

The "playing field" will be a static area that displays numbers, timers, etc.

The units won't have any abilities but, the player will have abilities that they can activate.

Here are the combat stats for the units:

Kill amount: is the amount of opposing force units destroyed per Attack Rate.
Attack Rate: The rate that the unit attacks at.(seconds, minutes, hours, etc.)
defense: is the negated destroyed units. Ex: Player is hit with an Attack of 11 but, the player has a defense of 10. 11 - 10 = 1. The player will lose 1 unit for that attack

This is the summarized version of my combat system. How would one code this? I'm not really looking for a complete system for this(unless you'd like to give one) but, more of an idea on ways of doing this. At least one that can get me started.

I'm still a beginner at coding and coding something like this in my head isn't that clear yet. Especially coding it in a way that is easy for a beginner to create, debug and edit it to fit their needs and wants.


Here is a more precise request:
If I were to create variables in a control object that declares the stats for a single unit, how do I make these variables usable for the player to use for a combat system?

Create event in obj_PlayerUnitControl;
GML:
_PlayerKIll = 0;   // Player's kills per attack from all units
_PlayerAttackRate = 0; // Player's attack rate from all units
_PlayerDefense = 0;  // Player's total defense from all units
_PlayerTotalUnits = 0; // Player's total owned units



_Unit1Name = "Bomber Plane";   // Name of unit
_Unit1Count = 1,500;  // Current count of Unit 1. Lets say the player purchased 1,500 of these.
_Unit1Kill = 100;   // Amount of kills per attack
_Unit1AttackRate = 10;  // Attack Rate(Per in game day)
_Unit1Defense = 50; // Unit's defense



If the player had 1,500 Bomber Planes, how would I code it so that it can be used in a combat system?
I'm also planning on adding a system to upgrade the units. My game will have several countries which will upgrade their units separately from the player.

I may be adding more over time.

Thank you.
 
Last edited:
C

Catastrophe

Guest
So, I read the description, but I'm still pretty unclear on the combat system: It feels like you explained a small portion of it.

By text based with gillions of units are you talking about something like swarmsim? Like this?:


Is there a playing field? Do units have abilities? Do you want to simulate each unit or are they just a number that is tallied up and done math with?
 

flyinian

Member
So, I read the description, but I'm still pretty unclear on the combat system: It feels like you explained a small portion of it.

By text based with gillions of units are you talking about something like swarmsim? Like this?:


Is there a playing field? Do units have abilities? Do you want to simulate each unit or are they just a number that is tallied up and done math with?
No playing field or abilities.

It's just numbers being calculated.

Similar to the game you linked.

I'll add more information at a later date.

Thanks for the reply.
 
C

Catastrophe

Guest
Heya, I can reply more tomorrow, but basically the main structure you want, is you want to have an object (basically GML for a class) called "unit", and you want an object for every type of unit you want, and those objects should be parented to "unit". Normally, you would use these objects to refer to an instance of each unit, but since you're having a zillion and it's just text, these objects are basically going to be the information for the object.

example:

Unit create:

_Name = "defaut unit";
_Kill = 100; // default kill rate
_AttackRate = 10; // default attack rate
_Defense = 50;

obj_Bomber create:

_Name = "Bomber Plane"; // Name of unit
_Kill = 100; // Amount of kills per attack
_AttackRate = 10; // Attack Rate(Per in game day)
_Defense = 50;

etc.

Immediately, this will do nothing, but later down the road this can be helpful as you learn more about inheritance and want to do more complex things with these units. When you have "information" objects like these, some people like to use ds_maps instead, but that rules out inheritance which is pretty nice.

As for how to keep track of these units you'd want to use some data structure for the player to keep count of how many of what units they have. So something like a ds_map with the amount of any unit they have.

Example:

myUnitList = ds_map_create
// here I'm giving 50 bombers to the player
ds_map_add(myUnitList,obj_bomber,50)


ds_map is not the only way, but feels the most convenient to me in this case, a list or grid can also work. Either way whatever structure you settle on, it's better than individual variables for each unit.
 
Last edited by a moderator:

flyinian

Member
Heya, I can reply more tomorrow, but basically the main structure you want, is you want to have an object (basically GML for a class) called "unit", and you want an object for every type of unit you want, and those objects should be parented to "unit". Normally, you would use these objects to refer to an instance of each unit, but since you're having a zillion and it's just text, these objects are basically going to be the information for the object.

example:

Unit create:

_Name = "defaut unit";
_Kill = 100; // default kill rate
_AttackRate = 10; // default attack rate
_Defense = 50;

obj_Bomber create:

_Name = "Bomber Plane"; // Name of unit
_Kill = 100; // Amount of kills per attack
_AttackRate = 10; // Attack Rate(Per in game day)
_Defense = 50;

etc.

Immediately, this will do nothing, but later down the road this can be helpful as you learn more about inheritance and want to do more complex things with these units. When you have "information" objects like these, some people like to use ds_maps instead, but that rules out inheritance which is pretty nice.

As for how to keep track of these units you'd want to use some data structure for the player to keep count of how many of what units they have. So something like a ds_map with the amount of any unit they have.

Example:

myUnitList = ds_map_create
// here I'm giving 50 bombers to the player
ds_map_add(myUnitList,obj_bomber,50)


ds_map is not the only way, but feels the most convenient to me in this case, a list or grid can also work. Either way whatever structure you settle on, it's better than individual variables for each unit.
This is great, I've been avoiding data structures but, it appears I may have to face it for this project to work.

Thanks for the information.
 

flyinian

Member
I looked into data structures and they're still fairly advanced for me at this time so, I am going to rule out data structures as long as it's possible.

If I were to create a controller object that calculates how many units my player has at any given time, as well with the calculations of determining the total stats. Along with anything else that may be related. Could this be an effective replacement for using data structures?

This may be more work but, I have a better understanding using this method than data structures.
 
Data structures are what you need to do this sort of thing. It's -possible- to do it without it, but you're literally kneecapping yourself if you avoid them. Get comfortable with data structures and once you have, you will honestly be kicking yourself that you didn't do it before. They might seem complex, but they are not; any data structure can be boiled down to what is essentially a list (like a shopping list) or a spreadsheet. If you can make a list, or put values into a spreadsheet, you can use data structures.
 

flyinian

Member
Data structures are what you need to do this sort of thing. It's -possible- to do it without it, but you're literally kneecapping yourself if you avoid them. Get comfortable with data structures and once you have, you will honestly be kicking yourself that you didn't do it before. They might seem complex, but they are not; any data structure can be boiled down to what is essentially a list (like a shopping list) or a spreadsheet. If you can make a list, or put values into a spreadsheet, you can use data structures.
okay, thanks.
 
C

Catastrophe

Guest
Yeah data structures are scary until you know which functions to look for in the manual. They pretty much all have:

A function to add to the structure
A function to look up the value or index
a function to remove from the structure
a function to create the data structure
a function to delete the memory of the structure
etc etc

Ds_map is a more complicated structure, and may not be the best starting place though, even if it would be my structure of choice for this. The introductory structure is a simple array, then a list, then you can learn the rest.

You might want to just start with arrays first as it's easier, although it will be quite awkward in the long run without a map if you ever need to check units for unique abilities or whatnot.

Easiest way to do this with arrays is you make one array for the object and one for the number:

unitsObj[0] = instance_create_depth(0,0,0,obj_bomberinfo)
unitsObj[1] = instance_create_depth(0,0,0,obj_fighterinfo)

unitsamount[0] =1000
unitsamount[1] = 50

Code:
//attacking
for (i = 0; i < 2/*well, look up one of the array sizes actual;y*/; i++) {
data = unitsObj[i]
amount = unitsamount[i]
attackRate = data.attack
//etc etc
}
Anyways, this is all very complicated stuff, so you'll just need to read a lot in the manual or tutorials, this is just to get your started.

The annoying part of doing this with arrays is that any time you need to add # of units of an object, you'll need to find which index to add to. Which isn't hard and is the only awkward thing, it's just unnecessarily complicated by using arrays. You could also store the amount in the data object itself, which would have a second array for each player's army
 
Last edited by a moderator:

flyinian

Member
Yeah data structures are scary until you know which functions to look for in the manual. They pretty much all have:

A function to add to the structure
A function to look up the value or index
a function to remove from the structure
a function to create the data structure
a function to delete the memory of the structure
etc etc

Ds_map is a more complicated structure, and may not be the best starting place though, even if it would be my structure of choice for this. The introductory structure is a simple array, then a list, then you can learn the rest.

You might want to just start with arrays first as it's easier, although it will be quite awkward in the long run without a map if you ever need to check units for unique abilities or whatnot.

Easiest way to do this with arrays is you make one array for the object and one for the number:

unitsObj[0] = instance_create_depth(0,0,0,obj_bomberinfo)
unitsObj[1] = instance_create_depth(0,0,0,obj_fighterinfo)

unitsamount[0] =1000
unitsamount[1] = 50

Code:
//attacking
for (i = 0; i < 2/*well, look up one of the array sizes actual;y*/; i++) {
data = unitsObj[i]
amount = unitsamount[i]
attackRate = data.attack
//etc etc
}
Anyways, this is all very complicated stuff, so you'll just need to read a lot in the manual or tutorials, this is just to get your started.

The annoying part of doing this with arrays is that any time you need to add # of units of an object, you'll need to find which index to add to. Which isn't hard and is the only awkward thing, it's just unnecessarily complicated by using arrays. You could also store the amount in the data object itself, which would have a second array for each player's army
Thank you for this.
 
Top