Thread Tools
Old February 7, 2001, 22:37   #1
Dale
Emperor
 
Dale's Avatar
 
Local Time: 19:54
Local Date: October 31, 2010
Join Date: Dec 2000
Posts: 3,944
Question to SLIC writers
I've been thinking about how to teleport units around the map. The question comes up because event TELEPORT can cause some weird results, and just disbanding a unit and creating a new one at the new location won't take across any veteran status. So I've had this idea and wondered if it would work in SLIC. Maybe Locutus can shed some light?

Here's the basics of the code anyways:

Code:
location_t tmploc;
unit_t tmpunit;

tmpunit = (unit you want to 'teleport');
// Define desired unit to 'teleport'.
//
// Routine to find desired location to 'teleport' to.
// In withdraw mod I use a 50 loop RandomNeighbor loop
// to find a desired spot.
// Define desired spot as tmploc
//
tmpunit.location = tmploc;
// Define location of unit to desired location.
//
// End with whatever the command is to refresh the screen.
By my thoughts, this should work because all you are doing is redefining the units location property to what you want and then refreshing the screen so the unit icon pops up in it's new location. Can anyone see any problems with this theory?

------------------
Author of Diplomod. The mod to fix diplomacy.

Rommell to a sub-commander outside Tobruk: "Those Australians are in there somewhere. But where? Let's advance and wait till they shoot, then shoot back."
[This message has been edited by Dale (edited February 07, 2001).]
Dale is offline  
Old February 8, 2001, 03:56   #2
Jerk
Chieftain
 
Jerk's Avatar
 
Local Time: 03:54
Local Date: October 31, 2010
Join Date: Nov 2000
Location: Green Bay, WI USA
Posts: 81

I haven't done any testing but I doubt it works like that. Using unit.location extracts the location but probably doesn't set the location. I could be wrong though. You can actually kill the unit and then create it at a different location. Just use IsVeteran() to see if the unit is a veteran, create the unit, then ToggleVeteran() to set it to the right status. You can do similar with hit points as well using unit.hp and DamageUnit().
Jerk is offline  
Old February 8, 2001, 04:55   #3
heardie
Prince
 
heardie's Avatar
 
Local Time: 20:54
Local Date: October 31, 2010
Join Date: Aug 1999
Posts: 684
Heres a function from the Alexander scenario. I presume you know how to use, include it, etc.
Code:
// Teleports units from a given location to a given location
void_f TeleportUnits (location_t tmpLoc, location_t tmpDest, int_t tmpPlayer)
{
int_t		unitTypes[12];
int_t		tmpNum;
int_t		playerNum;
int_t 		i;
location_t	tmpLoc2;
location_t	tmpDest2;
unit_t		tmpUnit;

	playerNum = tmpPlayer;
	tmpLoc2 = tmpLoc;
	tmpDest2 = tmpDest;
	tmpNum = GetUnitsAtLocation(tmpDest2);
	if (tmpNum > 0) {
		for (i = 0; i < tmpNum; i = i + 1) {
			GetUnitFromCell(tmpLoc2, i, tmpUnit);
			if (tmpUnit.owner != playerNum) {
				Event:KillUnit(tmpUnit, 0, playerNum);		// Kill units in the destination square not belonging to teleporting units
			}
		}
	}
	tmpNum = GetUnitsAtLocation(tmpLoc2);
	if (tmpNum > 0) {
		for (i = 0; i < tmpNum; i = i + 1) {
			GetUnitFromCell(tmpLoc2, i, tmpUnit);
			unitTypes[i] = tmpUnit.type;
		}
		for (i = 0; i < tmpNum; i = i + 1) {
			if (unitTypes[i] != 0) {
				CreateUnit(playerNum, unitTypes[i], tmpDest2, 0);	// 'Teleport' new unit
			}
		}
		for (i = 0; i < tmpNum; i = i + 1) {
			GetUnitFromCell(tmpLoc2, i, tmpUnit);
			Event:KillUnit(tmpUnit, 0, playerNum);				// Kill old unit
		}
	}
}
heardie is offline  
Old February 8, 2001, 16:00   #4
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:54
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
Here's another piece of code from the Alexander scenario (though this wasn't in the original game, something like this will be added to the improved version). It gives you an example of how to store veteran and health status. Combine this with the code above and you'll have a perfect replacement for the Teleport function.

