git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@10084 c06c8d41-db1a-0410-9941-cceddc491573
CAQIQYLQWP2NWLTLMSUOQ5R7HH2QZGZNIHQINATB6RG2BBIMJFMQC How to Write a Patch====================The following is a rough guide on how to write patches to the code. It ismeant to make writing patches easier to inexperienced programmers, butfollowing these steps does not guarantee that any patch will actually beaccepted - that depends entirely on content.Also, we're talking about Stonesoup here, but the principle could be applied toany other program as well. :)Required tools--------------At the very least you'll need the source code, and some helpful programs likediff and grep. The latter come preinstalled with Unix, whereas Windows userswill have to download and install them. This may be a bit of work, but istotally worth it if you're programming a lot. You can get them at e.g.http://gnuwin32.sourceforge.net/packages/diffutils.htmhttp://gnuwin32.sourceforge.net/packages/grep.htmMain steps----------0.) If you're not interested in coding or have no intention of compiling thegame, you can still submit patches for the documentation, descriptionsor vaults. In that case, simply ignore the steps relating to compilationand coding. You don't even need the source code for that, instead you cansimply use the binary distributation that also contains the relevanttext files.1.) Get the source code, either from the most recent release(http://sourceforge.net/projects/crawl-ref/files/) or use SVN to get thecurrent trunk:svn co https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk/crawl-ref trunk2.) Compile the code. To do this you might have to install a compiler and/oradditional libraries. See INSTALL.txt for details. If you have anyquestions, you can ask for help on crawl-ref-discuss@lists.sourceforge.net.3.) Once you've got everything set up, you should copy the folder containingthe files you're going to change, i.e. docs/, dat/descript/ or the entiresource/ folder, as appropriate. This is done so you can later easily createthe patch against the original version.4.) Now you can start tweaking the code. Depending on your coding backgroundyou may want to experiment with smaller changes first. If you intend tosubmit the patch to the dev team, please skim coding_conventions.txt.Following these guidelines will save us some time later when integratingthe patch.5.) Compile again to test your changes.6.) Once everything works as it should, you can use diff or git to create apatch out of the differences between the two folders, e.g.diff -ur trunk-orig trunk-new > mypatch.diffYou may want to apply the patch against the unmodified folder to testwhether everything worked correctly.7.) Upload the patch on the patch tracker of Sourceforge. Here it is immenselyhelpful if you give a summary of what the patch is about. If you createdit in response to a bug report or feature request, mention the id, and youmight also want to post a reply in said item pointing out your new patch.Please also mention the revision/version you used for patching, e.g. 0.5or r10078, and anything you think still may need to be improved ormodified.Thank you! :DTips----Tip 1: The code is rougly divided into files according to functionality thatis reflected in the file names, so monstuff.cc, mon-util.cc andmstuff2.cc all handle code relating to monsters, while spl-data.h,spl-cast.cc and spells2.cc deal with spells. Note that related code canstill be found in other files, too, but these are a good starting point.Tip 2: Start out with the simple, generic stuff where you only have to copyand minimally tweak existing code, and only once that works move on tothe more complicated implementations.Tip 3: Use grep to find all occurences of a similar instance of the same typeas the one you're implementing, e.g.grep GOD_ELYVILON *.cc when adding a new god, orgrep SCR_FOG *.cc when adding a new scroll.That way you'll be able to repurpose a lot of code for your newimplementation, and it also helps cut down on coding errors.Example-------I want to add a spell that creates some kind of clouds. The first similar spellI can think of is Mephitic Cloud. I know that this spell is defined asSPELL_MEPHITIC_CLOUD (and if I didn't know I could find out by grepping for"Mephitic Cloud"), so I type (within the source folder)grep SPELL_MEPHITIC_CLOUD *.h andgrep SPELL_MEPHITIC_CLOUD *.cc... which tells me that code regarding this spell turns up in enum.h (itsdeclaration), mon-spll.h (monsters "casting" the spell), spl-data.h (thedefinition), and ghost.cc (monster spell), it_use3.cc (some kind of misc.item, maybe), mstuff2.cc (helpfully with a comment mentioning swampdrakes), spl-book.cc (spellbooks that contain this spell), and spl-cast.cc(actually casting the spell).That gives me some ideas on where to start looking at code to duplicatefor my new spell. I'd start out with the basics, the declaration anddefinition, copying all values from Mephitic Cloud and only changing theSPELL_xxxx tag. Then I add the new spell to the list in spl-cast.cc, at whichpoint I'll also notice that Mephitic Cloud uses a function calledstinking_cloud() and that various other cloud spells (helpfully sorted byeffect type) use functions like cast_big_c() and others. Using grep I canquickly find out that both functions are declared in spells1.h, meaning theirdefinitions can be found in spells1.cc.stinking_cloud() contains a definition of a beam that defines damage andsuch. The various properties are not self-explanatory but they're also nottotally obscure, so you should be able to find out a lot about them by justfiddling with the values. In particular, beam.flavour is set to somethingcalled BEAM_POTION_STINKING_CLOUD which looks interesting enough to checkout, so I grep the source (*.h and *.cc) for all occurences and have a lookat all files this turns up. And so on.Evaluating and prioritising the findings takes some experience with the sourcecode but even if you have no idea what the files are likely to contain usinggrep still greatly reduces the number of files you have to look at. To findthe code you're interested in search the files for the same keyword you usedfor grepping.Good luck with your patch! If you have any questions, don't hesitate to ask.Thank you for your support!
static void replace_area( int sx, int sy, int ex, int ey,dungeon_feature_type replace,dungeon_feature_type feature, unsigned mapmask){[...]}
static void replace_area(int sx, int sy, int ex, int ey,dungeon_feature_type replace,dungeon_feature_type feature, unsigned mapmask){[...]}
If a logical connective needs to be distributed over several lines,the conjunction/disjunction operators (&&, ||) should be placed at the
If a logical connective needs to be distributed over several lines,the conjunction/disjunction operators (&&, ||) should be placed at the
Since conjunctions (&&) take precedence over disjunctions (||), pureconjunctive logical connectives don't need to be bracketed, unless this is
Since conjunctions (&&) take precedence over disjunctions (||), pureconjunctive logical connectives don't need to be bracketed, unless this is
In a row of if-else if-statements or in a switch-case loop, the optional bracesshould be used if the bigger part of statements needs braces for logicalreasons or because of one of the conventions above. Otherwise, they may be
In a row of if-else if-statements or in a switch-case loop, the optional bracesshould be used if the bigger part of statements needs braces for logicalreasons or because of one of the conventions above. Otherwise, they may be
for (int x = 0; x < GXM; x++)for (int y = 0; y < GYM; y++){if (grd[x][y] == DNGN_LAVA)lava_spaces++;if (grd[x][y] == DNGN_DEEP_WATER || grd[x][y] == NGN_SHALLOW_WATER)water_spaces++;}
for (int x = 0; x < GXM; x++)for (int y = 0; y < GYM; y++){if (grd[x][y] == DNGN_LAVA)lava_spaces++;if (grd[x][y] == DNGN_DEEP_WATER || grd[x][y] == NGN_SHALLOW_WATER)water_spaces++;}
If you feel that a method is complicated enough to be difficult to understand,or has restrictions or effects that might not be obvious, add explanatory
If you feel that a method is complicated enough to be difficult to understand,or has restrictions or effects that might not be obvious, add explanatory