shithub: cstory

Download patch

ref: 0d8179e98c886cb82bc47845b3654dcaec71ebb6
parent: a6f65f66a6b6384138b655d6a6ad2dc915d59efe
parent: 50ca5e37a2bb6e3f86f4a1d6963eb223119a99ee
author: Cucky <[email protected]>
date: Sat Jan 26 06:07:22 EST 2019

Merge pull request #12 from Clownacy/master

Makefile, readme, and NPC000 improvements

--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,18 @@
-RELEASE = 0
-
-ifeq ($(RELEASE), 0)
-CXXFLAGS := -O0 -g -static -mconsole
-FILENAME := debug
-else
-CXXFLAGS := -O3 -s -static
+ifeq ($(RELEASE), 1)
+CXXFLAGS := -O3 -s
 FILENAME := release
+else
+CXXFLAGS := -O0 -g -mconsole
+FILENAME := debug
 endif
 
 ifeq ($(JAPANESE), 1)
 CXXFLAGS += -DJAPANESE
-	ifeq ($(RELEASE), 0)
-	FILENAME := debugjp
-	else
+LIBS += -liconv
+	ifeq ($(RELEASE), 1)
 	FILENAME := releasejp
+	else
+	FILENAME := debugjp
 	endif
 endif
 
@@ -22,8 +21,13 @@
 endif
 
 CXXFLAGS += `sdl2-config --cflags` `pkg-config freetype2 --cflags`
-LIBS += `sdl2-config --static-libs` -lfreetype -lharfbuzz -lfreetype -lbz2 -lpng -lz -lgraphite2 -lRpcrt4 -lDwrite -lusp10 -liconv
+LIBS += `sdl2-config --static-libs` `pkg-config freetype2 --libs`
 
+ifeq ($(STATIC), 1)
+CXXFLAGS += -static
+LIBS += -lharfbuzz -lfreetype -lbz2 -lpng -lz -lgraphite2 -lRpcrt4 -lDwrite -lusp10
+endif
+
 # For an accurate result to the original's code, compile in alphabetical order
 SOURCES = \
 	Back \
@@ -130,9 +134,9 @@
 
 OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES)))
 
-all: build/$(FILENAME).exe
+all: build/$(FILENAME)
 
-build/$(FILENAME).exe: $(OBJECTS)
+build/$(FILENAME): $(OBJECTS)
 	@mkdir -p $(@D)
 	@g++ $(CXXFLAGS) $^ -o $@ $(LIBS)
 	@echo Finished compiling: $@
@@ -147,12 +151,12 @@
 	@echo Compiling $<
 	@g++ $(CXXFLAGS) $< -o $@ -c
 
-src/Resource/%.h: res/% obj/bin2h.exe
+src/Resource/%.h: res/% obj/bin2h
 	@mkdir -p $(@D)
 	@echo Converting $<
-	@obj/bin2h.exe $< $@
+	@obj/bin2h $< $@
 
-obj/bin2h.exe: res/bin2h.c
+obj/bin2h: res/bin2h.c
 	@mkdir -p $(@D)
 	@echo Compiling $^
 	@gcc -O3 -s -static $^ -o $@
--- a/README.md
+++ b/README.md
@@ -1,20 +1,22 @@
 # Cave Story Engine 2
-I'm rewriting Cave Story Engine from scratch, to be more accurate than before!
 
-Cave Story Engine is a recompilation of Cave Story (freeware release), also porting it from DirectX to SDL2
+Cave Story Engine is an in-progress decompilation of Cave Story (freeware release), ported from DirectX to SDL2.
 
 ![Screenshot](screenshot.png)
 
-How to build:
+## Dependencies
 
-Create "build" directory
+This project currently depends on SDL2 and Freetype2.
 
-cd to the base directory,
+## Building
 
-make (RELEASE=1 for release build)
+Just run 'make' in the base directory, preferably with some of the following optional settings:
 
