Temple Termagant
Posts: 14
Joined: Sunday, 29th March 2015, 16:00
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!
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