shithub: cstory

Download patch

ref: 905ae02d77e87923d534ef72ef61c845cdbd0e28
parent: 687f02119f20e0b5ec77a5fbc3360281aa1086ba
parent: 113c3fc124268633663c454f465459ad1c8172a3
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Jan 31 13:42:19 EST 2019

Merge branch 'master' of https://github.com/cuckydev/Cave-Story-Engine-2

--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -441,7 +441,7 @@
 	ClearArmsData();
 	ClearItemData();
 	ClearPermitStage();
-	//StartMapping();
+	StartMapping();
 	InitFlags();
 	InitBossLife();
 	
--- a/src/GenericLoad.cpp
+++ b/src/GenericLoad.cpp
@@ -1,5 +1,7 @@
 #include "CommonDefines.h"
 #include "Draw.h"
+#include "Sound.h"
+#include "PixTone.h"
 
 bool LoadGenericData()
 {
@@ -51,6 +53,34 @@
 		MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1);
 		MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2);
 		MakeSurface_Generic(WINDOW_WIDTH, 240, SURFACE_ID_CREDIT_CAST);
+		
+		char path[0x100];
+		uint8_t *buf = nullptr;
+		size_t len;
+			
+		for (unsigned int n = 0; n < SOUND_NO; n++)
+		{
+			sprintf(path, "%2.2X.pxt", n);
+			
+			if (LoadPxt(path, &buf, &len))
+			{
+				lpSECONDARYBUFFER[n] = new SOUNDBUFFER(len);
+				
+				uint8_t *sBuf;
+				size_t sLen;
+				lpSECONDARYBUFFER[n]->Lock(&sBuf, &sLen);
+				memcpy(sBuf, buf, sLen);
+				lpSECONDARYBUFFER[n]->Unlock();
+				lpSECONDARYBUFFER[n]->SetFrequency(22050);
+			}
+			
+			//Free buffer, we're done with it
+			if (buf)
+			{
+				free(buf);
+				buf = nullptr;
+			}
+		}
 		return true;
 	}
 }
--- a/src/MiniMap.cpp
+++ b/src/MiniMap.cpp
@@ -1,3 +1,5 @@
+#include <stdint.h>
+
 #include "WindowsWrapper.h"
 
 #include "CommonDefines.h"
@@ -7,9 +9,12 @@
 #include "Game.h"
 #include "KeyControl.h"
 #include "Map.h"
+#include "Stage.h"
 #include "MyChar.h"
 #include "Main.h"
 
+int8_t gMapping[0x80];
+
 void WriteMiniMapLine(int line)
 {
 	RECT rcLevel[4];
@@ -170,4 +175,19 @@
 	}
 
 	return 1;
-}
\ No newline at end of file
+}
+
+bool IsMapping()
+{
+	return gMapping[gStageNo] != 0;
+}
+
+void StartMapping()
+{
+	memset(gMapping, 0, 0x80u);
+}
+
+void SetMapping(int a)
+{
+	gMapping[a] = 1;
+}
--- a/src/MiniMap.h
+++ b/src/MiniMap.h
@@ -1,2 +1,9 @@
 #pragma once
+#include <stdint.h>
+
+extern int8_t gMapping[0x80];
+
 int MiniMapLoop();
+bool IsMapping();
+void StartMapping();
+void SetMapping(int a);
--- a/src/PixTone.cpp
+++ b/src/PixTone.cpp
@@ -10,6 +10,7 @@
 #include "PixTone.h"
 
 int8_t gWaveModelTable[6][0x100];
