From 3571f23799feeed37b5577a310af596026182677 Mon Sep 17 00:00:00 2001
From: Stan_Lewry <stanley.jml@gmail.com>
Date: Fri, 30 Aug 2024 18:35:35 +0100
Subject: [PATCH] improved combat ui. temporarily disable enemy turn for debug

---
 combat.cpp | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/combat.cpp b/combat.cpp
index c2611d6..755988d 100644
--- a/combat.cpp
+++ b/combat.cpp
@@ -410,7 +410,7 @@ void actionSelectState(double delta) {
 			break;
 		case 1: // attack selected
 			if (activeCombatant->canAttack) {
-				// filter the targets
+				// filter the targets - Have to do it here too in case the player attacks without moving?
 				targets.clear();
 				for (auto& c : combatants) {
 					if (!c.allied && c.alive) {
@@ -489,6 +489,19 @@ void playerMoveActionState(double delta) {
 
 	}
 
+
+	// compute characters in melee range
+	targets.clear();
+	for (auto& c : combatants) {
+		if (!c.allied && c.alive) {
+			float dist = distance(moveCursorPos, c.position);
+			if (dist <= activeCombatant->basicAttackRange) {
+				targets.push_back(&c);
+			}
+		}
+	}
+
+
 	SDL_RenderClear(renderer);
 
 	renderTilemap(arena, arenaWidth, arenaHeight, combatCam);
@@ -506,9 +519,18 @@ void playerMoveActionState(double delta) {
 	SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
 	SDL_RenderDrawLine(renderer, playerCenterScreen.x, playerCenterScreen.y, lineEndPos.x, lineEndPos.y);
 
+	// render lines to targets in range
+	SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
+	for (auto t : targets) {
+		S2DE::Vec2<float> targetCenter = { t->position.x + 0.5, t->position.y + 0.5 };
+		S2DE::Vec2<int> targetCenterScreen = S2DE::worldToScreenPoint(&combatCam, &targetCenter, 64, WINDOW_WIDTH, WINDOW_HEIGHT);
+		SDL_RenderDrawLine(renderer, lineEndPos.x, lineEndPos.y, targetCenterScreen.x, targetCenterScreen.y);
+	}
+
+
 	renderCombatants();
 
-	S2DE::Rect cursorDRect = S2DE::worldToScreenRect(&combatCam, &moveCursorPos, 4, WINDOW_WIDTH, WINDOW_HEIGHT, 16, 16);
+	S2DE::Rect cursorDRect = S2DE::worldToScreenRect(&combatCam, &moveCursorPos, 2, WINDOW_WIDTH, WINDOW_HEIGHT, 32, 32);
 	S2DE::renderTexture(&renderer, &arrowSprite, NULL, &cursorDRect);
 
 	renderTilemap(fogLayer, arenaWidth, arenaHeight, combatCam); // draw the fog layer
@@ -557,18 +579,9 @@ void selectAttackTarget(double delta) {
 
 	renderTilemap(arena, arenaWidth, arenaHeight, combatCam);
 
-
-	S2DE::Vec2<float> playerCenterWorld = { activeCombatant->position.x + 0.5, activeCombatant->position.y + 0.5 };
-	S2DE::Vec2<int> playerCenterScreen = S2DE::worldToScreenPoint(&combatCam, &playerCenterWorld, 64, WINDOW_WIDTH, WINDOW_HEIGHT);
-
-	S2DE::renderCircle(&renderer, playerCenterScreen, (activeCombatant->basicAttackRange) * 64, { 255, 0, 0, 125 });
-
-
 	renderCombatants();
-	
 
 	// render the little red arrow above all valid targets
-	//for (auto target : targets) {
 	if (targets.size() > 0) {
 		S2DE::Vec2<float> arrowPos = targets.at(currentTargetIdx)->position;
 
@@ -576,7 +589,6 @@ void selectAttackTarget(double delta) {
 		S2DE::Rect arrowDRect = S2DE::worldToScreenRect(&combatCam, &arrowPos, 2, WINDOW_WIDTH, WINDOW_HEIGHT, 32, 32);
 		S2DE::renderTexture(&renderer, &indicatorRedSprite, NULL, &arrowDRect);
 	}
-	//}
 	
 
 	renderTilemap(fogLayer, arenaWidth, arenaHeight, combatCam); // draw the fog layer
@@ -703,7 +715,7 @@ void determineNextTurnState(double delta) {
 			currentCombatState = ACTION_SELECT;
 		}
 		else {
-			currentCombatState = ENEMY_MOVE;
+			//currentCombatState = ENEMY_MOVE;
 		}
 	}
 
-- 
2.20.1