 |
|  |
 |
|
heardie
|
|
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
}
}
}
|
|
|  |
 |
|
Locutus
|
|
ACS CTP1/2 Manager & Civ4 Co-Manager
|
 |
Hengelo, The Netherlands
Nov 1999 time: 06:14
|
|
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).]
|
|
|  |
 |
|  |
 |
|
Alpha Wolf
|
|
Prince of the Barbarians
Feb 2001 time: 05:14
|
|
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.
|
|
|  |
All times are GMT. The time now is 05:14. Apolyton Time is 00:14. |
top of page
|
| archivepost |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|