Made my first patch - criticism, please! And what to do now?


Questions, Explanations, Howtos

Temple Termagant

Posts: 14

Joined: Sunday, 29th March 2015, 16:00

Post Saturday, 2nd May 2015, 11:04

Made my first patch - criticism, please! And what to do now?

Hi,

I just created my first patch for DCSS. It allows the player to check if an item is a corpse or a skeleton, if it has a skeleton and if it is zombifiable. I was told by a dev that exposing that information is alright, but I don't know if I'm doing it right on the technical side of things as I have very little experience in C++ and basically none contributing to a large project. So, can someone look it over, please? I'm fairly certain there are no real errors, and it works, but I'm for instance not certain if l_item.cc is the right place for this, if it's OK to include mon-util.h or if I used git right. Also, what to do now with the patch if it's acceptable in its current form?

Thanks for any advice!

  Code:
From 182b38b3c7ad8db4b16c70ee3eb58821ccc90afc Mon Sep 17 00:00:00 2001
From: (redacted)
Date: Sat, 2 May 2015 12:55:25 +0200
Subject: [PATCH] Make mons_skeleton() and mons_zombifiable() accessible in
 CLua

---
 crawl-ref/source/l_item.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/crawl-ref/source/l_item.cc b/crawl-ref/source/l_item.cc
index 0803f54..2a49a4a 100644
--- a/crawl-ref/source/l_item.cc
+++ b/crawl-ref/source/l_item.cc
@@ -24,6 +24,7 @@
 #include "item_use.h"
 #include "l_defs.h"
 #include "libutil.h"
+#include "mon-util.h"
 #include "output.h"
 #include "player.h"
 #include "prompt.h"
@@ -558,6 +559,46 @@ IDEF(can_cut_meat)
     return 1;
 }
 
+IDEF(is_corpse)
+{
+    if (!item || !item->defined())
+        return 0;
+
+    lua_pushboolean(ls, item && item->is_type(OBJ_CORPSES, CORPSE_BODY));
+
+    return 1;
+}
+
+IDEF(is_skeleton)
+{
+    if (!item || !item->defined())
+        return 0;
+
+    lua_pushboolean(ls, item && item->is_type(OBJ_CORPSES, CORPSE_SKELETON));
+
+    return 1;
+}
+
+IDEF(has_skeleton)
+{
+    if (!item || !item->defined())
+        return 0;
+
+    lua_pushboolean(ls, item && ( item->is_type(OBJ_CORPSES, CORPSE_BODY) && mons_skeleton(item->mon_type) || item->is_type(OBJ_CORPSES, CORPSE_SKELETON) ) );
+
+    return 1;
+}
+
+IDEF(can_zombify)
+{
+    if (!item || !item->defined())
+        return 0;
+
+    lua_pushboolean(ls, item && item->is_type(OBJ_CORPSES, CORPSE_BODY) && mons_zombifiable(item->mon_type));
+
+    return 1;
+}
+
 IDEF(is_preferred_food)
 {
     if (!item || !item->defined())
@@ -1256,6 +1297,10 @@ static ItemAccessor item_attrs[] =
     { "dropped",           l_item_dropped },
     { "is_melded",         l_item_is_melded },
     { "can_cut_meat",      l_item_can_cut_meat },
+    { "is_skeleton",       l_item_is_skeleton },
+    { "is_corpse",         l_item_is_corpse },
+    { "has_skeleton",      l_item_has_skeleton },
+    { "can_zombify",       l_item_can_zombify },
     { "is_preferred_food", l_item_is_preferred_food },
     { "is_bad_food",       l_item_is_bad_food },
     { "is_useless",        l_item_is_useless },
--
2.1.4

Dungeon Master

Posts: 634

Joined: Sunday, 22nd September 2013, 14:46

Post Sunday, 3rd May 2015, 02:28

Re: Made my first patch - criticism, please! And what to do

It looks good to me (admittedly I'm not an expert about the C++-Lua code interface).

You probably don't need to check item &&, since you already returned from the function if item is null, but that's just a small quibble.

We generally try to wrap lines to 80 characters -- check out https://github.com/crawl/crawl/blob/mas ... ntions.txt for rules like that. (edit: except I guess that isn't explicitly in the rules there, oops! anyway, that has the rules for how to indent logical operators etc.)

Also, when you're actually submitting a patch you should probably supply an actual name and email rather than just "redacted" -- it doesn't have to be your real name or your main email, just something to associate the patch with you, and to not muddle up the commit history with nameless authors.

Temple Termagant

Posts: 14

Joined: Sunday, 29th March 2015, 16:00

Post Sunday, 3rd May 2015, 04:46

Re: Made my first patch - criticism, please! And what to do

Thank you very much! I've fixed the code according to your post and those guidelines. And of course I'll supply a name and mail address, git is just using my main address at the moment and I didn't want to have that published.

Return to Coding

Who is online

Users browsing this forum: No registered users and 3 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.