Friday, April 11, 2014

Some Completed Projects 3/3 - Village Trader

Hello everyone!

This post is the third of three presenting information on a couple of projects I've completed in the last two weeks.

After I finished up with the resource buildings in UDK I decided to try a similar concept in C#. Since I couldn't think of another project to do in C#, I figured I'd give it a shot. I figured this would give me a chance to learn a few more controls from the Visual Studio Toolbox, like panels and a progress bar. I had also planned to learn how to use the Task Parallel Library to do multithreading for the resource gathering, but that ended up being way over-complicated, so I used timers instead(I would essentially be creating a timer with the new tasks) since they supported all the features I needed without a lot of work.

The game (besides being really boring) puts you as a trader who has contracts with several resource gatherers(Steel, Candles, and Wheat). You provide these gatherers with workers and you can collect any resources they gather. You can then sell these resources to establishments in the local community (Blacksmith, Cathedral, and Windmill respectively) for a profit. After a variable amount of time it displays how much gold you made and your average gold per second. You can choose between a 3, 5, or 10 minute duration. Here are screenshots of the game, and you can download it here:



The gold and average is different on this due to the
screenshot coming from a different round.


There is a lot of balancing that would need to go into this to be remotely entertaining, as well as some structural changes. Since this was a C# learning project, not a game development one, I chose to leave out a lot of the balancing in order to complete it faster.

I learned quite a bit from this project, which was good. I learned that working with panels to create a 'paged' WinForm is tedious, unless there is some way to hide the panels in the editor. I read about using a tab control to achieve a more designer friendly 'paged' window, but that came with its own set of issues. It seems to me that the panel method is difficult at design time, but nice at runtime, while the tabbed method is easy at design time and (potentially) difficult at runtime. I also learned more about timers and how to update a progress bar based upon how far along the timer is. I also worked with picture boxes, which I hadn't used before.

Another thing I learned was how to make a custom UserControl. I had made one previously for another small project, but I didn't add any custom events that could be called so interactions between the control and the main form were messy to say the least. On this project I actually took the time to learn how to add custom events properly.The control I made was essentially a numeric stepper(or a NumericUpDown in C#/Visual Studio). I decided on creating my own because I wanted specific methods to run when I either increased or decreased the value of the stepper. The default stepper only has a ValueChanged event so I would have had to save the old value to a variable the compare it to the new one and see if it increased or decreased. I also didn't want the user to be able to input their own number into the textbox, since this would be displaying the amount of workers assigned and I wanted all the numeric checks to run through my custom Increased/Decreased events. I also wanted the control to blend in with the background more, so by default it has a gray background.  Here is a comparison between my custom stepper and the NumericUpDown:




I think that about wraps up the little projects I've been working on recently. There have been tutorials, but nothing too spectacular.



Some Completed Projects Part 2/3 - Resource Buildings

Hello everyone!

This post is the second of three presenting information on a couple of projects I've completed in the last two weeks.

During a break from a C# tutorial I was playing a round on Stronghold Crusader and I was looking at the resource gathering buildings and thought, "Hmm, I wonder if I can make something like that..." I've been interested in attempting to make an RTS after Winds of Commerce, but I think I have a lot of learning to do. Anyway, I decided to let my mind drift away from C# and back into Unrealscript. I decided to try and make a stone mine that gathers up to three units of stone if there are enough workers to run the building. Here is a demo that I made for it:



I added in some rudimentary functionality to select different buildings. Ideally this would be done via a point and click mouse system, but that was not my primary focus for this project. It just uses a trace to see if the actor that was hit was a resource building, then assigns the hit building to the currentBuilding. If I were going to make an RTS this would only be a small part of the game, but it was fun to do. Learned some stuff about the trace function, and getting a specific instance of an object.

There are only a couple things I would like to add to the building. One is actual animations to show the stone being mined. Another is some indicator as to whether or not the building is fully staffed. Scaling the buildings up to the correct size would also be nice. The last thing I would probably do is add some sort of graphical interface to aid with all of the tasks.

Some Completed Projects Part 1/3 - Meal Generator

Hello everyone!

This post is the first of three presenting information on a couple of projects I've completed in the last two weeks.

Last week I finished up the meal generator I was talking about in this post.  You can download it here. Just unzip it and double click the MealGenerator.application.