+* RELEASE=1 to compile a release build (optimised, stripped, etc.)
+* STATIC=1 to produce a statically-linked executable (good for Windows builds)
+* JAPANESE=1 to enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)
+* FIX_BUGS=1 to fix certain bugs (see [src/Bug Fixes.txt](https://github.com/cuckydev/Cave-Story-Engine-2/blob/master/src/Bug%20Fixes.txt))
 
+## Licensing
 
-JAPANESE=1 to enable certain Japanese differences
-
-FIX_BUGS=1 to fix certain bugs (see src/Bug Fixes.txt)
+Being a decompilation, the majority of the code in this project belongs to Daisuke "Pixel" Amaya - not us. We've yet to agree on a license for our own code.
--- a/src/NpChar.cpp
+++ b/src/NpChar.cpp
@@ -43,23 +43,23 @@
 {
 	char path[PATH_LENGTH];
 	sprintf(path, "%s/%s", gDataPath, path_event);
-	
+
 	SDL_RWops *fp = SDL_RWFromFile(path, "rb");
 	if (!fp)
 		return false;
-	
+
 	//Read "PXE" check
 	char code[4];
 	fp->read(fp, code, 1, 4);
 	if (memcmp(code, gPassPixEve, 3))
 		return false;
-	
-	//Get amount of npcs
+
+	//Get amount of NPCs
 	int count = SDL_ReadLE32(fp);
-	
-	//Load npcs
+
+	//Load NPCs
 	memset(gNPC, 0, sizeof(gNPC));
-	
+
 	int n = 170;
 	for (int i = 0; i < count; i++)
 	{
@@ -71,7 +71,7 @@
 		eve.code_event = SDL_ReadLE16(fp);
 		eve.code_char = SDL_ReadLE16(fp);
 		eve.bits = SDL_ReadLE16(fp);
-		
+
 		//Set NPC parameters
 		if (eve.bits & npc_altDir)
 			gNPC[n].direct = 2;
@@ -86,7 +86,7 @@
 		gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits;
 		gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp;
 		SetUniqueParameter(&gNPC[n]);
-		
+
 		//Check flags
 		if (gNPC[n].bits & npc_appearSet)
 		{
@@ -102,11 +102,11 @@
 		{
 			gNPC[n].cond = 0x80;
 		}
-		
+
 		//Increase index
 		n++;
 	}
-	
+
 	return true;
 }
 
@@ -144,7 +144,7 @@
 		int offset_y = Random(-wa, wa) << 9;
 		SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 0, NULL, 0x100);
 	}
-	
+
 	//Flash effect
 	//SetCaret(x, y, 12, 0);
 }
@@ -159,7 +159,7 @@
 		int offset_y = Random(-wa, wa) << 9;
 		SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 1, NULL, 0x100);
 	}
-	
+
 	//Flash effect
 	//SetCaret(x, y, 12, 0);
 }
@@ -171,7 +171,7 @@
 		if (!gNPC[n].cond)
 		{
 			memset(&gNPC[n], 0, sizeof(NPCHAR));
-			
+
 			int sub_exp = 0;
 			if (exp < 20)
 			{
@@ -194,7 +194,7 @@
 				exp -= 20;
 				sub_exp = 20;
 			}
-			
+
 			gNPC[n].cond |= 0x80u;
 			gNPC[n].direct = 0;
 			gNPC[n].code_char = 1;
@@ -222,10 +222,10 @@
 		else
 			tamakazu_ari[t] = 0;
 	}
-	
+
 	if (!t)
 		return false;
-	
+
 	int n = Random(1, 10 * t);
 	int bullet_no = tamakazu_ari[n % t];
 	for (n = 0x100; n < NPC_MAX; n++)
@@ -245,7 +245,7 @@
 			return true;
 		}
 	}
-	
+
 	return false;
 }
 
@@ -267,7 +267,7 @@
 			return true;
 		}
 	}
