From 1861c02819c9f25ff585382289b3ca0a4e78678e Mon Sep 17 00:00:00 2001
From: Clownacy <Clownacy@users.noreply.github.com>
Date: Sun, 27 Jan 2019 11:16:49 +0000
Subject: [PATCH 1/4] Added NPC016 (save point)

---
 src/NpcAct.h      |  2 ++
 src/NpcAct000.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 src/NpcTbl.cpp    |  2 +-
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/src/NpcAct.h b/src/NpcAct.h
index 1bb7e4ac..1932b594 100644
--- a/src/NpcAct.h
+++ b/src/NpcAct.h
@@ -6,3 +6,5 @@ void ActNpc003(NPCHAR *npc);
 void ActNpc004(NPCHAR *npc);
 void ActNpc005(NPCHAR *npc);
 void ActNpc006(NPCHAR *npc);
+
+void ActNpc016(NPCHAR *npc);
diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp
index 544d5c77..065090ca 100644
--- a/src/NpcAct000.cpp
+++ b/src/NpcAct000.cpp
@@ -614,3 +614,58 @@ void ActNpc006(NPCHAR *npc)
 	else
 		npc->rect = rcLeft[npc->ani_no];
 }
+
+//Save point
+void ActNpc016(NPCHAR *npc)
+{
+	RECT rects[8];
+
+	rects[0] = {96, 16, 112, 32};
+	rects[1] = {112, 16, 128, 32};
+	rects[2] = {128, 16, 144, 32};
+	rects[3] = {144, 16, 160, 32};
+	rects[4] = {160, 16, 176, 32};
+	rects[5] = {176, 16, 192, 32};
+	rects[6] = {192, 16, 208, 32};
+	rects[7] = {208, 16, 224, 32};
+
+	switch (npc->act_no)
+	{
+		case 0:
+			npc->bits |= 0x2000u;
+			npc->act_no = 1;
+
+			if (npc->direct == 2)
+			{
+				npc->bits &= ~0x2000u;
+				npc->ym = -0x200;
+
+				for (int i = 0; i < 4; ++i)
+					SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100);
+			}
+
+			// Fallthrough
+		case 1:
+			if (npc->flag & 8)
+				npc->bits |= 0x2000u;
+
+			break;
+	}
+
+	if ( ++npc->ani_wait > 2 )
+	{
+		npc->ani_wait = 0;
+		++npc->ani_no;
+	}
+
+	if ( npc->ani_no > 7 )
+		npc->ani_no = 0;
+
+	npc->ym += 0x40;
+	if ( npc->ym > 0x5FF )
+		npc->ym = 0x5FF;
+
+	npc->y += npc->ym;
+
+	npc->rect = rects[npc->ani_no];
+}
diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp
index ce5ab964..eaf87079 100644
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -72,7 +72,7 @@ NPCFUNCTION gpNpcFuncTbl[] =
 	nullptr,
 	nullptr,
 	nullptr,
-	nullptr,
+	&ActNpc016,
 	nullptr,
 	nullptr,
 	nullptr,

From 8056f42e9cbb0f7fab4db4344eb68a3b0c69e2d6 Mon Sep 17 00:00:00 2001
From: Clownacy <Clownacy@users.noreply.github.com>
Date: Sun, 27 Jan 2019 11:32:04 +0000
Subject: [PATCH 2/4] Added NPC017 (health refill)

---
 src/NpcAct.h      |  1 +
 src/NpcAct000.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++
 src/NpcTbl.cpp    |  2 +-
 3 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/src/NpcAct.h b/src/NpcAct.h
index 1932b594..78124aa7 100644
--- a/src/NpcAct.h
+++ b/src/NpcAct.h
@@ -8,3 +8,4 @@ void ActNpc005(NPCHAR *npc);
 void ActNpc006(NPCHAR *npc);
 
 void ActNpc016(NPCHAR *npc);
+void ActNpc017(NPCHAR *npc);
diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp
index 065090ca..69bd23fc 100644
--- a/src/NpcAct000.cpp
+++ b/src/NpcAct000.cpp
@@ -669,3 +669,82 @@ void ActNpc016(NPCHAR *npc)
 
 	npc->rect = rects[npc->ani_no];
 }