It works pretty well, though after using it a bit I thought of some stuff that would make it more complete. Some things I would like to add:

  • Having the list 'print' to a rich text box that would allow the user to edit the list, or add stuff before it actually gets printed. 
  • A section for additional items that you need to get, since some things don't need to be bought every time(Bottle of Ketchup, Box of Rice, etc...). You would just put those down in this additional list if you knew you need to buy those items this trip.
  • Have all the windows display at the same place over the main window.
  • Add another list of sides
  • Better search functionality, so if there are several things that share the same name/type you can search through them. Currently it just selects the first one that meets the criteria.
  • Additional options for quantity on ingredients, i.e. 1/2 Cup
If I decide to do another version I'll add these features, but that will be much later.

Monday, March 31, 2014

A Lot of Rambling About a C# Project

Hello everyone!

About a month ago a friend of mine told me a local company was hiring for a software developer, and they had told them I would be stopping by to talk to them. Unfortunately, my friend didn't really know what the company did exactly or what coding language they used for developing software. I went in and talked to the company and got a bit more information on what they do. They use C# for all their software development, which I had no experience with. It is an Object Oriented Programming language like Unrealscript, so at least I has some knowledge of how the language was supposed to work. Long story short, the guy I talked to said he'll put together a small project for me to try out and see if we're compatible. While I'm waiting for that project I went ahead and started learning what I could about C#. I'm nowhere near being proficient in it yet, but I've learned quite a bit. Hopefully enough to work out the project when it arrives.

So, Winds of Commerce is on hold until I learn if I will be getting the job. It saddens me because I really want to finish it, but all my free time has been spent going through tutorials and creating some basic programs with C# to work into more advanced stuff.

One project I'm working on is a meal list/meal generator. How it works is you create a master list of different meals(like dinners and such) with optional ingredients and notes. Once you have some meals in your master list you can either manually add them to a smaller meal list(for instance to make a dinner plan for the week), or you have the option to automatically generate how ever many meals you need, or both.

For example: if you knew you wanted to have burgers next week you could manually add burgers to the list, then generate the other 6 meals randomly to make the full 7 days of meals.

After you have your finalized list of meals you can then print them off using several different formats. You can choose to just print the meal names, print just the ingredients, or a all the meals and their ingredients. If you choose to print just the ingredients it will compile all of the ingredients from all the meals into one list, combining duplicate ingredients into one with the combined quantities. On the other hand, if you print meals and ingredients it will print each meal with the individual ingredients directly underneath the meal name. This way you can see exactly how much of what goes into that particular meal. I guess I should add one in for printing the notes off, but I forgot about that until just now...

Enough rambling for now, I'll go over some of the issues I ran into while trying to create this once I'm satisfied with it. Here are some images of the meal generator:

Main Page
Adding a new meal
Viewing the notes
Viewing the ingredient list
The selected meal list randomly generated
Print options
Printed with the "Both" option
Printed with the "Ingredients Only" option



Friday, February 21, 2014

A Little Detour To Revisit a Old Side Project

Hello everyone!

My buddy Andrew contacted me the other day and asked if I wanted to help him redo a lot of the stuff that we made for SpaceWings now that we have a bit more experience. So, we dredged up as many of the old files that we could and got to work figuring out what we needed to redo. He wanted to tackle most of the base code himself, while I took on getting the menus put together.

Unfortunately, the only assets we had from the original menus were screenshots. A bit of Photoshop magic and I had almost all the elements I needed. A major thing I was still missing was the font. None of the other guys that worked on it before that I talked to had the name of the font we used in the original. So, I had to find some new fonts. I then had to try and replicate the effects that Justin Bucher made for the originals. He's much more proficient at Photshop than I am though, but I did my best.

Here are some of the HUD assets:


Once I got the main aspects of the menus done I decided to start working on getting the pickup system working. This has four main parts to it: Picking up and classifying an item, adding to the inventory if applicable, updating the HUD if something was added to the inventory, and checking to see if the player has a particular item. 

Picking Up and Classifying

Getting the item to be picked up proved to be surprisingly difficult for me. I haven't really worked with skeletal meshes/skinning/animation before in UDK. I got almost all of it set up thanks to some help from Andrew, mostly setting up the anim tree. The part that kept throwing me off was the collision. To get collision on a static mesh is really easy, but I was having a trouble with a skeletal mesh. Turns out I was looking at too much code and over looked adding BlockNonZeroExtent = true default properties of the skeletal mesh component...

As for classifying it, there is a variable in the actual pickup that holds what type of pickup it is. When the pickup is touched it calls a function in the player controller class that takes that variable and decides what to do with it. Here is my base pickup class:

class SW_Pickup extends Actor abstract placeable ClassGroup(SW_Pickups); var string PickupType; var SpaceWingsPlayerController PC; var SpaceWingsPawn P; event Touch(Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal) { PC = SpaceWingsPlayerController(GetALocalPlayerController()); P = SpaceWingsPawn(PC.Pawn); PC.MyLog("A" @ PickupType @ "Pickup was touched", 'PickupTouch'); //If the instigator is the player, then process the pickup if(Other == P) { PC.ProcessPickup(PickupType); Destroy(); } } defaultproperties { PickupType = "None" Begin Object Class=SkeletalMeshComponent Name=PickupMesh Scale3D=(X=1.0, Y=1.0, Z=1.0) CollideActors=true BlockNonZeroExtent=true End Object Components.Add(PickupMesh) CollisionComponent=PickupMesh bCollideActors = true bBlockActors = false CollisionType = COLLIDE_TouchAll }
And then all you have to do is extend off of that and add the relevant skeletal mesh properties in the defaultproperties of the child class and assign the item type to that variable I mentioned earlier. For example, here is the the red key card pickup class.
class SW_RedKeyCardPickup extends SW_Pickup; defaultproperties { PickupType = "RedKeyCard" Begin Object Name=PickupMesh SkeletalMesh=SkeletalMesh'SW_Meshes.KeyCard.KeyCard' Materials(0)=Material'SW_Meshes.KeyCard.RedKeyCard_Mat' AnimSets(0)=AnimSet'SW_Meshes.KeyCard.KeyCard_Anim' AnimTreeTemplate=AnimTree'SW_Meshes.KeyCard.KeyCard_AnimTree' PhysicsAsset=PhysicsAsset'SW_Meshes.KeyCard.KeyCard_Physics' End Object }

Adding To My Inventory

Adding it to the inventory was really simple. Since the inventory can hold a maximum of 3 items I didn't need to implement a grand inventory manager. For simplicity I assigned each pickup that could be added to the inventory a number instead of trying to save a class into the array, or something overly complex like that. I could have done a string, but I end up using the id number when updating the HUD. Here are the functions that manage my small inventory:
exec function AddItem(int ItemID) { local int i; if(ItemList.length < 3) { i = ItemList.length; ItemList.length = ItemList.length + 1; ItemList[i] = ItemID; HUDGFx.UpdateItems(); } else { MyLog("ItemList is full", 'AddItem'); } } function bool CheckForItem(int ItemID, out int FoundItemID) { local int i; local bool bHaveItem; bHaveItem = false; for(i = 0; i < ItemList.length; i++) { if(ItemList[i] == ItemID) { bHaveitem = true; FoundItemID = i; } } return bHaveItem; } //This would be used like this in whatever function needs the check //If not being called from this class, get PC reference like normal /* local int FoundID; if(CheckForItem(1, FoundID)) //If we have a keycard (ID 1) { RemoveItem(FoundID); //Insert the rest of the code that happens if they have the keycard } */ exec function RemoveItem(int ItemID) { ItemList.Remove(ItemID, 1); HUDGFx.UpdateItems(); }

Updating the HUD

Now that I have all of that in order I have to update the HUD to show which items I have in my inventory. As I do more and more Scaleform projects I try and migrate as much code as I can from AS3 to Unrealscript, since Unrealscript runs faster than AS3. Since I will be spawning movieclips directly from Unrealscript I have to keep a reference to them in order to adjust them or delete them. To help manage my references I decided to make my AttachMovie function a bit more dynamic on what parameters are passed. The first step was to create an array that holds the linkage names(to match the ones in Flash) and the desired instance names for all of the different item types that can be added to the inventory. The element number then corresponds to the ID I gave the items when I added them to the inventory. Here is how I have the AttachMovie and the reference array set up:
var struct ItemInfo { var string LinkageName; //Name used in Flash var string InstanceName; //Desired Instance Name } ItemReference; //ItemSlot[0] holds the id number of the item assigned to that spot. ItemOneSlot.AttachMovie(ItemReference[ItemList[0]].LinkageName, ItemReference[ItemList[0]].InstanceName); ItemOneMC = GetVariableObject("_root.itemOneSlot_mc." $ ItemReference[ItemList[0]].InstanceName); //In the defualt properties ItemReference[1] = (LinkageName = "redKeyCard_item", InstanceName = "redKeyCard") ItemReference[2] = (LinkageName = "blueKeyCard_item", InstanceName = "blueKeyCard")

CheckForItem Kismet Node

Since I like using Kismet for setting up triggers and other level specific things I needed a way to check if I had the correct item before the actual action could be executed. For instance, if they have the red keycard when trying to lower the force field. If they don't have it they shouldn't be able to lower it. So I made a custom Kistmet node that calls my check inventory function in my PlayerController class(see above), then outputs the correct result. I wanted to be able to set which item was being checked and also if I wanted it to be removed when the check was made. If I had like a master key card or something that could be used over and over again I wouldn't want it to be removed from my inventory. Anyway, here is my Kismet node:
class SeqCond_CheckForItem extends SequenceCondition; var bool bResult; var int ItemID; /**Remove the item if found? */ var(Items) bool bRemove; /**Expected Item Type*/ var(Items) enum ItemTypes { ITEM_RedKeyCard, ITEM_BlueKeyCard } ExpectedItem; event Activated() { local SpaceWingsPlayerController PC; PC = SpaceWingsPlayerController(class'WorldInfo'.static.GetWorldInfo().Game.GetALocalPlayerController()); bResult = PC.CheckForItem(ExpectedItem + 1, ItemID); if(bResult && bRemove) { PC.RemoveItem(ItemID); } //If the check result is true, activate the first output link, else the second OutputLinks[(bResult == true) ? 0 : 1].bHasImpulse = true; } defaultproperties { ObjName="CheckForItem" ObjCategory="SpaceWings" bRemove = true InputLinks(0)=(LinkDesc="In") OutputLinks(0)=(LinkDesc="True") OutputLinks(1)=(LinkDesc="False") VariableLinks(0)=(ExpectedType=class'SeqVar_Bool',LinkDesc="Result",bWriteable=true,PropertyName=bResult) }

Wow, this post ended up being a lot longer than I had anticipated. I was going to throw up a video of the pickups and HUD in action, but that will have to wait until later. Time to work!

Wednesday, February 5, 2014

Returns and Removing Children

Hello everyone!

I don't really have much to report on Winds of Commerce, I wrapped up the transaction list/receipts feature. When you bring up the receipts menu it will show you a list of all the cities you've been to, what day of the journey you visited it on, and how much you spent or earned there. You can then click on a city in the list and it will bring up an itemized list of what commodities you purchased/sold, how much you spent/earned on each commodity, and how much you spent on purchasing information.

The next thing I have to tackle is the navigation system. Right now I'm using exec functions to simulate going between cities. This will probably be the biggest system I've had to tackle developing this game. Unfortunately, before I can even start coding I have to get the routes figured out. That way I know how many days away each city is from one another and try and make the shortest route to each city. The hard part is trying to make it logical. Each time I get a route down I look at it and think, "Is that the most efficient route to that city?" then proceed to convince myself it isn't... and redo it again!

Returns


While I was working on getting this game put together I ran into how to use returns in a function. I had only used them a handful of times before, and didn't quite know how to use them. I knew you had to have 'return SomeVariable;' but I guess the usefulness didn't really hit me. Since I read more about them and did some tests I have started to use them more. I find them very useful for doing calculations, conversions, or simply checking if a function has completed running.
Setting up a function to return something is really simple, though it is different in Unrealscript and AS3. In Unrealscript the function setup looks like this:
function ReturnType FunctionName() { local ReturnType SomeVar; //Set SomeVar return SomeVar; }

Here is an example of a function that returns an int:

function int GetSum(int A, int B) { local int Sum; Sum = A + B; return Sum; } //To call use it Total = GetSum(5, 10); //GetSum would return 15

The return type can be any of the standard variable types: bool, int, string, array, and even a class. An example of a class being returned can be found in the GameInfo class, with the SetGameType function. This function returns the GameInfo class to use for the game.
static event class<GameInfo> SetGameType(string MapName, string Options, string Portal) { return Default.Class; }

A bool return can be useful if used in an if statement to make sure that function has ran completely before moving on with the if statement. An example of this is in a lot of the bot AI code that is floating around the internet. It is being used to make sure that a path has been found or not, basically:
if(FindPath()) { //Commence moving }

Return functions work the same in AS3, just with the different declaration. Here is how you would declare a retunr funciton in AS3:
function functionName():ReturnType { var someVar:ReturnType; //Set someVar return someVar; }

Speaking of ActionScript, in my last post I mentioned the different ways to call a function in AS3 from Unrealscript(ActionScriptVoid, ActionScriptBool, AsctionScriptInt, and so on). These are there to allow you to receive a return value from your AS3 function. For instance, if you had the GetSum function in AS3 and needed to call it from Unrealscript it would look like this:
//In AS3 function getSum(a:Number, b:Number):Number { var sum:Number; sum = a + b; return sum; } //In Unrealscript Total = ActionScriptInt("_root.getSum");

Now you have several examples of how to use a function to return a value!

Removing Children


The next code bit I found extends what I talked about in my last post with the removeChild function. Sometimes it is necessary to remove all the children from a MovieClip, and since there isn't a function for removeAllChildren there is a work around using a for loop. It's pretty simple, you get the number of children in the MovieClip, then go backwards through the children and remove them one at a time. Here is an example of what I'm talking about:

for (var i:int = container_mc.numChildren-1; i >= 0; i--) { container_mc.removeChildAt(i); }
I think that is all I have for you this week. Hopefully by my next update I'll have all of the routes figured out.

Saturday, January 25, 2014

Chuggin' Along - Winds of Commerce

Hey guys!

Just a quick update on Winds of Commerce. I've been steadily getting components of the code done. I recently finished up opening and filling the information page which will give you a random amount of information about the city you click on. From there you can purchase additional information if you'd like. I also decided to add a transaction list to the game, that way you can look back and see how much you spent, or made, at a given city and on what day that was on. It will also show you the net profit from each city.

While I have completed quite a few things, I still have a lot of work to do with the menus, choosing the starting options, and the end game.

Here is a neat bit of code I found while doing all of this that would have made some of my previous projects a little smoother. This allows you to create a movieclip in Flash, from Unrealscript. This helps because you then have an easier reference to dynamically created objects than you would spawning them through AS3. Here is the code to add the movie:
//In your custom GFxMovieplayer class var GFxObject RootMC, TestMC; RootMC = GetVariableObject("_root"); RootMC.AttachMovie("mySymbol", "myInstanceName"); TestMC = GetVariableObject("_root.myInstanceName");

This part of the code is pretty self explanatory. The function AttachMovie takes 4 parameters, but only two are required.
/** Attaches a symbol to specified movie instance. If no instance is found in this object's scope with the InstanceName, a new instance is created and returned */ native final function GFxObject AttachMovie(string symbolname, string instancename, optional int depth = -1, optional class<GFxObject> type = class'GFxObject');

The first parameter is the name of the linkage name you set in your Flash file.
The second is what you want the instance name to be of the newly created movieclip. You  can also set the depth of the new movie clip, or where it falls on the z-order in the SWF. The last parameter is what class to cast the return as, but I'm not entirely sure.

Now, even though they have a function to add a movieclip, they don't have one pre-built to remove one through Unrealscript. Matt Doyle, on the Epic Games forums, posted a work around(here) that works like a charm. First you'll need to create a new class extending from GFxObject. This will allow us to add the proper functions to remove the clip.
class GFxDisplayObject extends GFxObject; function RemoveChild(GFxObject childObject) { ActionScriptVoid("removeChild"); } defaultproperties { }

This will allow us to call the removeChild function easily on a movieclip cast to this class. When ActionScriptVoid(or similar, like ActionScriptBool, or ActionScriptObject) is called it will automatically pass whatever parameters are passed to the function that is calling it. In this case it will pass childObject onto the removeChild function in AS3. To actually make use of this you just need to add this line into your custom GFxMoviePlayer class:
//In your custom GFxMoviePlayer class GFxDisplayObject(TestMC.GetObject("parent", class'GFxDisplayObject')).RemoveChild(TestMC);

Here, you are grabbing the parent of the movieclip you want to remove, casting it into the custom GFxObject class you made, then calling the RemoveChild function of it, passing the desired movieclip. This line is really versatile since you don't have to set a hardcoded path to the object, since you are getting the parent.

Well enough rambling. hope this was helpful to someone.

Monday, January 6, 2014

And Now We're Back From Our Intermission!

Hey guys!

Sorry it's been so long, life has been hectic! Thankfully, my life has mellowed out a lot now, so I can get back on a regular updating schedule.

In the spare time I have had I've been dividing my time between working on that commerce game I mentioned in my last post, and helping a buddy with a game he's working on.

The premise of the trading game is you are the captain of a merchant ship. You can find more information here. You start off with a set amount of gold and you buy your first cargo with it. You then have a set amount of  'days' to go to different ports to try and make the greatest profit in that time. Each port, except the starting one will have randomized prices and quantities so each playthrough will be different. I've made some pretty good progress so far. I have the core system down for determining the value and quantity of the various goods, and I've almost finished up the information system in the game. This will allow you to get information on the different ports ahead of time, to help you plan. I still need to implement the actual buying and selling of goods though.

I've made a very simplistic mock up to give a representation of the game. To exit the trade and information windows just click them.


That's all I have for now. Once I get things a bit more organized I'll put up some interesting code bits, images, or something.