From 711fc63b0c49e9d928a5f36ac368b312d20c1807 Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Fri, 18 Apr 2003 17:45:45 +0000
Subject: [PATCH] ChangeUnitOwner doesn't need oldplayer argument

---
 src/action/action_die.cpp       |  4 ++--
 src/include/unit.h              |  2 +-
 src/stratagus/script_player.cpp | 17 ++++++++++-------
 src/unit/unit.cpp               | 15 +++++++--------
 4 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/action/action_die.cpp b/src/action/action_die.cpp
index 7536927cd..9959b883c 100644
--- a/src/action/action_die.cpp
+++ b/src/action/action_die.cpp
@@ -10,7 +10,7 @@
 //
 /**@name action_die.c	-	The die action. */
 //
-//	(c) Copyright 1998,2000,2001 by Lutz Sammer
+//	(c) Copyright 1998,2000,2001,2003 by Lutz Sammer
 //
 //	FreeCraft is free software; you can redistribute it and/or modify
 //	it under the terms of the GNU General Public License as published
@@ -93,7 +93,7 @@ global void HandleActionDie(Unit* unit)
 	UnitShowAnimation(unit,unit->Type->Animations->Die);
 
 	// FIXME: perhaps later or never is better
-	//ChangeUnitOwner(unit,unit->Player,&Players[PlayerNumNeutral]);
+	//ChangeUnitOwner(unit,&Players[PlayerNumNeutral]);
     }
     UnitMarkSeen(unit);
 }
diff --git a/src/include/unit.h b/src/include/unit.h
index 0eb46340d..464a5637e 100644
--- a/src/include/unit.h
+++ b/src/include/unit.h
@@ -773,7 +773,7 @@ extern void UnitIncrementHealth(void);
     /// Check for rescue each second
 extern void RescueUnits(void);
     /// Change owner of unit
-extern void ChangeUnitOwner(Unit* unit,Player* old,Player* new);
+extern void ChangeUnitOwner(Unit* unit,Player* newplayer);
 
     /// Convert direction (dx,dy) to heading (0-255)
 extern int DirectionToHeading(int,int);
diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp
index 244872e06..855953442 100644
--- a/src/stratagus/script_player.cpp
+++ b/src/stratagus/script_player.cpp
@@ -286,24 +286,27 @@ local SCM CclPlayer(SCM list)
 }
 
 /**
-**	Change Unit Owner
+**	Change unit owner
 **
 **	@param pos1	top left tile
 **	@param pos2	bottom right tile
 **	@param old	old player number
 **	@param new	new player number
 **/
-local SCM CclChangeUnitsOwner(SCM pos1, SCM pos2, SCM old, SCM new)
+local SCM CclChangeUnitsOwner(SCM pos1, SCM pos2, SCM oldplayer, SCM newplayer)
 {
     Unit* table[UnitMax];
     int n;
+    int oldp;
+    int newp;
     
-    n = SelectUnits(gh_scm2int(gh_car(pos1)), gh_scm2int(gh_cadr(pos1)),
-		gh_scm2int(gh_car(pos2)), gh_scm2int(gh_cadr(pos2)), table);
+    n=SelectUnits(gh_scm2int(gh_car(pos1)), gh_scm2int(gh_cadr(pos1)),
+	    gh_scm2int(gh_car(pos2)), gh_scm2int(gh_cadr(pos2)), table);
+    oldp=gh_scm2int(oldplayer);
+    newp=gh_scm2int(newplayer);
     while( n ) {
-        if(table[n-1]->Player->Player == gh_scm2int(old)) {
-	    ChangeUnitOwner(table[n-1],&Players[gh_scm2int(old)],
-			&Players[gh_scm2int(new)]);
+        if( table[n-1]->Player->Player == oldp ) {
+	    ChangeUnitOwner(table[n-1],&Players[newp]);
 	}
 	n--;
     }
diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp
index 8580d3157..670eb8dfd 100644
--- a/src/unit/unit.cpp
+++ b/src/unit/unit.cpp
@@ -1708,25 +1708,24 @@ global void UnitIncrementHealth(void)
 **	Change the unit's owner
 **
 **	@param unit		Unit which should be consigned.
-**	@param oldplayer	Old owning player.
 **	@param newplayer	New owning player.
 **
 **	@todo	FIXME: I think here are some failures, if building is build
 **		what is with the unit inside? or a main hall with workers
 **		inside?
-**		Parameter old player is redunant?
 */
-global void ChangeUnitOwner(Unit* unit,Player* oldplayer,Player* newplayer)
+global void ChangeUnitOwner(Unit* unit,Player* newplayer)
 {
     int i;
+    Player* oldplayer;
 
-    DebugCheck( unit->Player!=oldplayer );
+    oldplayer=unit->Player;
 
     // For st*rcr*ft (dark archons),
     if( unit->Type->Transporter ) {
         for( i=0; i<MAX_UNITS_ONBOARD; i++) {
 	    if( unit->OnBoard[i] ) {
-	        ChangeUnitOwner(unit->OnBoard[i],oldplayer,newplayer);
+	        ChangeUnitOwner(unit->OnBoard[i],newplayer);
 	    }
 	}
     }
@@ -1811,7 +1810,7 @@ local void ChangePlayerOwner(Player* oldplayer,Player* newplayer)
     memcpy(table,oldplayer->Units,n*sizeof(Unit*));
     for( i=0; i<n; i++ ) {
 	unit=table[i];
-	ChangeUnitOwner(unit,oldplayer,newplayer);
+	ChangeUnitOwner(unit,newplayer);
 	unit->Blink=5;
 	unit->Rescued=1;
     }
@@ -1882,7 +1881,7 @@ global void RescueUnits(void)
 #endif
 		    if( around[i]->Type->CanAttack &&
 			    IsAllied(unit->Player,around[i]) ) {
-			ChangeUnitOwner(unit,unit->Player,around[i]->Player);
+			ChangeUnitOwner(unit,around[i]->Player);
 			unit->Blink=5;
 			unit->Rescued=1;
 			PlayGameSound(GameSounds.Rescue[unit->Player->Race].Sound
@@ -3661,7 +3660,7 @@ global void HitUnit(Unit* attacker,Unit* target,int damage)
 	    && IsEnemy(attacker->Player,target)
 	    && (attacker->Type==UnitTypeOrcWorker
 		|| attacker->Type==UnitTypeHumanWorker) ) {
-	ChangeUnitOwner(target, target->Player, attacker->Player);
+	ChangeUnitOwner(target,attacker->Player);
 	CommandStopUnit(attacker);	// Attacker shouldn't continue attack!
     }