+
+// Health refill
+void ActNpc017(NPCHAR *npc)
+{
+	RECT rect[2];
+
+	rect[0] = {288, 0, 304, 16};
+	rect[1] = {304, 0, 320, 16};
+
+	int aa;
+
+	switch (npc->act_no)
+	{
+		case 0:
+			npc->act_no = 1;
+
+			if (npc->direct == 2)
+			{
+				npc->ym = -512;
+
+				for (int a = 0; a < 4; ++a)
+					SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100);
+			}
+
+			// Fallthrough
+		case 1:
+			aa = Random(0, 30);
+
+			if (aa >= 10)
+			{
+				if (aa >= 25)
+					npc->act_no = 4;
+				else
+					npc->act_no = 3;
+			}
+			else
+			{
+				npc->act_no = 2;
+			}
+
+			npc->act_wait = Random(0x10, 0x40);
+			npc->ani_wait = 0;
+			break;
+
+		case 2:
+			npc->rect = rect[0];
+
+			if (--npc->act_wait == 0)
+				npc->act_no = 1;
+
+			break;
+
+		case 3:
+			if (++npc->ani_wait % 2)
+				npc->rect = rect[0];
+			else
+				npc->rect = rect[1];
+
+			if (--npc->act_wait == 0)
+				npc->act_no = 1;
+
+			break;
+
+		case 4:
+			npc->rect = rect[1];
+
+			if (--npc->act_wait == 0)
+				npc->act_no = 1;
+
+			break;
+	}
+
+	npc->ym += 0x40;
+
+	if (npc->ym > 0x5FF)
+		npc->ym = 0x5FF;
+
+	npc->y += npc->ym;
+}
diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp
index eaf87079..16d111cd 100644
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -73,7 +73,7 @@ NPCFUNCTION gpNpcFuncTbl[] =
 	nullptr,
 	nullptr,
 	&ActNpc016,
-	nullptr,
+	&ActNpc017,
 	nullptr,
 	nullptr,
 	nullptr,

From ce34eea2dc1822d0fe4e6b0e1cff5d23f64bd1bf Mon Sep 17 00:00:00 2001
From: Clownacy <Clownacy@users.noreply.github.com>
Date: Sun, 27 Jan 2019 11:32:48 +0000
Subject: [PATCH 3/4] Change how gpNpcFuncTable is done

The '&'s are pointless
---
 src/NpcTbl.cpp | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp
index 16d111cd..320ca33a 100644
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -56,13 +56,13 @@ void ReleaseNpcTable()
 //Npc function table
 NPCFUNCTION gpNpcFuncTbl[] =
 {
-	&ActNpc000,
-	&ActNpc001,
-	&ActNpc002,
-	&ActNpc003,
-	&ActNpc004,
-	&ActNpc005,
-	&ActNpc006,
+	ActNpc000,
+	ActNpc001,
+	ActNpc002,
+	ActNpc003,
+	ActNpc004,
+	ActNpc005,
+	ActNpc006,
 	nullptr,
 	nullptr,
 	nullptr,
@@ -72,8 +72,8 @@ NPCFUNCTION gpNpcFuncTbl[] =
 	nullptr,
 	nullptr,
 	nullptr,
-	&ActNpc016,
-	&ActNpc017,
+	ActNpc016,
+	ActNpc017,
 	nullptr,
 	nullptr,
 	nullptr,

From 27cfd5a575d9ac60594556c0a1770211e99a5d24 Mon Sep 17 00:00:00 2001
From: Clownacy <Clownacy@users.noreply.github.com>
Date: Sun, 27 Jan 2019 12:18:21 +0000
Subject: [PATCH 4/4] Added NPC015, NPC018, and NPC020 (chest close, door, and
 chest open)

---
 Makefile          |  1 +
 src/NpcAct.h      |  4 +++
 src/NpcAct000.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++
 src/NpcAct020.cpp | 29 ++++++++++++++++
 src/NpcTbl.cpp    |  6 ++--
 5 files changed, 122 insertions(+), 3 deletions(-)
 create mode 100644 src/NpcAct020.cpp

diff --git a/Makefile b/Makefile
index c48567eb..43037d3d 100644
--- a/Makefile
+++ b/Makefile
@@ -55,6 +55,7 @@ SOURCES = \
 	MyChar \
 	MycHit \
 	NpcAct000 \
+	NpcAct020 \
 	NpChar \
 	NpcHit \
 	NpcTbl \
diff --git a/src/NpcAct.h b/src/NpcAct.h
index 78124aa7..6da5916a 100644
--- a/src/NpcAct.h
+++ b/src/NpcAct.h
@@ -7,5 +7,9 @@ void ActNpc004(NPCHAR *npc);
 void ActNpc005(NPCHAR *npc);
 void ActNpc006(NPCHAR *npc);
 
+void ActNpc015(NPCHAR *npc);
 void ActNpc016(NPCHAR *npc);
 void ActNpc017(NPCHAR *npc);
+void ActNpc018(NPCHAR *npc);
+
+void ActNpc021(NPCHAR *npc);
diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp
index 69bd23fc..260d541c 100644
--- a/src/NpcAct000.cpp
+++ b/src/NpcAct000.cpp
@@ -615,6 +615,63 @@ void ActNpc006(NPCHAR *npc)
 		npc->rect = rcLeft[npc->ani_no];
 }
 