Code:
int_f SwapCityW (city_t swCity, int_t swPlayer, int_t killUnits) {
int_t  	i;
int_t  	tmpPlayer;
int_t  	tmpNum;
int_t  	numUnits;
int_t  	noSwap;
int_t 	tmpUnitTypesW[12];	// -> changed from tmpUnitTypes  (CR 2001-01-16)
int_t 	tmpHp[12];
int_t 	tmpHealth[12];
int_t 	tmpDamage;
unit_t 	tmpUnit;
city_t 	tmpCity;
location_t 	tmpLoc;

    tmpCity = swCity;
    if (CityIsValid(tmpCity)) {
        tmpPlayer = swPlayer;
        numUnits = GetUnitsAtLocation(tmpCity.location);
        tmpLoc = tmpCity.location;
        for (i = 0; i < numUnits; i = i + 1) {   // Check for special units
            GetUnitFromCell(tmpLoc, i, tmpUnit);
            tmpNum = tmpUnit.type;
            if (tmpNum >= 72 && tmpNum <= 88) {
                noSwap = 1;
            }
        }
        if (noSwap == 0) {
            if (killUnits == 1) {
                	for (i = 0; i < numUnits; i = i + 1) {
                    	GetUnitFromCell(tmpLoc, i, tmpUnit);
                    	Event: KillUnit(tmpUnit, 0, tmpUnit.owner);
                }
            } elseif (killUnits == 0) {
			for (i = 0; i < numUnits; i = i + 1) {	// -> added (CR 2001-01-16)
//                while (GetUnitsAtLocation(tmpLoc) > 0) {
                    	GetUnitFromCell(tmpLoc, 0, tmpUnit);
                    	tmpUnitTypesW[i] = tmpUnit.type;		// -> changed from tmpUnitTypes  (CR 2001-01-16)
                    	tmpHealth[i] = tmpUnit.hp;
                    	if (IsVeteran(tmpUnit)) {
                        	tmpHp[i] = 1;		// -> changed from tmpUnitHp  (CR 2001-01-16)
                    	} else {
                      		tmpHp[i] = 0;		// -> changed from tmpUnitHp  (CR 2001-01-16)
                    	}
                    	Event: KillUnit(tmpUnit, 0, tmpUnit.owner);
//                    i = i + 1;
                	}
            }
            Event:GiveCity(tmpCity, tmpPlayer);
            for (i = 0; i < numUnits; i = i + 1) {
                	CreateUnit(tmpPlayer, tmpUnitTypesW[i], tmpLoc, 0);	// -> changed from tmpUnitTypes  (CR 2001-01-16)
                	if (tmpHp[i] == 1) {
                    	ToggleVeteran(tmpUnit, 1);
                	}
                	tmpDamage = UnitDB(tmpUnitTypesW[i]).MaxHP - tmpHealth[i];	// -> changed from tmpUnitTypes  (CR 2001-01-16)
                	DamageUnit(tmpUnit, tmpDamage);
            }
        } else {
            return -1;    // Can't swap due to Special unit
        }
    } else {
        return -2;    // Can't swap due to invalid city
    }
}
[This message has been edited by Locutus (edited February 08, 2001).]
Locutus is offline  
Old February 8, 2001, 17:49   #5
Dale
Emperor
 
Dale's Avatar
 
Local Time: 19:54
Local Date: October 31, 2010
Join Date: Dec 2000
Posts: 3,944
Thanks guys! You're champs! I'll look through it all this weekend.

Now I know why I bow to the SLIC wisdom of others, cuz I'm crap!

------------------
Author of Diplomod. The mod to fix diplomacy.

Rommell to a sub-commander outside Tobruk: "Those Australians are in there somewhere. But where? Let's advance and wait till they shoot, then shoot back."
Dale is offline  
Old February 9, 2001, 00:47   #6
Alpha Wolf
Chieftain
 
Local Time: 09:54
Local Date: October 31, 2010
Join Date: Feb 2001
Location: Prince of the Barbarians
Posts: 0
Dear SLIC Lords,
Can transport be triggered before the AI gives away a city in order to salvage the garrison?

GiveCity 'savearmy' pre {
transport garrison logic
}

????????

Sincerely,
Prince of the Barbarians

------------------
History is written by the victor.
Alpha Wolf is offline  
Old February 9, 2001, 03:32   #7
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 11:54
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
AW,
This already happens automaticly. Right before a city is given away, all units in that city are teleported to nearby cities.
Locutus is offline  
Old February 9, 2001, 12:07   #8
Colonel Kraken
PtWDG Legoland
Warlord
 
Colonel Kraken's Avatar
 
Local Time: 04:54
Local Date: October 31, 2010
Join Date: Nov 2000
Location: Grand Rapids, MI
Posts: 296
In my experience in giving cities away to AI players (just to try it out), units in the city were destroyed. (I had wanted to see if the units would revert to control of the new player). The units definitely were NOT teleported back to my nearest city, but perhaps it works differently if the AI gives YOU a city.
Colonel Kraken is offline  
Old February 9, 2001, 22:55   #9
Alpha Wolf
Chieftain
 
Local Time: 09:54
Local Date: October 31, 2010
Join Date: Feb 2001
Location: Prince of the Barbarians
Posts: 0
I've seen them die many times. But you can also hear them die. i once bought an AIs second to last city then a few turns later attacked the already surrounded capital. I heard/saw eight units die after I bought the city and the capitol only had a couple of units in it when I attacked, and there was no way those units could have escaped the capitol.

------------------
History is written by the victor.
Alpha Wolf is offline  
Old February 11, 2001, 01:23   #10
XMon
Warlord
 
XMon's Avatar
 
Local Time: 04:54
Local Date: October 31, 2010
Join Date: Sep 2000
Location: Tampa, Florida
Posts: 117
I've given cities to other civs (I just can't resist Sheherazade!) and my units were teleported to my nearest city. If your's died then perhaps (just a guess) your cities were full of defenders or you were out of support shields. Dunno.
XMon is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:54.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team