-	
+
 	return false;
 }
 
@@ -294,7 +294,7 @@
 		if (gNPC[n].cond & 0x80)
 		{
 			int8_t a;
-			
+
 			if (gNPC[n].shock)
 			{
 				a = 2 * ((gNPC[n].shock >> 1) & 1) - 1;
@@ -308,13 +308,13 @@
 					gNPC[n].damage_view = 0;
 				}
 			}
-			
+
 			int side;
 			if (gNPC[n].direct)
 				side = gNPC[n].view.back;
 			else
 				side = gNPC[n].view.front;
-			
+
 			PutBitmap3(
 				&grcGame,
 				(gNPC[n].x - side) / 0x200 - fx / 0x200 + a,
--- a/src/NpcAct000.cpp
+++ b/src/NpcAct000.cpp
@@ -10,14 +10,18 @@
 //Null
 void ActNpc000(NPCHAR *npc)
 {
+	RECT rect[1];
+	rect[0] = {0x00, 0x00, 0x10, 0x10};
+
 	if (!npc->act_no)
 	{
 		npc->act_no = 1;
+
 		if (npc->direct == 2)
 			npc->y += 0x2000;
 	}
-	
-	npc->rect = {0, 0, 16, 16};
+
+	npc->rect = rect[0];
 }
 
 //Experience
@@ -31,11 +35,11 @@
 			//Set state
 			npc->act_no = 1;
 			npc->ani_no = Random(0, 4);
-			
+
 			//Random speed
 			npc->xm = Random(-0x200, 0x200);
 			npc->ym = Random(-0x400, 0);
-			
+
 			//Random direction (reverse animation or not)
 			if (Random(0, 1) != 0)
 				npc->direct = 0;
@@ -42,23 +46,23 @@
 			else
 				npc->direct = 2;
 		}
-		
+
 		//Gravity
 		if (npc->flag & 0x100)
 			npc->ym += 21;
 		else
 			npc->ym += 42;
-		
+
 		//Bounce off walls
 		if (npc->flag & 1 && npc->xm < 0)
 			npc->xm = -npc->xm;
 		if (npc->flag & 4 && npc->xm > 0)
 			npc->xm = -npc->xm;
-		
+
 		//Bounce off ceiling
 		if (npc->flag & 2 && npc->ym < 0)
 			npc->ym = -npc->ym;
-		
+
 		//Bounce off floor
 		if (npc->flag & 8)
 		{
@@ -66,7 +70,7 @@
 			npc->ym = -0x280;
 			npc->xm = 2 * npc->xm / 3;
 		}
-		
+
 		//Play bounce song (and try to clip out of floor if stuck)
 		if (npc->flag & 0xD)
 		{
@@ -78,7 +82,7 @@
 		{
 			npc->count2 = 0;
 		}
-		
+
 		//Limit speed
 		if (npc->xm < -0x5FF)
 			npc->xm = -0x5FF;
@@ -96,23 +100,23 @@
 		{
 			//Set state
 			npc->act_no = 1;
-			
+
 			//Set random speed
 			npc->ym = Random(-0x80, 0x80);
 			npc->xm = Random(0x7F, 0x100);
 		}
-		
+
 		//Blow to the left
 		npc->xm -= 8;
-		
+
 		//Destroy when off-screen
 		if (npc->x <= 0x9FFF)
 			npc->cond = 0;
-		
+
 		//Limit speed (except pixel applied it to the X position)
 		if (npc->x < -0x5FF)
 			npc->x = -0x5FF;
-		
+
 		//Bounce off walls
 		if (npc->flag & 1)
 			npc->xm = 0x100;
@@ -121,11 +125,11 @@
 		if (npc->flag & 8)
 			npc->ym = -0x40;
 	}
-	
+
 	//Move
 	npc->x += npc->xm;
 	npc->y += npc->ym;