+//Chest (closed)
+void ActNpc015(NPCHAR *npc)
+{
+	RECT rcLeft[3];
+
+	rcLeft[0] = {240, 0, 256, 16};
+	rcLeft[1] = {256, 0, 272, 16};
+	rcLeft[2] = {272, 0, 288, 16};
+
+	switch (npc->act_no)
+	{
+		case 0:
+			npc->act_no = 1;
+			npc->bits |= 0x2000u;
+
+			if (npc->direct == 2)
+			{
+				npc->ym = -0x200;
+
+				for (int i = 0; i < 4; ++i)
+					SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100);
+			}
+
+			// Fallthrough
+		case 1:
+			npc->ani_no = 0;
+
+			if (Random(0, 30) == 0)
+				npc->act_no = 2;
+
+			break;
+
+		case 2:
+			if (++npc->ani_wait > 1)
+			{
+				npc->ani_wait = 0;
+				++npc->ani_no;
+			}
+
+			if (npc->ani_no > 2)
+			{
+				npc->ani_no = 0;
+				npc->act_no = 1;
+			}
+
+			break;
+	}
+
+	npc->ym += 0x40;
+	if (npc->ym > 0x5FF)
+		npc->ym = 0x5FF;
+
+	npc->y += npc->ym;
+
+	npc->rect = rcLeft[npc->ani_no];
+}
+
 //Save point
 void ActNpc016(NPCHAR *npc)
 {
@@ -748,3 +805,31 @@ void ActNpc017(NPCHAR *npc)
 
 	npc->y += npc->ym;
 }
+
+// Door
+void ActNpc018(NPCHAR *npc)
+{
+	RECT rect[2];
+
+	rect[0] = {224, 16, 240, 40};
+	rect[1] = {192, 112, 208, 136};
+
+	switch (npc->act_no)
+	{
+		case 0:
+			if (npc->direct == 0)
+				npc->rect = rect[0];
+			else
+				npc->rect = rect[1];
+
+			break;
+
+		case 1:
+			for (int i = 0; i < 4; ++i)
+				SetNpChar(4, npc->x, npc->y, Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100);
+
+			npc->act_no = 0;
+			npc->rect = rect[0];
+			break;
+	}
+}
\ No newline at end of file
diff --git a/src/NpcAct020.cpp b/src/NpcAct020.cpp
new file mode 100644
index 00000000..9a1c0808
--- /dev/null
+++ b/src/NpcAct020.cpp
@@ -0,0 +1,29 @@
+#include "WindowsWrapper.h"
+
+#include "MyChar.h"
+#include "NpChar.h"
+#include "Game.h"
+#include "Sound.h"
+#include "Back.h"
+#include "Triangle.h"
+
+//Chest (open)
+void ActNpc021(NPCHAR *npc)
+{
+	switch (npc->act_no)
+	{
+		case 0:
+			npc->act_no = 1;
+
+			if (npc->direct == 2)
+				npc->y += 0x2000;
+
+			break;
+	}
+
+	RECT rect[0];
+
+	rect[0]	= {224, 40, 240, 48};
+
+	npc->rect = rect[0];
+}
diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp
index 320ca33a..6ee7f722 100644
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -71,13 +71,13 @@ NPCFUNCTION gpNpcFuncTbl[] =
 	nullptr,
 	nullptr,
 	nullptr,
-	nullptr,
+	ActNpc015,
 	ActNpc016,
 	ActNpc017,
+	ActNpc018,
 	nullptr,
 	nullptr,
-	nullptr,
-	nullptr,
+	ActNpc021,
 	nullptr,
 	nullptr,
 	nullptr,