| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Getting Started with Coding

This version was saved 4 years, 5 months ago View current version     Page history
Saved by James Koppel
on May 24, 2016 at 10:46:08 pm
 
This page has an associated video tutorial, Modding with an Iron Fist: Episode 4: Modding the Code ( http://www.youtube.com/watch?v=dFTT0id4Iz0 )
 
Getting a development environment set up is never a picnic, especially not for a project as advanced as Ironfist. This tutorial aims to remove as much of the pain as possible.
Our code interacts with the code of the original game at the binary level, and we're stuck using Microsoft tools as a result of some of the features we use to do this. 

 

What You'll Need

 

  • A checked-out repository (see Setting up the Repository)
  • Microsoft Visual Studio (free versions should do, but make sure they have C++)

 

Setup 

 

We have now started distributing the Visual Studio Project file in the repository. Simply go to your local copy of the repository, and open the ironfist/ironfist/ironfist.vcxproj file in Visual Studio. You should be able to immediately compile the project. The map editor should work similarly, but with ironfist/editor_vs/editor_vs.vcxproj instead.

 

One issue is that, for some reason, all files will be displayed in one giant unorganized list, even though the actual files are organized in a nice hierarchy. Fixing this is on the to-do list, but we'll do it sooner if you complain.  And, of course, please complain if you have any other problems.

 

Guidelines

 

Follow the Google C++ Style guide's recommendation for formatting,  https://google.github.io/styleguide/cppguide.html#Formatting . The exception is that lines may exceed 80 characters.

 

When transporting code from the decompilation into Ironfist, apply the "Does this look like code I would have written myself?" test. Decompiled code has a lot of features that are hard to read that are seldom seen in human-written code, such as gotos, lots of pointer arithmetic, automatically-generated variable names, etc. It's important to clean this up before merging it into the Ironfist codebase.

 

For includes: Have your includes from standard libraries, 3rd party libraries, and Ironfist code in three separate sections, separated by whitespace. Within each section, have all includes in alphabetical order.

 

Strings

 

The game relies exclusively on C-style strings, but std:string, although it has problems, is generally much more pleasant to work with. Here's our compromise:

 

  • char* ‘s mayo be used when they are simply passed from one function to the next, including the common case of just passing a string literal to DisplayMessage. However, if any manipulation is performed on that string, the surrounding code must use C++ strings
  • Commonly-used API functions such as H2Message should be overloaded to also accept an std:string
  • Except for special exceptions, method that need to return strings will return the actual values (not pointers/references) so as not to worry about memory management, favoring ease of use over efficiency

  • Data structures taken from the original game will continue to use character arrays as fields unless all dependence of the original code on that field or its size have been eliminated. We will not make an active effort to do this at all possible places

 

 

Workflow

 

Ask to be added as a contributor to the Ironfist repository in Github. When adding a new feature to Ironfist, use this workflow in git:

 

  1. Create a new branch in git, named <your initials>-<name of feature>. So, for example, if James Koppel wants to write the code for a "first strike" creature ability, he would run the command git checkout -b jk-first-strike
  2. Write all your code and commit it to this branch. Be sure to commit often, preferably each distinct chunk of work, to make following the history easy.
  3. When you're done, use git push to upload your code to Github, go to the Github website, and create a pull request against the master branch
  4. Ask your teammates for a code review, and make more commits to respond to any feedback they may have
  5. Once you have gotten the thumbs up, merge in your changes. Congrats -- your code is in the game! 

 

Configure Creature Secondary Resource Cost

 

To configure a creature's secondary resource cost, edit the file in DATA/creatures.xml. Simply add an xml element named "secondary-cost" inside the element for that creature. For example. to set ore as the secondary cost for greater druid:

 

 <creature id="26" name-singular="greater druid" name-plural="greater druids" icn="druid2.icn" frm="druidfrm.bin" cost="400" fight-value="1428" fight-value-aux="36" growth="3" hp="25" faction="2" speed="6" attack="7" defense="7" shots="16" short-name="drui">

        <damage minimum="5" maximum="8"/>

        <creature-attribute name="shoots"/>

        <random-spawn minimum="10" maximum="20"/>

 </creature>

 

Add an element 

 

<secondary-cost resource="ore" cost="25"/>

 

inside this creature element:

 

 <creature id="26" name-singular="greater druid" name-plural="greater druids" icn="druid2.icn" frm="druidfrm.bin" cost="400" fight-value="1428" fight-value-aux="36" growth="3" hp="25" faction="2" speed="6" attack="7" defense="7" shots="16" short-name="drui">

        <damage minimum="5" maximum="8"/>

        <creature-attribute name="shoots"/>

        <random-spawn minimum="10" maximum="20"/>

        <secondary-cost resource="ore" cost="25"/> 

 </creature>

 

Then it will cost you 400 gold plus 24 ore to recruit one greater druid. Available secondary resource names are "wood", "mercury", "ore", "sulfur", "crystal", "gems".

 

Some creatures (Genie, Phoenix, Cyclops, Green Dragon, Black Dragon, Giant and Titan) already have default secondary cost. If you add a secondary resource cost for one of these creatures, it will override the default one.

 

Right now, ironfist only support one secondary resource cost per creature. You will expect to see an error message window pops up at startup if you assign more than one secondary resources to a single creature.

 

 

 

 

 

 

 

 

Comments (0)

You don't have permission to comment on this page.