From a6ddc5c5bcdbc18feb1c04d38b452d225dd7852b Mon Sep 17 00:00:00 2001
From: Treeki <treeki@gmail.com>
Date: Tue, 8 May 2012 02:43:37 +0200
Subject: I don't even remember what shit this commit contains

---
 src/koopatlas/camera.cpp      |  2 +-
 src/koopatlas/core.cpp        | 24 ++++++++++++----
 src/koopatlas/hud.cpp         | 66 +++++++++++++++++++++++++++++--------------
 src/koopatlas/hud.h           |  2 ++
 src/koopatlas/mapdata.h       |  2 +-
 src/koopatlas/pathmanager.cpp | 41 ++++++++++++++++++++++++++-
 src/koopatlas/pathmanager.h   |  2 ++
 7 files changed, 109 insertions(+), 30 deletions(-)

diff --git a/src/koopatlas/camera.cpp b/src/koopatlas/camera.cpp
index c13db56..1347c93 100644
--- a/src/koopatlas/camera.cpp
+++ b/src/koopatlas/camera.cpp
@@ -31,7 +31,7 @@ dWorldCamera_c::dWorldCamera_c() {
 
 	currentX = 416;
 	currentY = -224;
-	zoomLevel = 2.0f;
+	zoomLevel = 2.8f;
 }
 
 
diff --git a/src/koopatlas/core.cpp b/src/koopatlas/core.cpp
index 5e15d99..4a0d190 100644
--- a/src/koopatlas/core.cpp
+++ b/src/koopatlas/core.cpp
@@ -219,26 +219,33 @@ bool WMInit_SetupExtra(void *ptr) {
 		STKI_ITEM(wm->stockItem,i) = obj;
 	}
 
+	// need Player before we can set up paths
+	SpammyReport("creating player\n");
+	wm->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, wm, 0, 2);
+	wm->player->modelHandler->mdlClass->setPowerup(2);
+	wm->player->modelHandler->mdlClass->startAnimation(0, 1.2f, 10.0f, 0.0f);
+
 	// since we've got all the resources, set up the path data too
 	SpammyReport("preparing level info\n");
 	wm->levelInfo.load(wm->levelInfoLoader.buffer);
+	SpammyReport("preparing path manager\n");
 	wm->pathManager.setup();
 
-	// and now Player setup
-	wm->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, wm, 0, 2);
-	wm->player->modelHandler->mdlClass->setPowerup(2);
-	wm->player->modelHandler->mdlClass->startAnimation(0, 1.2f, 10.0f, 0.0f);
-
+	// and put the player into position
 	dKPNode_s *cNode = wm->pathManager.currentNode;
 	wm->player->pos = (Vec){cNode->x, -cNode->y, wm->player->pos.z};
 
 	// is last param correct? must check :/
+	SpammyReport("creating MAP\n");
 	wm->map = (dWMMap_c*)CreateParentedObject(WM_MAP, wm, 0, 0);
+	SpammyReport("creating HUD\n");
 	wm->hud = (dWMHud_c*)CreateParentedObject(WM_HUD, wm, 0, 0);
 	// note: world_camera is not created here
 	// because we require it earlier
 	// it is created in dScKoopatlas_c::onCreate
 
+	SpammyReport("SetupExtra done\n");
+
 	return true;
 }
 