-	
+
 	//Get framerects
 	RECT rect[6];
 	rect[0] = {0x00, 0x10, 0x10, 0x20};
@@ -134,12 +138,12 @@
 	rect[3] = {0x30, 0x10, 0x40, 0x20};
 	rect[4] = {0x40, 0x10, 0x50, 0x20};
 	rect[5] = {0x50, 0x10, 0x60, 0x20};
-	
+
 	RECT rcNo = {0, 0, 0, 0};
-	
+
 	//Animate
 	++npc->ani_wait;
-	
+
 	if (npc->direct)
 	{
 		if (npc->ani_wait > 2)
@@ -155,9 +159,9 @@
 		if (++npc->ani_no > 5)
 			npc->ani_no = 0;
 	}
-	
+
 	npc->rect = rect[npc->ani_no];
-	
+
 	//Size
 	if (npc->act_no)
 	{
@@ -171,14 +175,14 @@
 			npc->rect.top += 32;
 			npc->rect.bottom += 32;
 		}
-		
+
 		npc->act_no = 1;
 	}
-	
+
 	//Delete after 500 frames
 	if (++npc->count1 > 500 && npc->ani_no == 5 && npc->ani_wait == 2)
 		npc->cond = 0;
-	
+
 	//Blink after 400 frames
 	if (npc->count1 > 400)
 	{
@@ -208,18 +212,18 @@
 	rcUp[4] = {96, 24, 128, 48};
 	rcUp[5] = {128, 24, 160, 48};
 	rcUp[6] = {160, 24, 192, 48};
-	
+
 	//Turn when touching a wall
 	if (npc->flag & 1)
 		npc->direct = 2;
 	else if (npc->flag & 4)
 		npc->direct = 0;
-	
+
 	switch (npc->act_no)
 	{
 		case 1: //Shot
 			npc->xm = 7 * npc->xm / 8;
-			
+
 			if (++npc->count1 > 40)
 			{
 				if (npc->shock)
@@ -242,19 +246,19 @@
 				npc->xm = 0x400;
 			else
 				npc->xm = -0x400;
-			
+
 			if (++npc->count1 > 200)
 			{
 				npc->act_no = 0;
 				npc->damage = 1;
 			}
-			
+
 			if (++npc->ani_wait > 5)
 			{
 				npc->ani_wait = 0;
 				++npc->ani_no;
 			}
-			
+
 			if (npc->ani_no > 6)
 				npc->ani_no = 5;
 			break;
@@ -263,16 +267,16 @@
 				npc->xm = 0x100;
 			else
 				npc->xm = -0x100;
-			
+
 			if (++npc->ani_wait > 8)
 			{
 				npc->ani_wait = 0;
 				++npc->ani_no;
 			}
-			
+
 			if (npc->ani_no > 3)
 				npc->ani_no = 0;
-			
+
 			if (npc->shock)
 			{
 				npc->count1 = 0;
@@ -281,16 +285,16 @@
 			}
 			break;
 	}
-	
+
 	//Gravity
 	npc->ym += 0x40;
 	if (npc->ym > 0x5FF)
 		npc->ym = 0x5FF;
-	
+
 	//Move
 	npc->x += npc->xm;
 	npc->y += npc->ym;
-	
+
 	//Set framerect
 	if (npc->direct)
 		npc->rect = rcUp[npc->ani_no];
@@ -303,7 +307,7 @@
 {
 	if (++npc->count1 > 100)
 		npc->cond = 0;
-	
+
 	npc->rect = {0, 0, 0, 0};
 }
 
@@ -312,7 +316,7 @@
 {
 	RECT rcLeft[8];
 	RECT rcUp[8];
-	
+
 	rcLeft[0] = {16, 0, 17, 1};
 	rcLeft[1] = {16, 0, 32, 16};
 	rcLeft[2] = {32, 0, 48, 16};
@@ -330,13 +334,13 @@
 	rcUp[5] = {48, 128, 64, 144};
 	rcUp[6] = {64, 128, 80, 144};
 	rcUp[7] = {80, 128, 96, 144};
-	
+
 	if (npc->act_no)
 	{
 		//Slight drag
 		npc->xm = 20 * npc->xm / 21;
 		npc->ym = 20 * npc->ym / 21;
-		
+
 		//Move
 		npc->x += npc->xm;
 		npc->y += npc->ym;
@@ -350,13 +354,13 @@
 			npc->xm = GetCos(deg) * Random(0x200, 0x5FF) / 0x200;
 			npc->ym = GetSin(deg) * Random(0x200, 0x5FF) / 0x200;
 		}
-		
+
 		//Set state
 		npc->ani_no = Random(0, 4);
 		npc->ani_wait = Random(0, 3);
 		npc->act_no = 1;
 	}
-	
+
 	//Animate
 	if (++npc->ani_wait > 4)
 	{
@@ -363,7 +367,7 @@
 		npc->ani_wait = 0;
 		npc->ani_no++;
 	}
-	
+
 	//Set framerect
 	if (npc->ani_no < 8)
 	{
@@ -390,17 +394,17 @@
 	rcLeft[0] = {0, 48, 16, 64};
 	rcLeft[1] = {16, 48, 32, 64};
 	rcLeft[2] = {32, 48, 48, 64};
-	
+
 	rcRight[0] = {0, 64, 16, 80};
 	rcRight[1] = {16, 64, 32, 80};
 	rcRight[2] = {32, 64, 48, 80};
-	
+
 	switch (npc->act_no)
 	{
 		case 0: //Init
 			npc->y += 0x600;
 			npc->act_no = 1;
-			
+
 		case 1: //Waiting
 			//Look at player
 			if (npc->x <= gMC.x)
@@ -407,7 +411,7 @@
 				npc->direct = 2;
 			else
 				npc->direct = 0;
-			
+
 			//Open eyes near player
 			if (npc->act_wait < 8 || npc->x - 0xE000 >= gMC.x || npc->x + 0xE000 <= gMC.x || npc->y - 0xA000 >= gMC.y || npc->y + 0xA000 <= gMC.y)
 			{
@@ -419,7 +423,7 @@
 			{
 				npc->ani_no = 1;
 			}
-			
+
 			//Jump if attacked
 			if (npc->shock)
 			{
@@ -427,7 +431,7 @@
 				npc->ani_no = 0;
 				npc->act_wait = 0;
 			}
-			
+
 			//Jump if player is nearby
 			if (npc->act_wait >= 8 && npc->x - 0x6000 < gMC.x && npc->x + 0x6000 > gMC.x && npc->y - 0xA000 < gMC.y && npc->y + 0x6000 > gMC.y)
 			{
@@ -436,7 +440,7 @@
 				npc->act_wait = 0;
 			}
 			break;
-			
+
 		case 2: //Going to jump
 			if (++npc->act_wait > 8)
 			{
@@ -443,11 +447,11 @@
 				//Set jump state
 				npc->act_no = 3;
 				npc->ani_no = 2;
-				
+
 				//Jump
 				npc->ym = -0x5FF;
 				PlaySoundObject(30, 1);
-				
+
 				//Jump in facing direction
 				if (npc->direct)
 					npc->xm = 0x100;
@@ -455,7 +459,7 @@
 					npc->xm = -0x100;
 			}
 			break;
-			
+
 		case 3: //Jumping
 			//Land
 			if (npc->flag & 8)
@@ -468,16 +472,16 @@
 			}
 			break;
 	}
-	
+
 	//Gravity
 	npc->ym += 64;
 	if (npc->ym > 0x5FF)
 		npc->ym = 0x5FF;
-	
+
 	//Move
 	npc->x += npc->xm;
 	npc->y += npc->ym;
-	
+
 	//Set framerect
 	if (npc->direct)
 		npc->rect = rcRight[npc->ani_no];