Empire of The Corn Fields
Background
There are many things that a person can do to help cure the sickness known as boredom. This can be watching some TV, reading a book, or even starting a new hobby. However, what is there to do in the Midwest? Practically nothing. So, when two farmers got bored when they ran out of alcohol. They decided to wage a county-wide fight against each other.
This game is a simple RTS game in which the player takes control of a unit of farmers who are bored farmers. The player will be able to control these guys to fight against the enemy to win. They will also be able to build structures that help spawn in more units for the player to control and…
Become the emperor of the corn fields.
Game Play
Resource Gather
Construction
Game Break Down
This game, as stated, was an RTS or real-time strategy game. This game is a simple take on the genre. The game is simple, funny, and has a 2.5D style. I have done a lot of the programming for this game. I am not the sole programmer. I programmed the building construction as well as some functions for the camera. In other words, I did the whole construction system, from the time functions to the actual buildings themselves.
Construction
One of the main things I worked on for this game was the construction function for the buildings. This was the main thing that I spent the majority of time working on for this project. In the construction function, some functions relate to time.
The time functions, in short, are the functions that calculate the speed for the construction, the daylight cycle, and the setting of the meshes for the buildings.
Game Time Library
Calculate Game Time
The very first thing that I programmed was the game time library. This library is the place where the values of the speed variables are stored and calculated.
The calculate game time takes the delta time and two other variables and adds them into a single variable, then it takes it and divides it. It takes the remainder and returns it to two new variables—the day counter and our game time.
The other function is the set speed setting. This function gets the game speed and adds the default game speed local variable. Then adds that to a new variable called proportional speed local. This is then checked multiple times with different float values. The values are checked with a nearly equal float. Then the new speed setting local variable is set based on that. At the end of the function, the local speed setting is returned.
Set Speed Setting
Calculate Game Time
Set Speed Setting
The function below is the set speed multiplier. This function takes the current speed setting and assigns it to a switch on integer switch. The integer variable will then be chosen, and the speed multiplier local is then set. That variable is then returned at the end of this function.
Set Speed Multiplier
Game State
The next thing that was programmed is a thing called the game state. The game state is the function that enables the game time that is to be calculated and used in the game. In other words, this state is the start of the clock for the variables to be used by the game mode.
Calculate Time
The first thing that was done for the game state was to make the function calculate time. This function gets the game speed and time. These are then calculated to be set for the game time and day counter. This is the start of the game state blueprint.
Set Seconds and Initial Conversion
Set Minutes
Set Hours
The above functions are all a part of the larger function of updating the clock calendar. The first thing that gets triggered was set seconds and initial conversion. These two functions first get the game time variable, is then multiply it. After it is multiplied, it is divided by sixty. Leaving the remainder and the return value. The return value is plugged into the dividend for the set minutes function. The seconds are set from the remainder of the game time. This same formula is used for the minutes and hours.
For the calendar function, the day is simply figured by adding the day counter and the day. There is then a check to see the day of the month. If it is true, the day is set to one, so is the month. The branch has been used for months. It checks if the month is greater than twelve. If that is true, then the month is set to one, and so is the year.
After each of those values is set and plugged into the proper checks. The variables are then returned at the end of the function. Second, minute, hour, day, month, and year.
Calendar
Sun Rotation
The next blueprint actor that was made is the sun. The sun is an actor that uses the time functions to simulate the sun itself. Some functions are in the game state, but they relate to the sun’s rotation. So, they will be explained here.
The sun’s rotation starts with the event begin play. This is a simple check to see if it is valid or not.
Event Begin Play
Calculate Sun Rotation
Event Tick
The next thing that is done is the event ticket. However, there is a calculation of the sun’s rotation. The calculation first gets the game time, then changes for different day lengths are calculated then it makes it a rotator. This is then returned to the actor rotation.
Get Sun Rotation Actor
The game state then gets the sun rotation actor and sets the reference for it. The pass game time is a setting of the game time for the sun actor reference. The sun actor itself is then able to get the game time from the interface that has the game time and sets it in the sun actor.
As I stated, some functions relate to certain actors, so even though the functions are in the game state. They relate to the sun actor, so that is why they are explained here.
UMG Clock
The thing that was programmed next was the UI element that appeared on screen for the clock. The UI has functions that how for the control of the time, the spawning of troops, as well as the choosing of the building type.
Before the functions of the UI can be explained, the Ui will first need to be able to appear on screen. This is done by the player controller creating the widget and setting a variable, it then adds it to the view port.
Pass Game Time
Event Set Game Time
Add Widget to Screen
Pass Date Time Struct
Event Set Date Time
After the UI appears on screen, there is functionality that needs to be programmed. There are a lot of little pass-through things that help the UI display the time and have the controls to increase and decrease.
The first thing that I programmed was a simple pass-through for the player controller to communicate with the interface that was created to store the time variables. The second thing is the event to set the date and time for the main UI. The third thing that was programmed is the main UI widget’s event set date time and set game speed int.
Event Set Data and Game Time
Set Calender
Set Clock
Event Date Time (Game Time Widget)
In the main UI, there are small widgets that are in it. One of these widgets is called game time. This widget stores all of the individual parts for the time UI. This UI has buttons to control time manipulation, such as increasing and decreasing the time. This can also pause time.
The above function Event Set Date Time is in the Game Time widget. The date and time is set, and then set calendar is called then set clock. In the set calendar, the text for the year, date, and month is set. It is formatted before being turned into a text widget.
Set Month Text
In the set calendar function. There are smaller functions. One of these smaller functions is the set month function. In this function, the month is determined by the date time variable from the interface, then the get month from that is triggered. That is plugged into the switch on the int. This will check which month it is based on the integer value. That will then set the month and return it.
Set Year
Set Date Text
In the set calendar function, there are two more functions. They are set year text and set date text. Both of which do the same thing, but with different values. They get the day and year from the datetime variable. That is then converted to a text integer. Which is then plugged into the set calendar function.
Set Hour Text
Much like the set calendar function, the set clock function also has smaller functions. These smaller functions are set hour text, set minute text, and set second and special text. Each of these functions operates similarly to the functions above. It is a get from the date time variable, then it is get and used for the functions.
For the set hour text function, it starts by getting the hour and the hour 12 from the date time. These are then converted to text integers then it is put in a select function with the Boolean variable of Use 12-Hour Clock. The value of this is then returned.
Set Second and Special Text
The next function is set second and special text. In this function, the first thing that gets checked is the Use 12-Hour Check variable. This branch uses it to check if the date time is the military time style clock or a twelve-hour clock. If it is true, then the am and pm are set to the text. If it is not, then it is using the twenty-four-hour style clock.
Set Minute Text
The set minute text is simple. It only gets the minute from the datetime variable. Then it is converted to the text integer variable. This is similar to the calendar function above. But it relates to time instead of date.
All of the logic above is then computed and used for a UI that can be used to manipulate time and date. And it looks like this.
So, the logic for the controls of the button has been explained. I also programmed the key bind inputs.
Input for Clock Type (12 hr or 24hr)
The first of these controls is the switching of the clock styles. This is either the military clock or twelve hour clock. This is done by pressing the T key on the keyboard. This then changes the clock by changing the Use 12 Hour Clock value to true or false.
The next inputs are the increase and decrease. The key binds for this are G for decrease and J for increase.
Decrease Input
Increase Input
Each of the buttons are coded the same. However, there is one function that is different in each of the input functions.
Decrease speed function starts off with a check to see if the speed setting is greater or equal too one. If it true then it is subtracted and the set game speed is set. Then another check is done to ensure that it does not go past one.
Increase speed function starts off with a check to see if it paused. If it is true. The speed setting is stored. If the check is false there is another check to see if it is less than five. If that branch comes back as true then the speed setting is added to. If it is false. The speed setting is set to five.
Decrease Input
Decrease Input
In the decrease and the increase input button functions there is another function called check buttons. This is a simple pass through function that leads to the auto button function.
Auto Enable Buttons
Auto enable buttons starts off with a branch check to see if speed settings is zero. If that is true then the decrease speed button is disabled. If the branch is false then the decrease speed button is enabled. Then another branch is check where it checks if speed setting is equal to five. If the branch is true then increase speed button is disabled. If the branch is false then the increase speed button is enabled.
Pause Input
Set Play Pause Game
When the H key is pressed the set play pause game function is called. If the branch is true then the game un-paused. The is paused variable is set to false and the store game setting is set to the speed setting. This will resume the game. If the branch at the beginning of the function comes pack false. The function will pause the game. The speed setting is stored and then set to zero. The Boolean value is set to true. Then the game will be paused. The biggest thing that ensures that the game is paused is the setting of the global time dilation. If the game is paused that is set to zero. If the game is un-paused the time dilation is set to one.
Set Game Prog Bar
The progress bar does change after the increase and decrease buttons are pressed. A few functions are called when these inputs are pressed. The event set game speed int is trigged when the game speed functions are trigged. The set game prog bar function is called. The set percent is trigged where the value of the speed setting divided by five is plugged into the game speed prog bar which is a variable in the game time widget.
Construction Data Table
One of the main things I learned from this project is how to use a data table in a Unreal Engine 5 project.
I first set up some enums as well as structs that are used in the data table. The enums are the resources, building types, buildings themselves, and the stages of the construction. The data table stores this information, and it is then used to set the meshes that are used in the construction stages.
Event Set Game Speed Int
Event Set Game Speed Int (BPI Game Time)
Building Data Table
Meshes
The enums are the main variables that are plugged into the data table. Barracks, Silo, Garage each have their building type with a name that is used for the row name. Stability is something that is used for building health. The construction meshes are the meshes that make up the look of the building while the building is being constructed. Base meshes are the completed meshes. The image above shows the meshes that are used. The three buildings have their own distinct meshes.
Buildings
Building Type
Construction Stages
The images above are the enums that hold the information that is used in the data table. Each enum has its information, as I previously stated. The information is then plugged and used by the data table. However, the struct is also used.
Resource Type
The above struct is the building struct. This is essentially the butter for the data table. The enums are the milk. In other words, the data table is the bread, the struct is the butter, and the enums are the milk. The struct is the stuff that is used to store the variables, then it is used in the data table. Hence why the struct has the same names as some of the elements that are in the data table.
Spawn Preview
So, the data table holds all the data for the construction. Now, the actual construction part can be explained. The first thing is the preview.
Building Struct
The set preview is the first thing that was programmed for the preview portion of the construction of the buildings. The preview is a box that can be moved by the player and is the location where the building that the player wants to build be placed at. The branch checks if the player is trying to spawn in a preview. If this branch is true then the destroy preview function is called. Then Spawn Preview building. The set is preview is then set to true. After this set to true a event is created sop the timer can be set. All this does is trigger a series of functions.
Set Preview
The first function that the set preview function triggers is the destroy preview. It first checks if the building reference is valid. If it is valid, the destroy preview for the building master is triggered. The building reference is set the preview is set to false. Finally the timer is cleared.
Destroy Preview (Building Manager)
It may be confusing that the master and the manager have the same name functions, but that is to keep things simple. The master function’s destroy preview function starts by getting a blank mesh. After that is set. The set entrance function is triggered, and the same with the set collision area as well. The new rotation is set to zero for all axis’s and the building master actor is destroyed.
Destroy Preview (Building Master)
Set Entrance
The set preview function triggers this with the row name from the function. The preview transform is set from the getGridSnaps function. The actor is spawned in that location. After the actor is spawned, the function checks if it is valid. If it is, the building reference is set. Then the construction’s status is changed to preview.
Spawn Preview Building
The above functions are triggered by the B key. The player will press the B key and begin a series of functions. Firstly, for a player to build any building. They will need to have a builder selected. This is a simple Boolean value check. If it is true, then the destroy preview will be triggered. This will make the preview mesh not spawn. If the value is true, then a flip-flop is triggered to make it act like a button. The first time the preview is checked. If the player can spawn a preview. The branch will need to have a false value.
Controls For Build Function
These two functions are triggered back-to-back, from each other. Entrance then the collision. In the set entrance function first, the local bounds of the mesh are get and and one-hundred-fifty is added to the X bounds and twenty is subtracted from the Y bounds. After that, the X value is multiplied by negative one. That is plugged into the new X location for the set relative location. As for the Y value, that is made into a vector, then that is plugged into the box extent with the entry point being the target.
The collision function starts the same. However, the local bounds are split more, and the min X and min Y have fifteen subtracted from it. The max Z has two divided by it. All three of these values are made into a vector, and the Z value is plugged into the relative location. The return value from the set relative location is returned as a sweep hit result.
Set Collision Area
Now, all of the check functions relate to the resources, which will be explained in the section regarding the programming behind the resources. But the set preview functions are called here in the actor that was called camera 3. The reason for this is that this is the controlled actor pawn. After B is pressed on the keyboard and the checks return the true value. Building name is plugged in for the set preview function, and the action mode is changed to construction.
Check Resources for Buildings
Moving The Preview
The preview can be spawned in. However, at this point, if the player were to just press B. The preview would only spawn in and not follow the movement of the cursor for this. A few more functions were programmed. The first of these functions that was programmed was the function needed to get the arm length.
Get Current Arm Length
One might be curious why there is not a line trace for the preview instead of a standard value like the code shown. The reason for this is the preview needs to follow the cursor and not spawn in where the cursor is at.
Set Build Position
This function, titled set build position, is a function that does the line trace from the camera and gets the hit on the hex grid actor. The first thing that happens is the player manager gets the camera location and actor forward vector. The location is added by the results of the trace distance multiplied by the forward vector. This is then plugged in for the line trace end, and the camera location is plugged in for the start. The block hit result location is then plugged in for the return and the hit actor is the hex grid.
Set Cursor Position
The Set Cursor position function uses the get current arm length function result and adds two thousand to it. The results from that are then plugged into the set build position function. After the build position function is triggered, the result from that function is then plugged into the cursor position variable. That is then plugged into the variable for the building manager’s set cursor position function.
Get Grid Snaps
This function’s whole purpose is to get and set the grid snaps. Firstly, the vector of the cursor position that was obtained is obtained, and then fifty is added to the X and Y of the cursor position. The floor is obtained from that value, and the snap values are divided by that. Results from that are then multiplied by the snap values, and that is plugged into the make vector variable, and the vector value is then returned. This makes the grid snaps function work.
Move Preview
The get grid snaps are plugged into the move preview. Track cursor does this. It is called the move preview function from the building master. The grid snaps are used for the new location then which is plugged in for the set world location as well as the set actor location. This will cause the preview to follow the player’s camera as they move around the map.
Track Cursor
Checking Building Placement
Now the preview can move and be spawned in. However, the preview can only be moved. If a building were to spawn in where the preview is. There needs to be a check to see if the build can be spawned in.
Get Vectors
The check to see if the building can be spawned in. The first thing that is done is the get vectors. The actor location and rotation are get first. Then the forward vector and right vector are obtained from the actor rotation. Secondly, the overlapping actors need to be gotten. The get overlapping actors are get and plugged into the for each loop with a break. The cast to bp_hexgrid is the base actor that is the play area.
Check Is Overlapping
Slope Trace
The other smaller function that is done is the slope trace. This function gets a vector that is plugged into it, then a thousand is added and subtracted from the Z-axis value for the vector that is plugged into this function. That is then plugged in for the start and end of the line trace by object. The on-hit is broken, and the impact point is also broken. The get actor location is subtracted by the break vector. The final result is then returned.
Set Material Overlap
The final thing in the check stage is the ability to change the material of the preview to let the player know if the building can be spawned in that location or not.
The first that is done is a branch that checks if the preview is overlapping anything. If it comes back as true, then the for each loop is done to have the material change after the overlap is true. The material is then changed with the set vector parameter value.
The second branch is done for a false check. If there is no overlap detected. Then the same loop is done, but the vector parameter value is different.
Destroying Preview
After the preview is checked to see if a building can be placed. Then it will need to be destroyed so that the building can be placed in the place of the preview. These are the functions that trigger and perform such events.
Destroy Preview (Building Manager)
The destroy function of the building manager first gets the building reference actor, which is the building master. the building reference is then set. The set is previewing is then set to false. The timer is cleared. This function was previously shown above, however, its placement relates to functions in this logic section.
Destroy Preview (Building Master)
This destroy preview function is in the building master actor. In this, the static mesh is set to blank the set entrance, and the collision area functions are called again. The actor rotation is then set to zero for all axis’s then the actor is destroyed. This will destroy the preview and start the construction functions.
All of the functions that relate to the preview look like this.
Constructing Building
Now that the preview is done. The next thing that needs to be done is the construction of the actual buildings.
Switch To Construction
The preview was the place where the building location was determined. However, the next step would be the construction. To construct a building. The Q key is pressed,, and a branch is checked. If a builder is selected the action mode is changed to construction. The Minus materials function is triggered, and then the construction events function.
Minus Materials
This function mainly deals with the resource functions. However, it is triggered by the construction functions. This function starts by checking if the Boolean for the building name is set to true. If it is, then a certain amount of resources will be deducted from the game mode.
Construction Events
The next function that gets triggered after the minus materials function is the construction events function. In this function, the construction checks functions get called, then a branch is triggered. If the results of the construction checks are true, then the remove preview function is called. The spawn construction is next. Then the final thing is that the action mode is set to selection. The purpose of this function is to trigger more functions in the series of logic that makes the builds spawn and build.
Store Variables
After the construction checks function is triggered, the next function in the logic series that is triggered, is the remove preview function. The remove preview stores the variables of the row name and the transform of the building reference. After the variables are stored, the destroy preview will be triggered. This is the destroy preview of the building manager that was shown previously.
Spawn Construction
After the remove preview function is triggered the spawn construction function is triggered. The first thing that happens in this function is that the building master is spawned into the scene. The branch will check if an actor has spawn. If it did, the value will be true and the building local is set. The building status is set to zero. The add to unconstruction list function is triggered, and finally the set construction timer function.
Remove Preview
Set Building Status
After the set building status is triggered, the building status is set. The construction status switch is also triggered, and the set mesh function is triggered for both the built and the getting done status. The building status is then converted to a string so that the value can be used in the branch. This branch checks to see if the construction is done. Once it is done and the status is built, the spawn selectable function is triggered.
Add To Unconstruction List
Add to Unconstruction List is triggered after the set building status function is triggered. The add to the unconstruction list is a function that checks if the building is valid. If it is valid, then the building is added to an array.
After the building is added to the array, the set construction timer is triggered. This function starts with a branch that checks if the index is greater than or equal to zero. If it is true, another branch is triggered to check is the timer is active by the handle. If this branch is true, then a timer by function name is set. The construction time handle is then set.
If the first branch is false, then another branch is used to check the timer if it is valid and active. If that is true, then the timer is cleared.
Set Construction Timer
If the first branch is true, then a loop is triggered. The body of the will set the building locally from the array. Another branch will be triggered to check the construction status. If the construction status is getting done, then the branch will return true.
For Each Loop and Branch To Check Status
When the first loop is complete, a second loop is triggered. This loop will remove the buildings from the unconstructed list and reset it by adding the completed building to the list. Once this loop is done. The buildings to remove local are cleared, and a branch is triggered. This branch is done to check if the length of the array is less than one. If it is true, then the timer is cleared.
Loop To Remove Building from List
Clear Array
When the remove from the unconstructed list is triggered. A is valid is done to check is the building is valid. Then a branch checks if the under construction building list has a length is greater than or equal to one. If the value is true, then the building is removed from the underconstruction list.
When the add to list of buildings is triggered. It adds the completed building to the list of buildings. But first, a is valid is done to see if the input is valid.
Remove from Unconstructed List
Add to List Of Buildings
Going back to the branch that checks the construction status, if the value is true, then a division of the base construction speed and the speed multiplier is done, and the value is used to set the delta construction time local. After that value is set, the add constructed time function is triggered. The switch on int will be triggered after checking the length where the building construction stage is at.
Update For Num Of Units and Switch on Int
Add Constructed Time
When the switch on int is set to a value of three. The third value is a branch that checks the building local for a few values. The first value is if the time constructed is divided by the construction time. The value of this is checked to see if it is greater than or equal to .33 and less than .66. The second value is if the building status does not equal to one.
If the switch on int has a value of two. Then a similar branch triggered. This branch checks if the value of the time constructed divided by construction time is greater than or equal to .5. The second value of this branch is to see if the building status does not equal one.
Switch on Int 3
Switch on Int 2
There is a second branch in the third value of the switch on int. But the first thing that happens is that the building status is set to one. The branch will then check if the value of time constructed divided by construction time is greater than and equal to .66. The second value is that the building status is not equal to two.
Second Branch on Switch Int Value 3
After the branches, the building status will either be set to one or two. If the switch on int is three before the branches are triggered. Then, after the branches are done, the building status is set to two. If the value was two at the switch on int. Then the building status will be set to one after the branches.
Set Building Status to 1 or 2
After the branches, there is a final branch that gets the time constructed and the construction time. It checks if the time constructed is greater than the construction time. If it is, then the building local is added to the buildings to remove local array. The construction status is set to built, and the building status is then set to zero.
Building Local final check and Set Status
Looking back at the set-building status. There was a function that was triggered at the end of it. This function was the spawn selectable. The spawn selectable is the building that can be selected to be used to spawn more troops.
This function first sets the actor of the building master to hidden. A do once is triggered after getting the camera pawn so the camera reference can be set. After the spawn menu function is called, the selectable building is spawned. The function named selectable is called from the selectable building actor.
Spawn Selectable
In the camera actor, the spawn menu function is called. This will trigger another function called selectable check. It will check and set the name for menu.
The selectable check has three branches. These branches will check the building name if the value of the name is true. The building name will be set that is the same name as the true value of the branch and returned so that the name for menu is set.
Spawn Menu / Set name from menu
Selectable Check
This is the final function of the construction logic. The selectable function starts by getting the building result and setting it as the building built name. There are once again three branches that check if that value is a certain name. If a name comes back as true the building built name will be reset to the name that comes back as true. This will then cause the set static mesh to be set with the corresponding mesh with the name.
All of the logic relating to the construction function will result in the construction working as shown below.
Selectable
Construction UI
The construction logic is done. The player will be able to spawn in a building. However, there is still the UI that the player needs to use to select the building type and the UI to spawn troops.
The first thing that happens is that the UI needs to get added to the screen. It first gets created, then added to the viewport. The music is also played. The Event tick checks if the main UI is on screen for every tick and ensures that it is visible.
Add UI to Screen
If the player presses one key on the keyboard. The build menu button function gets called. There is a flip-flop that first calls the first button function in the activities menu. A flip-flop is a function that has two outputs. One triggers the first time, and the other triggers a second time. The First button function first changes the UI button color, then there is a delay before the construction menu function is called. Then the color is changed back to the default. The first button function is also inside the UI regarding the spawning of troops.
Build Menu Button
Opens Spawn Menu
When the call construction menu gets called a branch is checked; if the construction menu is visible, it is true. Then the construction menu is set to visible and the reset menu is called, and the construction menu visible is set to false. If the branch is false, then the visibility is set to no hit-testable, and the construction menu visibility is set to true.
The reset menu is in the construction widget. When this function gets called the whole construction menu and the different building selection button are set to collapsed and false. There are three different buttons that can be pressed. The code for them are the same, they just set the building that the player wants to build.
Build Menu Button
Reset Menu
The event construct is a function that is triggered at the beginning when the UI is created. All this function does is set a reference for each of the UI elements. It ensures that the main widget can be called in the individual UI elements.
Event Construct (Main Widget)
Inside the construction menu and the UI menus for the troop spawning. There is the event construct functions. Each of them represents the same logic. A branch to see if the menu is expanded and the reference is being set.
Event Construct (Construction Widget and Troop Spawner Widgets)
The above code is the logic for the collapse functions. There are multiple collapse functions. This is the collapse function for the civilian, aka the selection for the barn. The first thing that is done is a branch that checks if the menu is not collapsed. If they are, then a flip-flop is triggered. A second branch is set to either expand the text or collapse the text of the UI. The second output of the flip-flop will trigger a branch that checks if it is expanded.
Collapse Functions
The collapse functions continue with more code. The true value of the branch will make the UI collapse, and the corresponding Boolean value to be set to false, and the button color to be changed back to the default.
If the value is false, then the UI is expanded and the value is set to true. Upon the second time the flip flop is triggered, the button color is changed and a delay is triggered before the camera pawn is get.
Collapse Function CONT.
In all of the collapse menu functions. There is logic above the troops have a call for an additional function at the end. The Buildings do not. The first thing that gets set is a row name variable. In the example above, it is barracks for buildings and ATV for vehicles. However, it changes for each of the different options that can be spawned in for troops or the building type. The Boolean variables are set in accordance with the selection of the player. Then the preview functions are triggered and the button color is changed back to the original.
Collapse Menu (Buildings)
Collapse Menu (Troops)
The call preview functions are in all of the different collapse functions. Each resets their UI menu. The only difference is that the building preview functions have the start preview function, and the troop versions do not. Each preview will set the visibility of their UI menu to hidden. Then the reset menu function is triggered, and the Boolean for the menu is set to false.
Collapse Menu (Buildings)
Collapse Menu (Troops)
As previously stated, this function is not in the menu functions that relate to troop menus. This is only in the building menu functions. When this function is triggered, a branch checks if the player is previewing. If he is, then the destroy preview function is called and the set preview function after. If the branch is false then just the set preview function is called. The action mode is then set to selection.
Start Preview
As for the troop collapse functions, there is a spawn function. For the example shown, that would be the vehicle spawn. But it is the same for the other troop types in the game. When this function is called a branch is triggered to check what the name of the troop that the player wants to spawn in is. That would correspond with the true value and the function. For example, if the player wants to spawn in ATVs. Then the spawn atv function is called.
Vehicle Spawn
When the troop spawn function is called, a branch is triggered to check if the player has a certain amount of resources. If that value is true the troop will be spawned. The location is determined by getting the building reference transform. The X is plugged straight in, the Z and Y values are added to a random float before it is plugged into the spawn actor function.
The logic that is shown above will result as shown below.
Troop UI
Building UI
Vehicle Spawn
Resources
Resources were mentioned multiple times throughout the logic above. However, it was next explained how the player gets these resources.
Gather Resource
Overlap Event
Gather Loop
The resource gathering logic starts when the player overlaps with the resource nodes. An event is triggered when the overlap happens, the event is the gather resource function. The gather resource function is cast to the builder actor, and the builder unit is set. After that is set, a timer is set by the event. The resource loop is the timer event. When this event is started, the builder unit will get the corresponding resource that is being gathered and add six to it. The name of the resource is set and passed to the drop-off function.
When the timer is over, a function that is called drop off is triggered. In the builder actor, when the drop-off function is triggered. It gets and sets the resource gathering name. It checks if the resource harvester is valid. If it is the state of the builder is set to dropping off. The trailer actor is then get and another check is done to see if it is valid.
Drop Off
The drop-off function continues with an AI move to the node. This node moves the builder to the trailer actor. Then, a branch is done to check which resource is being gathered. In this example, the builder is gathering cash. So the cash drop-off function is triggered.
Drop Off CONT.
After the function that removes the resource from the builder actor is triggered, the final part of the drop-off function sets the resource b to false and checks if the builder is moving to an enemy or resource node, where the resource is harvested.
Drop Off CONT.
A resource drop-off function is triggered to remove the resource from the builder actor. A cast is done to the game mode to get the cash inventory. The resource is added to the inventory and then the resource that is in the inventory is then set to zero.
Resource Drop Off
Upon the end of the drop off function, and the is valid for the resource harvester is true, the gather two function is triggered. At the start of this function the state is changed to gather. Then, a check is done to see if the builder is attacking an enemy or gathering resources. If the player is gathering resources, a branch is triggered. This branch checks for the location of the resource harvester actor. Then the resource b variable is set to true. And finally, the builder is moved to the location of the resource harvester actor.
Gather
Lessons Learned
There was a lot learned when I was programming my elements for this game. Most of it was the logic behind the creation of real-time strategy games. But the second is the logic of how to control NPCs and have them move while the player is controlling another actor.
The non-programming things that I learned were how to be the producer for a game in a year. For this project, I was the producer for the game as well as a programmer. However, I was not the only programmer. I did a lot of programming, but I was not the integrator; that was my teammate. I learned how to use JIRA, a project management tool. I also learned how to manage a project personally as a team leader.
This project helped improve my programming skills as they relate to a different type of game.
Collaborators:
Andrew Schwartz | Heath Oakley