+bool wave_tables_made;
 
 void MakeWaveTables()
 {
@@ -72,6 +73,13 @@
 
 bool MakePixelWaveData(const std::vector<double>& pxtData, uint8_t *data)
 {
+	//Make wave tables if not created already
+	if (!wave_tables_made)
+	{
+		MakeWaveTables();
+		wave_tables_made = true;
+	}
+	
 	//Get some envelope stuff
 	char envelopeTable[0x100];
 	memset(envelopeTable, 0, sizeof(envelopeTable));
--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -9,6 +9,7 @@
 #include "Fade.h"
 #include "ArmsItem.h"
 #include "Flags.h"
+#include "MiniMap.h"
 #include "MyChar.h"
 #include "Frame.h"
 #include "ValueView.h"
@@ -101,7 +102,7 @@
 	memcpy(gArmsData, profile.arms, sizeof(gArmsData));
 	memcpy(gItemData, profile.items, sizeof(gItemData));
 	//memcpy(gPermitStage, profile.permitstage, 0x40u);
-	//memcpy(gMapping, profile.permit_mapping, 0x80u);
+	memcpy(gMapping, profile.permit_mapping, 0x80);
 	memcpy(gFlagNPC, profile.flags, 1000);
 	
 	//Load stage
@@ -149,7 +150,7 @@
 	ClearArmsData();
 	ClearItemData();
 	ClearPermitStage();
-	//StartMapping();
+	StartMapping();
 	InitFlags();
 	if (!TransferStage(13, 200, 10, 8))
 		return false;
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -268,38 +268,6 @@
 	
 	//Start organya
 	StartOrganya();
-	
-	//Load sound effects
-	MakeWaveTables();
-	
-	char path[0x100];
-	uint8_t *buf = nullptr;
-	size_t len;
-		
-	for (unsigned int n = 0; n < SOUND_NO; n++)
-	{
-		sprintf(path, "%2.2X.pxt", n);
-		
-		if (LoadPxt(path, &buf, &len))
-		{
-			lpSECONDARYBUFFER[n] = new SOUNDBUFFER(len);
-			
-			uint8_t *sBuf;
-			size_t sLen;
-			lpSECONDARYBUFFER[n]->Lock(&sBuf, &sLen);
-			memcpy(sBuf, buf, sLen);
-			lpSECONDARYBUFFER[n]->Unlock();
-			lpSECONDARYBUFFER[n]->SetFrequency(22050);
-		}
-		
-		//Free buffer, we're done with it
-		if (buf)
-		{
-			free(buf);
-			buf = nullptr;
-		}
-	}
-	
 	return true;
 }
 
--- a/src/Stage.h
+++ b/src/Stage.h
@@ -12,6 +12,8 @@
 	char name[0x20];
 };
 
+extern int gStageNo;
+
 bool TransferStage(int no, int w, int x, int y);
 void ChangeMusic(int no);
 void ReCallMusic();
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -16,6 +16,7 @@
 #include "Flags.h"
 #include "Profile.h"
 #include "Map.h"
+#include "MiniMap.h"
 #include "MapName.h"
 #include "KeyControl.h"
 #include "NpChar.h"
@@ -677,7 +678,18 @@
 						y = GetTextScriptNo(gTS.p_read + 9);
 						AddPermitStage(x, y);
 						gTS.p_read += 13;
+					else if (IS_COMMAND('M','P','+'))
+					{
+						x = GetTextScriptNo(gTS.p_read + 4);
+						SetMapping(x);
+						gTS.p_read += 8;
 					}
+					else if (IS_COMMAND('U','N','I'))
+					{
+						z = GetTextScriptNo(gTS.p_read + 4);
+						ChangeMyUnit(z);
+						gTS.p_read += 8;
+					}
 					else if (IS_COMMAND('T','R','A'))
 					{
 						z = GetTextScriptNo(gTS.p_read + 4);
@@ -867,6 +879,41 @@
 						else
 							gTS.p_read += 13;
 					}
+					else if (IS_COMMAND('U','N','J'))
+					{
+						x = GetTextScriptNo(gTS.p_read + 4);
+						z = GetTextScriptNo(gTS.p_read + 9);
+						if (GetUnitMyChar() == x)
+							JumpTextScript(z);
+						else
+							gTS.p_read += 13;
+					}
+					else if (IS_COMMAND('E','C','J'))
+					{
+						x = GetTextScriptNo(gTS.p_read + 4);
+						z = GetTextScriptNo(gTS.p_read + 9);
+						if (GetNpCharAlive(x))
+							JumpTextScript(z);
+						else
+							gTS.p_read += 13;
+					}
+					else if (IS_COMMAND('E','C','J'))
+					{
+						x = GetTextScriptNo(gTS.p_read + 4);
+						z = GetTextScriptNo(gTS.p_read + 9);
+						if (IsNpCharCode(x))
+							JumpTextScript(z);
+						else
+							gTS.p_read += 13;
+					}
+					else if (IS_COMMAND('M','P','J'))
+					{
+						x = GetTextScriptNo(gTS.p_read + 4);
+						if (IsMapping())
+							JumpTextScript(x);
+						else
+							gTS.p_read += 8;
+					}
 					else if (IS_COMMAND('S','S','S'))
 					{
 						x = GetTextScriptNo(gTS.p_read + 4);
@@ -949,6 +996,17 @@
 					{
 						ReCallMusic();
 						gTS.p_read += 4;
+					}
+					else if (IS_COMMAND('M','L','P'))
+					{
+						gTS.p_read += 4;
+						bExit = true;
+						
+						int tscRet = MiniMapLoop();
+						if (tscRet == 0)
+							return 0;
+						if (tscRet == 2)
+							return 2;
 					}
 					else if (IS_COMMAND('S','L','P'))
 					{