From 22c596f62a03ce25debeae6aca08cc62f01a0ec5 Mon Sep 17 00:00:00 2001
From: cybermind <iddqd_mail@mail.ru>
Date: Sun, 19 Feb 2012 22:03:29 +0600
Subject: [PATCH] Removed CommandSetResource action. In most cases it desynced
 the replays, and now there is another way to implement needed feature (it was
 added to make trading between players) through animations.

---
 src/action/actions.cpp          |  2 +-
 src/action/command.cpp          | 12 ------------
 src/game/replay.cpp             |  2 --
 src/include/actions.h           |  2 --
 src/include/commands.h          |  2 --
 src/include/network.h           |  3 +--
 src/network/commands.cpp        | 24 ------------------------
 src/stratagus/script_player.cpp |  2 +-
 8 files changed, 3 insertions(+), 46 deletions(-)

diff --git a/src/action/actions.cpp b/src/action/actions.cpp
index 223b9ab52..c6b299209 100644
--- a/src/action/actions.cpp
+++ b/src/action/actions.cpp
@@ -693,7 +693,7 @@ static void SetPlayerData(int player, const char *prop, const char *arg, int val
 
 		for (int i = 0; i < MaxCosts; ++i) {
 			if (res == DefaultResourceNames[i]) {
-				SendCommandSetResource(Players[player].Index, i, value);
+				Players[player].SetResource(i,value);
 				return ;
 			}
 		}
diff --git a/src/action/command.cpp b/src/action/command.cpp
index 1db30be44..378f7599c 100644
--- a/src/action/command.cpp
+++ b/src/action/command.cpp
@@ -842,18 +842,6 @@ void CommandDiplomacy(int player, int state, int opponent)
 	// FIXME: Should we display a message?
 }
 
-/**
-**  Set new resources count for player.
-**
-**  @param player    Player which changes his state.
-**  @param resource     Resource index
-**  @param value  New value
-*/
-void CommandSetResource(int player, int resource, int value)
-{
-	Players[player].SetResource(resource, value);
-}
-
 /**
 **  Shared vision changed.
 **
diff --git a/src/game/replay.cpp b/src/game/replay.cpp
index 8e975b0cc..99d08e55b 100644
--- a/src/game/replay.cpp
+++ b/src/game/replay.cpp
@@ -886,8 +886,6 @@ static void DoNextReplay()
 			state = -1;
 		}
 		SendCommandDiplomacy(arg1, state, arg2);
-	} else if (!strcmp(action, "set-resource")) {
-		SendCommandSetResource(arg1, num, arg2);
 	} else if (!strcmp(action, "shared-vision")) {
 		bool state;
 		state = atoi(val) ? true : false;
diff --git a/src/include/actions.h b/src/include/actions.h
index 4b2989893..5f1bb8dbb 100644
--- a/src/include/actions.h
+++ b/src/include/actions.h
@@ -312,8 +312,6 @@ extern void CommandSpellCast(CUnit &unit, const Vec2i &pos, CUnit *dest, SpellTy
 extern void CommandAutoSpellCast(CUnit &unit, int spellid, int on);
 	/// Prepare diplomacy command
 extern void CommandDiplomacy(int player, int state, int opponent);
-	/// Prepare set resources command
-extern void CommandSetResource(int player, int resource, int value);
 	/// Prepare shared vision command
 extern void CommandSharedVision(int player, bool state, int opponent);
 
diff --git a/src/include/commands.h b/src/include/commands.h
index 81a703064..4783f08c4 100644
--- a/src/include/commands.h
+++ b/src/include/commands.h
@@ -101,8 +101,6 @@ extern void SendCommandCancelResearch(CUnit &unit);
 extern void SendCommandSpellCast(CUnit &unit, const Vec2i &pos, CUnit *dest, int spellid, int flush);
 	/// Send auto spell cast command
 extern void SendCommandAutoSpellCast(CUnit &unit, int spellid, int on);
-	/// Send set resource command
-extern void SendCommandSetResource(int player, int resource, int value);
 	/// Send diplomacy command
 extern void SendCommandDiplomacy(int player, int state, int opponent);
 	/// Send shared vision command
diff --git a/src/include/network.h b/src/include/network.h
index c5f974f93..0d030c62d 100644
--- a/src/include/network.h
+++ b/src/include/network.h
@@ -107,8 +107,7 @@ enum _message_type_ {
 */
 enum _extended_message_type_ {
 	ExtendedMessageDiplomacy,     /// Change diplomacy
-	ExtendedMessageSharedVision,   /// Change shared vision
-	ExtendedMessageSetResource     /// Change resource count
+	ExtendedMessageSharedVision   /// Change shared vision
 };
 
 /**
diff --git a/src/network/commands.cpp b/src/network/commands.cpp
index 851c95658..558f23bfb 100644
--- a/src/network/commands.cpp
+++ b/src/network/commands.cpp
@@ -494,25 +494,6 @@ void SendCommandDiplomacy(int player, int state, int opponent)
 	}
 }
 
-/**
-** Send command: Diplomacy changed.
-**
-** @param player     Player which changes his resource.
-** @param resource   Resource type.
-** @param value      New resource value.
-*/
-void SendCommandSetResource(int player, int resource, int value)
-{
-	if (!IsNetworkGame()) {
-		CommandLog("set-resource", NoUnitP, 0, player, value,
-					NoUnitP, NULL, resource);
-		CommandSetResource(player, resource, value);
-	} else {
-		NetworkSendExtendedCommand(ExtendedMessageSetResource,
-			-1, player, resource, value, 0);
-	}
-}
-
 /**
 ** Send command: Shared vision changed.
 **
@@ -783,11 +764,6 @@ void ParseExtendedCommand(unsigned char type, int status,
 			}
 			CommandDiplomacy(arg2, arg3, arg4);
 			break;
-		case ExtendedMessageSetResource:
-			CommandLog("set-resource", NoUnitP, 0, arg2, arg4,
-						NoUnitP, NULL, arg3);
-			CommandSetResource(arg2, arg3, arg4);
-			break;
 		case ExtendedMessageSharedVision:
 			if (arg3 == 0) {
 				CommandLog("shared-vision", NoUnitP, 0, arg2, arg4,
diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp
index e4920fb3b..157a0c84f 100644
--- a/src/stratagus/script_player.cpp
+++ b/src/stratagus/script_player.cpp
@@ -930,7 +930,7 @@ static int CclSetPlayerData(lua_State *l)
 		if (i == MaxCosts) {
 			LuaError(l, "Invalid resource \"%s\"" _C_ res.c_str());
 		}
-		SendCommandSetResource(p->Index,i,LuaToNumber(l, 4));
+		p->SetResource(i,LuaToNumber(l, 4));
 // } else if (!strcmp(data, "UnitTypesCount")) {
 // } else if (!strcmp(data, "AiEnabled")) {
 // } else if (!strcmp(data, "TotalNumUnits")) {