@@ -249,6 +256,11 @@ bool WMInit_SetupWipe(void *ptr) {
 
 	if (wm->hasUninitialisedProcesses()) {
 		SpammyReport("WMInit_SetupWipe returning false\n");
+
+#ifdef WM_SPAMMY_DEBUGGING
+		fBase_c *p = wm->findNextUninitialisedProcess();
+		SpammyReport("Not done yet: %p [%d]\n", p, p->name);
+#endif
 		return false;
 	}
 
@@ -394,7 +406,7 @@ bool dScKoopatlas_c::canDoStuff() {
 int dScKoopatlas_c::onExecute() {
 	if (!canDoStuff()) return true;
 
-	SpammyReport("Executing state: %s\n", state.getCurrentState()->getName());
+	//SpammyReport("Executing state: %s\n", state.getCurrentState()->getName());
 	state.execute();
 
 	return true;
diff --git a/src/koopatlas/hud.cpp b/src/koopatlas/hud.cpp
index 531c3b1..c20f026 100644
--- a/src/koopatlas/hud.cpp
+++ b/src/koopatlas/hud.cpp
@@ -56,6 +56,9 @@ int dWMHud_c::onCreate() {
 
 		showPointBar();
 
+		if (dScKoopatlas_c::instance->pathManager.mustComplainToMapCreator)
+			dWMHud_c::instance->setText("Please Fix Your Missing Entrance. Thanks");
+
 		layoutLoaded = true;
 	}
 
@@ -88,30 +91,36 @@ void dWMHud_c::updateText() {
 }
 
 
-void dWMHud_c::setPointName() {
-	wchar_t newPointName[120];
-	int length;
+void dWMHud_c::setText(const char *str, int length) {
+	if (str == 0) {
+		setText("--NULL STRING--");
+		return;
+	}
 
-	// figure this out...
-	dKPNode_s *node = dScKoopatlas_c::instance->pathManager.currentNode;
+	if (length == -1) {
+		length = strlen(str);
+	}
 
-	if (node->type == dKPNode_s::LEVEL) {
-		dLevelInfo_c *li = &dScKoopatlas_c::instance->levelInfo;
-		dLevelInfo_c::entry_s *entry = li->search(node->levelNumber[0] - 1, node->levelNumber[1] - 1);
+	wchar_t newString[128];
 
-		const char *levelName = li->getNameForLevel(entry);
+	int i;
+	for (i = 0; i < length && i < 128; i++) {
+		newString[i] = str[i];
+	}
+	newString[i] = 0;
 
-		// copy it
-		// I need to make this into a function.
-		for (int i = 0; i < 120 && i < entry->nameLength; i++) {
-			newPointName[i] = levelName[i];
-		}
-		length = entry->nameLength;
-		newPointName[entry->nameLength] = 0;
+	setText(newString, i);
+}
 
-	} else {
-		newPointName[0] = 0;
-		length = 0;
+
+void dWMHud_c::setText(const wchar_t *str, int length) {
+	if (str == 0) {
+		setText("--NULL STRING--");
+		return;
+	}
+
+	if (length == -1) {
+		length = wcslen(str);
 	}
 
 	nw4r::lyt::TextBox *box = layout.findTextBoxByName("T_levelname_01");
@@ -124,14 +133,29 @@ void dWMHud_c::setPointName() {
 	if (box->tagProc != 0)
 		tw.tagProcessorMaybe = box->tagProc;
 
-	float width = tw.CalcStringWidth(newPointName, length);
+	float width = tw.CalcStringWidth(str, length);
 	SpammyReport("Text width: %f\n", width);
 
 	layout.findWindowByName("W_levelname")->size.x = width + 22;
 	layout.findPictureByName("P_topleftboxbg")->size.x = width;
 	layout.findPictureByName("P_topthinboxbg")->size.x = 597 - width;
 
-	box->SetString(newPointName);
+	box->SetString(str);
+}
+
+
+void dWMHud_c::setPointName() {
+	// figure this out...
+	dKPNode_s *node = dScKoopatlas_c::instance->pathManager.currentNode;
+
+	if (node->type == dKPNode_s::LEVEL) {
+		dLevelInfo_c *li = &dScKoopatlas_c::instance->levelInfo;
+		dLevelInfo_c::entry_s *entry = li->search(node->levelNumber[0] - 1, node->levelNumber[1] - 1);
+
+		setText(li->getNameForLevel(entry));
+	} else {
+		setText("");
+	}
 }
 
 
diff --git a/src/koopatlas/hud.h b/src/koopatlas/hud.h
index 1ef94ce..8d964c5 100644
--- a/src/koopatlas/hud.h
+++ b/src/koopatlas/hud.h
@@ -21,6 +21,8 @@ class dWMHud_c : public dBase_c {
 		void hidePointBar();
 
 		void setPointName();
+		void setText(const char *str, int length = -1);
+		void setText(const wchar_t *str, int length = -1);
 
 		static dWMHud_c *build();
 		static dWMHud_c *instance;
diff --git a/src/koopatlas/mapdata.h b/src/koopatlas/mapdata.h
index 913c933..ace1edd 100644
--- a/src/koopatlas/mapdata.h
+++ b/src/koopatlas/mapdata.h
@@ -67,7 +67,7 @@ struct dKPNode_s {
 	NodeTypes type;
 	union {
 		struct { u8 levelNumber[2]; };
-		struct { const char *destMap; u8 thisID, foreignID, transition; };
+		struct { const char *destMap; u8 thisID, foreignID, transition, _; };
 	};
 
 
diff --git a/src/koopatlas/pathmanager.cpp b/src/koopatlas/pathmanager.cpp
index 923d08c..632edfa 100644
--- a/src/koopatlas/pathmanager.cpp
+++ b/src/koopatlas/pathmanager.cpp
@@ -10,39 +10,57 @@ void dWMPathManager_c::setup() {
 
 	pathLayer = dScKoopatlas_c::instance->mapData.pathLayer;
 
+	SpammyReport("setting up PathManager\n");
 	SaveBlock *save = GetSaveFile()->GetBlock(-1);
 
+	mustComplainToMapCreator = false;
+
 	// Figure out what path node to start at
 	if (dScKoopatlas_c::instance->settings & 0x10000000) {
 		// Start off from a "Change"
 		u8 changeID = dScKoopatlas_c::instance->settings & 0xFF;
+		SpammyReport("entering at Change ID %d\n", changeID);
+		SpammyReport("Path layer: %p\n", pathLayer);
+		SpammyReport("Node count: %d\n", pathLayer->nodeCount);
 
 		bool found = false;
 
 		for (int i = 0; i < pathLayer->nodeCount; i++) {
 			dKPNode_s *node = pathLayer->nodes[i];
+			SpammyReport("Checking node: %p\n", node);
 
 			if (node->type == dKPNode_s::CHANGE && node->thisID == changeID) {
 				found = true;
 				currentNode = node;
 
-				startMovementTo(node->getAnyExit());
+				SpammyReport("a1 Node: %p\n", node);
+				dKPPath_s *exit = node->getAnyExit();
+				SpammyReport("a2 Exit: %p\n", exit);
+				startMovementTo(exit);
+				SpammyReport("a3\n");
+				break;
 			}
 		}
 
 		if (!found) {
 			OSReport("Couldn't find target node %d!\n", changeID);
+			currentNode = pathLayer->nodes[0];
+			mustComplainToMapCreator = true;
 		}
 		
 	} else {
+		SpammyReport("saved path node: %d\n", save->current_path_node);
 		if (save->current_path_node >= pathLayer->nodeCount) {
+			SpammyReport("out of bounds (%d), using node 0\n", pathLayer->nodeCount);
 			currentNode = pathLayer->nodes[0];
 		} else {
 			currentNode = pathLayer->nodes[save->current_path_node];
+			SpammyReport("OK %p\n", currentNode);
 		}
 	}
 
 	// unlock all needed paths
+	SpammyReport("Unlocking paths\n");
 	for (int i = 0; i < pathLayer->pathCount; i++) {
 		dKPPath_s *path = pathLayer->paths[i];
 
@@ -55,6 +73,7 @@ void dWMPathManager_c::setup() {
 				path->isAvailable = true;
 		}
 	}
+	SpammyReport("done\n");
 }
 
 
@@ -79,25 +98,37 @@ void dWMPathManager_c::execute() {
 
 
 void dWMPathManager_c::startMovementTo(dKPPath_s *path) {
+	SpammyReport("moving to path %p\n", path);
 	dWMHud_c::instance->hidePointBar();
+	SpammyReport("point bar hidden\n");
 
+	SpammyReport("a\n");
 	isMoving = true;
 	reverseThroughPath = (path->end == currentNode);
+	SpammyReport("b\n");
 
 	currentPath = path;
+	SpammyReport("c\n");
 
 	// calculate direction of the path
 	short deltaX = path->end->x - path->start->x;
 	short deltaY = path->end->y - path->start->y;
+	SpammyReport("d\n");
 	u16 direction = (u16)(atan2(deltaX, deltaY) / ((M_PI * 2) / 65536.0));
+	SpammyReport("e\n");
 
 	if (reverseThroughPath) {
+	SpammyReport("e2\n");
 		direction += 0x8000;
 	}
 
+	SpammyReport("f\n");
 	daWMPlayer_c *player = daWMPlayer_c::instance;
+	SpammyReport("g %p\n", player);
 	player->startAnimation(2, 2.0, 10.0, 0.0);
+	SpammyReport("h\n");
 	player->rot.y = direction;
+	SpammyReport("i\n");
 }
 
 void dWMPathManager_c::moveThroughPath() {
@@ -125,6 +156,8 @@ void dWMPathManager_c::moveThroughPath() {
    		player->pos.x = to->x;
    		player->pos.y = -to->y;
 
+   		SpammyReport("reached path end (%p)\n", to);
+
 		if (to->type == dKPNode_s::CHANGE) {
 			// Go to another map
 			isMoving = false;
@@ -132,20 +165,26 @@ void dWMPathManager_c::moveThroughPath() {
 			SaveBlock *save = GetSaveFile()->GetBlock(-1);
 			save->current_world = dScKoopatlas_c::instance->getIndexForMapName(to->destMap);
 
+			SpammyReport("Change to map ID %d (%s), entrance ID %d\n", save->current_world, to->destMap, to->foreignID);
+
 			DoSceneChange(WORLD_MAP, 0x10000000 | to->foreignID, 0);
 
 		} else if (to->type != dKPNode_s::PASS_THROUGH) {
 	   		// Stop here
 	   		player->startAnimation(0, 1.2, 10.0, 0.0);
 
+	   		SpammyReport("stopping here\n");
+
 	   		isMoving = false;
 
 			SaveBlock *save = GetSaveFile()->GetBlock(-1);
 			save->current_path_node = pathLayer->findNodeID(to);
 
 			dWMHud_c::instance->showPointBar();
+			SpammyReport("Point bar shown\n");
 		} else {
 			startMovementTo(to->getOppositeExitTo(currentPath));
+			SpammyReport("passthrough node, continuing to next path\n");
 		}
 	}
 }
diff --git a/src/koopatlas/pathmanager.h b/src/koopatlas/pathmanager.h
index 3ddcf58..c5a642c 100644
--- a/src/koopatlas/pathmanager.h
+++ b/src/koopatlas/pathmanager.h
@@ -23,6 +23,8 @@ class dWMPathManager_c {
 
 		dKPPath_s *currentPath;
 		bool reverseThroughPath; // direction we are going through the path
+
+		bool mustComplainToMapCreator;
 };
 
 #endif
-- 
cgit v1.2.3