mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-24 19:45:07 +00:00
SCUMM HE: Added main Moonbase AI code
This commit is contained in:
parent
26b5416433
commit
44333f7453
@ -553,8 +553,15 @@ protected:
|
||||
byte VAR_NUM_PALETTES;
|
||||
byte VAR_NUM_UNK;
|
||||
|
||||
public: // FIXME. TODO. Should be protected. Used by Moonbase
|
||||
byte VAR_U32_VERSION;
|
||||
byte VAR_U32_ARRAY_UNK;
|
||||
byte VAR_U32_USER_VAR_A;
|
||||
byte VAR_U32_USER_VAR_B;
|
||||
byte VAR_U32_USER_VAR_C;
|
||||
byte VAR_U32_USER_VAR_D;
|
||||
byte VAR_U32_USER_VAR_E;
|
||||
byte VAR_U32_USER_VAR_F;
|
||||
};
|
||||
|
||||
class ScummEngine_v99he : public ScummEngine_v90he {
|
||||
|
@ -123,13 +123,13 @@ int AntiAirUnit::selectWeapon(int index) {
|
||||
|
||||
case 2:
|
||||
if (getState() == DUS_OFF) {
|
||||
if (GetPlayerEnergy() > 6) {
|
||||
if (getPlayerEnergy() > 6) {
|
||||
if (!_vm->_rnd.getRandomNumber(3)) {
|
||||
return ITEM_VIRUS;
|
||||
}
|
||||
}
|
||||
|
||||
if (GetPlayerEnergy() > 2) {
|
||||
if (getPlayerEnergy() > 2) {
|
||||
if (!_vm->_rnd.getRandomNumber(1)) {
|
||||
return ITEM_SPIKE;
|
||||
}
|
||||
@ -169,8 +169,8 @@ Common::Point *ShieldUnit::createTargetPos(int index, int distance, int weaponTy
|
||||
case ITEM_CRAWLER:
|
||||
ratio = MAX(0.0, 1.0 - (static_cast<float>(getRadius()) / static_cast<float>(distance - 20)));
|
||||
{
|
||||
int maxX = GetMaxX();
|
||||
int maxY = GetMaxY();
|
||||
int maxX = getMaxX();
|
||||
int maxY = getMaxY();
|
||||
int thisX = (static_cast<int>(sourceX + ratio * (getPosX() - sourceX)) + maxX) % maxX;
|
||||
int thisY = (static_cast<int>(sourceY + ratio * (getPosY() - sourceY)) + maxY) % maxY;
|
||||
targetPos->x = thisX;
|
||||
@ -221,8 +221,8 @@ Common::Point *ShieldUnit::createTargetPos(int index, int distance, int weaponTy
|
||||
int ShieldUnit::selectWeapon(int index) {
|
||||
warning("Shield weapon select");
|
||||
|
||||
int myUnit = GetClosestUnit(getPosX(), getPosY(), GetMaxX(), GetCurrentPlayer(), 1, BUILDING_MAIN_BASE, 1, 0);
|
||||
int dist = GetDistance(getPosX(), getPosY(), GetHubX(myUnit), GetHubY(myUnit));
|
||||
int myUnit = getClosestUnit(getPosX(), getPosY(), getMaxX(), getCurrentPlayer(), 1, BUILDING_MAIN_BASE, 1, 0);
|
||||
int dist = getDistance(getPosX(), getPosY(), getHubX(myUnit), getHubY(myUnit));
|
||||
|
||||
if ((dist < (getRadius() - 20)) && (dist > 90)) {
|
||||
return ITEM_SPIKE;
|
||||
@ -231,7 +231,7 @@ int ShieldUnit::selectWeapon(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (getState() == DUS_OFF) {
|
||||
if (GetPlayerEnergy() < 3) {
|
||||
if (getPlayerEnergy() < 3) {
|
||||
return ITEM_BOMB;
|
||||
} else {
|
||||
return ITEM_SPIKE;
|
||||
@ -287,11 +287,11 @@ Common::Point *MineUnit::createTargetPos(int index, int distance, int weaponType
|
||||
}
|
||||
|
||||
int MineUnit::selectWeapon(int index) {
|
||||
int myUnit = GetClosestUnit(getPosX(), getPosY(), GetMaxX(), GetCurrentPlayer(), 1, 0, 0, 0);
|
||||
int myUnit = getClosestUnit(getPosX(), getPosY(), getMaxX(), getCurrentPlayer(), 1, 0, 0, 0);
|
||||
int x = getPosX();
|
||||
int y = getPosY();
|
||||
|
||||
int dist = GetDistance(x, y, GetHubX(myUnit), GetHubY(myUnit));
|
||||
int dist = getDistance(x, y, getHubX(myUnit), getHubY(myUnit));
|
||||
|
||||
if ((getState() == DUS_ON) && (dist < 110)) {
|
||||
return ITEM_EMP;
|
||||
@ -334,17 +334,17 @@ Common::Point *HubUnit::createTargetPos(int index, int distance, int weaponType,
|
||||
int HubUnit::selectWeapon(int index) {
|
||||
warning("Hub weapon select");
|
||||
|
||||
int energy = GetPlayerEnergy();
|
||||
int energy = getPlayerEnergy();
|
||||
|
||||
if (energy > 6) {
|
||||
//possibly choose crawler
|
||||
if (GetBuildingWorth(getID()) > 21) {
|
||||
if (getBuildingWorth(getID()) > 21) {
|
||||
return ITEM_CRAWLER;
|
||||
}
|
||||
}
|
||||
|
||||
//choose betw/ bomb and cluster
|
||||
if (GetBuildingArmor(getID()) < 1.5) {
|
||||
if (getBuildingArmor(getID()) < 1.5) {
|
||||
return ITEM_CLUSTER;
|
||||
}
|
||||
|
||||
@ -483,17 +483,17 @@ Common::Point *EnergyUnit::createTargetPos(int index, int distance, int weaponTy
|
||||
int EnergyUnit::selectWeapon(int index) {
|
||||
warning("Energy weapon select");
|
||||
|
||||
int energy = GetPlayerEnergy();
|
||||
int energy = getPlayerEnergy();
|
||||
|
||||
if (energy > 6) {
|
||||
//possibly choose crawler
|
||||
if (GetBuildingWorth(getID()) > 21) {
|
||||
if (getBuildingWorth(getID()) > 21) {
|
||||
return ITEM_CRAWLER;
|
||||
}
|
||||
}
|
||||
|
||||
//choose betw/ bomb and cluster
|
||||
if (GetBuildingArmor(getID()) < 1.5) {
|
||||
if (getBuildingArmor(getID()) < 1.5) {
|
||||
return ITEM_CLUSTER;
|
||||
}
|
||||
|
||||
@ -539,17 +539,17 @@ Common::Point *OffenseUnit::createTargetPos(int index, int distance, int weaponT
|
||||
int OffenseUnit::selectWeapon(int index) {
|
||||
warning("Offense weapon select");
|
||||
|
||||
int energy = GetPlayerEnergy();
|
||||
int energy = getPlayerEnergy();
|
||||
|
||||
if (energy > 6) {
|
||||
//possibly choose crawler
|
||||
if (GetBuildingWorth(getID()) > 21) {
|
||||
if (getBuildingWorth(getID()) > 21) {
|
||||
return ITEM_CRAWLER;
|
||||
}
|
||||
}
|
||||
|
||||
//choose betw/ bomb and cluster
|
||||
if (GetBuildingArmor(getID()) < 1.5) {
|
||||
if (getBuildingArmor(getID()) < 1.5) {
|
||||
return ITEM_CLUSTER;
|
||||
}
|
||||
|
||||
@ -589,13 +589,13 @@ Common::Point *CrawlerUnit::createTargetPos(int index, int distance, int weaponT
|
||||
|
||||
int CrawlerUnit::selectWeapon(int index) {
|
||||
warning("Crawler weapon select");
|
||||
int myUnit = GetClosestUnit(getPosX(), getPosY(), GetMaxX(), GetCurrentPlayer(), 1, 0, 0, 0);
|
||||
int dist = GetDistance(GetHubX(myUnit), GetHubY(myUnit), getPosX(), getPosY());
|
||||
int myUnit = getClosestUnit(getPosX(), getPosY(), getMaxX(), getCurrentPlayer(), 1, 0, 0, 0);
|
||||
int dist = getDistance(getHubX(myUnit), getHubY(myUnit), getPosX(), getPosY());
|
||||
|
||||
int x = getPosX();
|
||||
int y = getPosY();
|
||||
int energy = GetPlayerEnergy();
|
||||
int terrain = GetTerrain(x, y);
|
||||
int energy = getPlayerEnergy();
|
||||
int terrain = getTerrain(x, y);
|
||||
|
||||
if (terrain != TERRAIN_TYPE_WATER) {
|
||||
if ((energy > 2) && (dist < 220)) {
|
||||
|
3124
engines/scumm/he/moonbase/ai_main.cpp
Normal file
3124
engines/scumm/he/moonbase/ai_main.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -86,101 +86,95 @@ enum {
|
||||
|
||||
static int energyHogType = 0;
|
||||
|
||||
void ResetAI();
|
||||
void CleanUpAI();
|
||||
void SetAIType(const int paramCount, const int *params);
|
||||
int MasterControlProgram(const int paramCount, const int *params);
|
||||
void resetAI();
|
||||
void cleanUpAI();
|
||||
void setAIType(const int paramCount, const int *params);
|
||||
int masterControlProgram(const int paramCount, const int *params);
|
||||
|
||||
int ChooseBehavior();
|
||||
int ChooseTarget(int behavior);
|
||||
int chooseBehavior();
|
||||
int chooseTarget(int behavior);
|
||||
|
||||
Tree *InitApproachTarget(int targetX, int targetY, Node **retNode);
|
||||
int *ApproachTarget(Tree *myTree, int &x, int &y, Node **currentNode);
|
||||
Tree *InitAcquireTarget(int targetX, int targetY, Node **retNode);
|
||||
int *AcquireTarget(int targetX, int targetY);
|
||||
int *AcquireTarget(int targetX, int targetY, Tree *myTree, int &errorCode);
|
||||
int *OffendTarget(int &targetX, int &targetY, int index);
|
||||
int *DefendTarget(int &targetX, int &targetY, int index);
|
||||
int *EnergizeTarget(int &targetX, int &targetY, int index);
|
||||
Tree *initApproachTarget(int targetX, int targetY, Node **retNode);
|
||||
int *approachTarget(Tree *myTree, int &x, int &y, Node **currentNode);
|
||||
Tree *initAcquireTarget(int targetX, int targetY, Node **retNode);
|
||||
int *acquireTarget(int targetX, int targetY);
|
||||
int *acquireTarget(int targetX, int targetY, Tree *myTree, int &errorCode);
|
||||
int *offendTarget(int &targetX, int &targetY, int index);
|
||||
int *defendTarget(int &targetX, int &targetY, int index);
|
||||
int *energizeTarget(int &targetX, int &targetY, int index);
|
||||
|
||||
int GetClosestUnit(int x, int y, int radius, int player, int alignment, int unitType, int checkUnitEnabled);
|
||||
int GetClosestUnit(int x, int y, int radius, int player, int alignment, int unitType, int checkUnitEnabled, int minDist);
|
||||
int getClosestUnit(int x, int y, int radius, int player, int alignment, int unitType, int checkUnitEnabled);
|
||||
int getClosestUnit(int x, int y, int radius, int player, int alignment, int unitType, int checkUnitEnabled, int minDist);
|
||||
|
||||
int GetDistance(int originX, int originY, int endX, int endY);
|
||||
int GetAngle(int originX, int originY, int endX, int endY);
|
||||
int GetAngle(int originX, int originY, int endX, int endY, int noWrapFlag);
|
||||
int GetTerrain(int x, int y);
|
||||
int GetHubX(int hub);
|
||||
int GetHubY(int hub);
|
||||
int GetMaxX();
|
||||
int GetMaxY();
|
||||
int GetCurrentPlayer();
|
||||
int GetMaxPower();
|
||||
int GetMinPower();
|
||||
int GetTerrainSquareSize();
|
||||
int GetBuildingOwner(int building);
|
||||
int GetBuildingState(int building);
|
||||
int GetBuildingType(int building);
|
||||
int GetBuildingArmor(int building);
|
||||
int GetBuildingWorth(int building);
|
||||
void DebugBreak();
|
||||
int GetEnergyPoolsArray();
|
||||
int GetCoordinateVisibility(int x, int y, int playerNum);
|
||||
int GetUnitVisibility(int unit, int playerNum);
|
||||
int GetEnergyPoolVisibility(int pool, int playerNum);
|
||||
int GetNumberOfPools();
|
||||
int GetNumberOfPlayers();
|
||||
int GetPlayerEnergy();
|
||||
int GetPlayerMaxTime();
|
||||
int GetWindXSpeed();
|
||||
int GetWindYSpeed();
|
||||
int GetTotalWindSpeed();
|
||||
int GetWindXSpeedMax();
|
||||
int GetWindYSpeedMax();
|
||||
int GetBigXSize();
|
||||
int GetBigYSize();
|
||||
int GetEnergyPoolWidth(int pool);
|
||||
int GetBuildingMaxArmor(int building);
|
||||
int GetTimerValue(int timerNum);
|
||||
int GetLastAttacked(int &x, int &y);
|
||||
int PrintDebugTimer(int max, int timerVal);
|
||||
int GetPlayerTeam(int player);
|
||||
int GetBuildingTeam(int building);
|
||||
int GetFOW();
|
||||
int GetAnimSpeed();
|
||||
int GetBuildingStackPtr();
|
||||
int GetTurnCounter();
|
||||
int getDistance(int originX, int originY, int endX, int endY);
|
||||
int calcAngle(int originX, int originY, int endX, int endY);
|
||||
int calcAngle(int originX, int originY, int endX, int endY, int noWrapFlag);
|
||||
int getTerrain(int x, int y);
|
||||
int getHubX(int hub);
|
||||
int getHubY(int hub);
|
||||
int getMaxX();
|
||||
int getMaxY();
|
||||
int getCurrentPlayer();
|
||||
int getMaxPower();
|
||||
int getMinPower();
|
||||
int getTerrainSquareSize();
|
||||
int getBuildingOwner(int building);
|
||||
int getBuildingState(int building);
|
||||
int getBuildingType(int building);
|
||||
int getBuildingArmor(int building);
|
||||
int getBuildingWorth(int building);
|
||||
int getEnergyPoolsArray();
|
||||
int getCoordinateVisibility(int x, int y, int playerNum);
|
||||
int getUnitVisibility(int unit, int playerNum);
|
||||
int getEnergyPoolVisibility(int pool, int playerNum);
|
||||
int getNumberOfPools();
|
||||
int getNumberOfPlayers();
|
||||
int getPlayerEnergy();
|
||||
int getPlayerMaxTime();
|
||||
int getWindXSpeed();
|
||||
int getWindYSpeed();
|
||||
int getTotalWindSpeed();
|
||||
int getWindXSpeedMax();
|
||||
int getWindYSpeedMax();
|
||||
int getBigXSize();
|
||||
int getBigYSize();
|
||||
int getEnergyPoolWidth(int pool);
|
||||
int getBuildingMaxArmor(int building);
|
||||
int getTimerValue(int timerNum);
|
||||
int getLastAttacked(int &x, int &y);
|
||||
int getPlayerTeam(int player);
|
||||
int getBuildingTeam(int building);
|
||||
int getFOW();
|
||||
int getAnimSpeed();
|
||||
int getBuildingStackPtr();
|
||||
int getTurnCounter();
|
||||
|
||||
int GetGroundAltitude(int x, int y);
|
||||
int CheckForCordOverlap(int xStart, int yStart, int affectRadius, int simulateFlag);
|
||||
int CheckForAngleOverlap(int unit, int angle);
|
||||
int EstimateNextRoundEnergy(int player);
|
||||
int CheckForUnitOverlap(int x, int y, int radius, int ignoredUnit);
|
||||
int CheckForEnergySquare(int x, int y);
|
||||
int AIChat();
|
||||
int getGroundAltitude(int x, int y);
|
||||
int checkForCordOverlap(int xStart, int yStart, int affectRadius, int simulateFlag);
|
||||
int checkForAngleOverlap(int unit, int angle);
|
||||
int estimateNextRoundEnergy(int player);
|
||||
int checkForUnitOverlap(int x, int y, int radius, int ignoredUnit);
|
||||
int checkForEnergySquare(int x, int y);
|
||||
int aiChat();
|
||||
|
||||
int simulateBuildingLaunch(int x, int y, int power, int angle, int numSteps, int isEnergy);
|
||||
int simulateWeaponLaunch(int x, int y, int power, int angle, int numSteps);
|
||||
int fakeSimulateWeaponLaunch(int x, int y, int power, int angle);
|
||||
|
||||
int SimulateBuildingLaunch(int x, int y, int power, int angle, int numSteps, int isEnergy);
|
||||
int SimulateWeaponLaunch(int x, int y, int power, int angle, int numSteps);
|
||||
int FakeSimulateWeaponLaunch(int x, int y, int power, int angle);
|
||||
|
||||
int GetPowerAngleFromPoint(int originX, int originY, int endX, int endY, int threshold, int olFlag);
|
||||
int GetPowerAngleFromPoint(int originX, int originY, int endX, int endY, int threshold);
|
||||
int CheckIfWaterState(int x, int y);
|
||||
int CheckIfWaterSquare(int x, int y);
|
||||
int GetUnitsWithinRadius(int x, int y, int radius);
|
||||
int GetLandingPoint(int x, int y, int power, int angle);
|
||||
int GetEnemyUnitsVisible(int playerNum);
|
||||
int getPowerAngleFromPoint(int originX, int originY, int endX, int endY, int threshold, int olFlag);
|
||||
int getPowerAngleFromPoint(int originX, int originY, int endX, int endY, int threshold);
|
||||
int checkIfWaterState(int x, int y);
|
||||
int checkIfWaterSquare(int x, int y);
|
||||
int getUnitsWithinRadius(int x, int y, int radius);
|
||||
int getLandingPoint(int x, int y, int power, int angle);
|
||||
int getEnemyUnitsVisible(int playerNum);
|
||||
|
||||
float degToRad(float degrees);
|
||||
void MACRO_LimitLocation(int &a, int &b, int c, int d);
|
||||
void limitLocation(int &a, int &b, int c, int d);
|
||||
int energyPoolSize(int pool);
|
||||
int GetMaxCollectors(int pool);
|
||||
int getMaxCollectors(int pool);
|
||||
|
||||
int TempChooseBehavior();
|
||||
int TempChooseTarget(int behavior);
|
||||
|
||||
int GetEnergyHogType();
|
||||
int getEnergyHogType();
|
||||
|
||||
extern Common::Array<int> lastXCoord[];
|
||||
extern Common::Array<int> lastYCoord[];
|
||||
|
162
engines/scumm/he/moonbase/ai_pattern.h
Normal file
162
engines/scumm/he/moonbase/ai_pattern.h
Normal file
@ -0,0 +1,162 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SCUMM_HE_MOONBASE_AI_PATTERN_H
|
||||
#define SCUMM_HE_MOONBASE_AI_PATTERN_H
|
||||
|
||||
namespace Scumm {
|
||||
|
||||
const int NO_PATTERN = 0;
|
||||
const int PATTERN_FOUND = 1;
|
||||
|
||||
class patternInstance {
|
||||
private:
|
||||
int _sourceHub;
|
||||
int _unit;
|
||||
int _power;
|
||||
int _angle;
|
||||
|
||||
public:
|
||||
patternInstance() {
|
||||
_sourceHub = 0;
|
||||
_unit = 0;
|
||||
_power = 0;
|
||||
_angle = 0;
|
||||
}
|
||||
|
||||
patternInstance(int sh, int unit, int power, int angle) {
|
||||
setSourceHub(sh);
|
||||
setUnit(unit);
|
||||
setPower(power);
|
||||
setAngle(angle);
|
||||
}
|
||||
|
||||
void setSourceHub(int sh) { _sourceHub = sh; }
|
||||
void setUnit(int unit) { _unit = unit; }
|
||||
|
||||
void setPower(int power) {
|
||||
if (power < 300)
|
||||
_power = 1;
|
||||
else if (power < 480)
|
||||
_power = 2;
|
||||
else
|
||||
_power = 3;
|
||||
}
|
||||
|
||||
void setAngle(int angle) {
|
||||
int tempAngle = angle % 360;
|
||||
|
||||
if ((tempAngle >= 0) && (tempAngle < 90))
|
||||
_angle = 1;
|
||||
|
||||
if ((tempAngle >= 90) && (tempAngle < 180))
|
||||
_angle = 2;
|
||||
|
||||
if ((tempAngle >= 180) && (tempAngle < 270))
|
||||
_angle = 3;
|
||||
|
||||
if ((tempAngle >= 270))
|
||||
_angle = 4;
|
||||
}
|
||||
|
||||
int getSourceHub() const { return _sourceHub; }
|
||||
int getUnit() const { return _unit; }
|
||||
int getPowerIndex() const { return _power; }
|
||||
int getAngleIndex() const { return _angle; }
|
||||
|
||||
static int comparePatterns(patternInstance *p1, patternInstance *p2) {
|
||||
if (p1->getSourceHub() != p2->getSourceHub())
|
||||
return 0;
|
||||
|
||||
if (p1->getUnit() != p2->getUnit())
|
||||
return 0;
|
||||
|
||||
if (p1->getUnit() == -999)
|
||||
return 0;
|
||||
|
||||
int temp = abs(p1->getPowerIndex() - p2->getPowerIndex());
|
||||
|
||||
if (temp > 1)
|
||||
return 0;
|
||||
|
||||
temp = abs(p1->getAngleIndex() - p2->getAngleIndex());
|
||||
|
||||
if (temp > 1 && temp < 3)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
class patternList {
|
||||
private:
|
||||
patternInstance *theList[10];
|
||||
int listIndex;
|
||||
|
||||
public:
|
||||
patternList() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
theList[i] = new patternInstance();
|
||||
}
|
||||
|
||||
listIndex = 0;
|
||||
}
|
||||
~patternList() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
delete theList[i];
|
||||
}
|
||||
}
|
||||
|
||||
void addPattern(int sh, int unit, int power, int angle) {
|
||||
theList[listIndex]->setSourceHub(sh);
|
||||
theList[listIndex]->setUnit(unit);
|
||||
theList[listIndex]->setPower(power);
|
||||
theList[listIndex]->setAngle(angle);
|
||||
|
||||
listIndex++;
|
||||
|
||||
if (listIndex > 9)
|
||||
listIndex = 0;
|
||||
}
|
||||
|
||||
int evaluatePattern(int sh, int unit, int power, int angle) {
|
||||
patternInstance *patternToMatch = new patternInstance(sh, unit, power, angle);
|
||||
int matchCount = 0;
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (patternInstance::comparePatterns(theList[i], patternToMatch)) {
|
||||
matchCount++;
|
||||
}
|
||||
}
|
||||
|
||||
delete patternToMatch;
|
||||
|
||||
if (matchCount > 2)
|
||||
return PATTERN_FOUND;
|
||||
|
||||
return NO_PATTERN;
|
||||
}
|
||||
};
|
||||
|
||||
} // End of namespace Scumm
|
||||
|
||||
#endif
|
@ -36,22 +36,22 @@ int Sortie::_sTargetX = 0;
|
||||
int Sortie::_sTargetY = 0;
|
||||
|
||||
Sortie::~Sortie() {
|
||||
for (Common::Array<DefenseUnit *>::iterator k = _enemyDefenses.begin(); k != _enemyDefenses.end(); ++k) {
|
||||
for (Common::Array<DefenseUnit *>::iterator k = _enemyDefenses.begin(); k != _enemyDefenses.end(); k++) {
|
||||
delete *k;
|
||||
}
|
||||
}
|
||||
|
||||
void Sortie::setEnemyDefenses(int enemyDefensesScummArray, int defendX, int defendY) {
|
||||
DefenseUnit *thisUnit;
|
||||
int currentPlayer = GetCurrentPlayer();
|
||||
int currentPlayer = getCurrentPlayer();
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
for (int i = 0; i < 200; i++) {
|
||||
int thisElement = _vm->_moonbase->readFromArray(enemyDefensesScummArray, 0, i);
|
||||
|
||||
if (thisElement) {
|
||||
if (GetBuildingOwner(thisElement)) {
|
||||
if (GetPlayerTeam(currentPlayer) != GetBuildingTeam(thisElement)) {
|
||||
int type = GetBuildingType(thisElement);
|
||||
if (getBuildingOwner(thisElement)) {
|
||||
if (getPlayerTeam(currentPlayer) != getBuildingTeam(thisElement)) {
|
||||
int type = getBuildingType(thisElement);
|
||||
|
||||
switch (type) {
|
||||
case BUILDING_ANTI_AIR:
|
||||
@ -63,7 +63,7 @@ void Sortie::setEnemyDefenses(int enemyDefensesScummArray, int defendX, int defe
|
||||
break;
|
||||
|
||||
case BUILDING_EXPLOSIVE_MINE:
|
||||
if (GetDistance(GetHubX(thisElement), GetHubY(thisElement), defendX, defendY) < 90)
|
||||
if (getDistance(getHubX(thisElement), getHubY(thisElement), defendX, defendY) < 90)
|
||||
thisUnit = new MineUnit();
|
||||
else
|
||||
thisUnit = NULL;
|
||||
@ -81,9 +81,9 @@ void Sortie::setEnemyDefenses(int enemyDefensesScummArray, int defendX, int defe
|
||||
|
||||
if (thisUnit != NULL) {
|
||||
thisUnit->setID(thisElement);
|
||||
thisUnit->setPos(GetHubX(thisElement), GetHubY(thisElement));
|
||||
thisUnit->setPos(getHubX(thisElement), getHubY(thisElement));
|
||||
|
||||
if (GetBuildingState(thisElement)) thisUnit->setState(DUS_OFF);
|
||||
if (getBuildingState(thisElement)) thisUnit->setState(DUS_OFF);
|
||||
|
||||
_enemyDefenses.push_back(thisUnit);
|
||||
}
|
||||
@ -117,7 +117,7 @@ IContainedObject *Sortie::createChildObj(int index, int &completionFlag) {
|
||||
Common::Array<DefenseUnit *> thisEnemyDefenses;
|
||||
|
||||
// Copy the defensive unit list from the parent
|
||||
for (Common::Array<DefenseUnit *>::iterator k = _enemyDefenses.begin(); k != _enemyDefenses.end(); ++k) {
|
||||
for (Common::Array<DefenseUnit *>::iterator k = _enemyDefenses.begin(); k != _enemyDefenses.end(); k++) {
|
||||
DefenseUnit *temp;
|
||||
|
||||
switch ((*k)->getType()) {
|
||||
@ -155,7 +155,7 @@ IContainedObject *Sortie::createChildObj(int index, int &completionFlag) {
|
||||
retSortie->setUnitType(currentWeapon->getTypeID());
|
||||
|
||||
// Calculate distance from target to source hub
|
||||
int distance = GetDistance(currentTarget->getPosX(), currentTarget->getPosY(), getSourcePosX(), getSourcePosY());
|
||||
int distance = getDistance(currentTarget->getPosX(), currentTarget->getPosY(), getSourcePosX(), getSourcePosY());
|
||||
|
||||
// Pick correct shot position according to index
|
||||
Common::Point *targetCoords;
|
||||
@ -168,8 +168,8 @@ IContainedObject *Sortie::createChildObj(int index, int &completionFlag) {
|
||||
int AAcounter = 3;
|
||||
|
||||
// Loop through defensive units, toggling anti-air units and deciding if this weapon will land safely
|
||||
for (Common::Array<DefenseUnit *>::iterator i = thisEnemyDefenses.begin(); i != thisEnemyDefenses.end(); ++i) {
|
||||
distance = GetDistance((*i)->getPosX(), (*i)->getPosY(), targetCoords->x, targetCoords->y);
|
||||
for (Common::Array<DefenseUnit *>::iterator i = thisEnemyDefenses.begin(); i != thisEnemyDefenses.end(); i++) {
|
||||
distance = getDistance((*i)->getPosX(), (*i)->getPosY(), targetCoords->x, targetCoords->y);
|
||||
|
||||
// Check to see if we're within an active defense's radius
|
||||
if ((distance < (*i)->getRadius()) && ((*i)->getState() == DUS_ON)) {
|
||||
@ -198,7 +198,7 @@ IContainedObject *Sortie::createChildObj(int index, int &completionFlag) {
|
||||
}
|
||||
|
||||
// Turn on all the non-anti-air units in preparation for emp's and the next turn
|
||||
for (Common::Array<DefenseUnit *>::iterator i = thisEnemyDefenses.begin(); i != thisEnemyDefenses.end(); ++i) {
|
||||
for (Common::Array<DefenseUnit *>::iterator i = thisEnemyDefenses.begin(); i != thisEnemyDefenses.end(); i++) {
|
||||
if ((*i)->getType() != DUT_ANTI_AIR) {
|
||||
(*i)->setState(DUS_ON);
|
||||
}
|
||||
@ -210,10 +210,10 @@ IContainedObject *Sortie::createChildObj(int index, int &completionFlag) {
|
||||
for (Common::Array<DefenseUnit *>::iterator i = thisEnemyDefenses.begin(); i != thisEnemyDefenses.end(); ) {
|
||||
// Special simulated crawler detonation location used, since it walks a bit
|
||||
if (currentWeapon->getTypeID() == ITEM_CRAWLER)
|
||||
distance = GetDistance((*i)->getPosX(), (*i)->getPosY(), currentTarget->getPosX(), currentTarget->getPosY());
|
||||
distance = getDistance((*i)->getPosX(), (*i)->getPosY(), currentTarget->getPosX(), currentTarget->getPosY());
|
||||
// Normal detonation location used here
|
||||
else {
|
||||
distance = GetDistance((*i)->getPosX(), (*i)->getPosY(), targetCoords->x, targetCoords->y);
|
||||
distance = getDistance((*i)->getPosX(), (*i)->getPosY(), targetCoords->x, targetCoords->y);
|
||||
}
|
||||
|
||||
if (distance < currentWeapon->getRadius()) {
|
||||
@ -238,10 +238,10 @@ IContainedObject *Sortie::createChildObj(int index, int &completionFlag) {
|
||||
delete *i;
|
||||
i = thisEnemyDefenses.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
++i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -257,7 +257,7 @@ float Sortie::calcH() {
|
||||
float retValue = 0;
|
||||
Common::Array<DefenseUnit *> thisEnemyDefenses = getEnemyDefenses();
|
||||
|
||||
for (Common::Array<DefenseUnit *>::iterator i = thisEnemyDefenses.begin(); i != thisEnemyDefenses.end(); ++i) {
|
||||
for (Common::Array<DefenseUnit *>::iterator i = thisEnemyDefenses.begin(); i != thisEnemyDefenses.end(); i++) {
|
||||
if ((*i)->getState() == DUS_ON) {
|
||||
switch ((*i)->getType()) {
|
||||
case DUT_ANTI_AIR:
|
||||
@ -285,7 +285,7 @@ int Sortie::checkSuccess() {
|
||||
|
||||
int targetCheck = 0;
|
||||
|
||||
for (Common::Array<DefenseUnit *>::iterator i = _enemyDefenses.begin(); i != _enemyDefenses.end(); ++i) {
|
||||
for (Common::Array<DefenseUnit *>::iterator i = _enemyDefenses.begin(); i != _enemyDefenses.end(); i++) {
|
||||
if (((*i)->getState() == DUS_ON) && ((*i)->getType() != DUT_HUB)) {
|
||||
return 0;
|
||||
}
|
||||
@ -314,41 +314,41 @@ IContainedObject *Sortie::duplicate() {
|
||||
|
||||
|
||||
void Sortie::printEnemyDefenses() {
|
||||
for (Common::Array<DefenseUnit *>::iterator i = _enemyDefenses.begin(); i != _enemyDefenses.end(); ++i) {
|
||||
for (Common::Array<DefenseUnit *>::iterator i = _enemyDefenses.begin(); i != _enemyDefenses.end(); i++) {
|
||||
warning("Unit %d - Type: %d, Armor: %d, Status: %d", (*i)->getID(), (*i)->getType(), static_cast<int>((*i)->getArmor()), (*i)->getState());
|
||||
}
|
||||
}
|
||||
|
||||
int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index) {
|
||||
int currentPlayer = GetCurrentPlayer();
|
||||
int currentPlayer = getCurrentPlayer();
|
||||
|
||||
//Get list of near hubs
|
||||
int unitsArray = GetUnitsWithinRadius(targetX + 5, targetY, 480);
|
||||
//get list of near hubs
|
||||
int unitsArray = getUnitsWithinRadius(targetX + 5, targetY, 480);
|
||||
|
||||
const int NUM_HUBS = 10;
|
||||
//Order on dist
|
||||
int hubArray[NUM_HUBS] = { 0 };
|
||||
int hubIndex = 0;
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
for (int i = 0; i < 200; i++) {
|
||||
int thisUnit = _vm->_moonbase->readFromArray(unitsArray, 0, i);
|
||||
|
||||
if (thisUnit) {
|
||||
if (((GetBuildingType(thisUnit) == BUILDING_MAIN_BASE) || (GetBuildingType(thisUnit) == BUILDING_OFFENSIVE_LAUNCHER)) && (GetBuildingOwner(thisUnit) == currentPlayer)) {
|
||||
for (int j = 0; j < NUM_HUBS; ++j) {
|
||||
if (((getBuildingType(thisUnit) == BUILDING_MAIN_BASE) || (getBuildingType(thisUnit) == BUILDING_OFFENSIVE_LAUNCHER)) && (getBuildingOwner(thisUnit) == currentPlayer)) {
|
||||
for (int j = 0; j < NUM_HUBS; j++) {
|
||||
if (hubArray[j]) {
|
||||
int distCurrent = GetDistance(targetX, targetY, GetHubX(thisUnit), GetHubY(thisUnit));
|
||||
int distSaved = GetDistance(targetX, targetY, GetHubX(hubArray[j]), GetHubY(hubArray[j]));
|
||||
int distCurrent = getDistance(targetX, targetY, getHubX(thisUnit), getHubY(thisUnit));
|
||||
int distSaved = getDistance(targetX, targetY, getHubX(hubArray[j]), getHubY(hubArray[j]));
|
||||
|
||||
if (distCurrent < distSaved) {
|
||||
hubArray[hubIndex] = hubArray[j];
|
||||
hubArray[j] = thisUnit;
|
||||
++hubIndex;
|
||||
hubIndex++;
|
||||
j = 100;
|
||||
}
|
||||
} else {
|
||||
hubArray[j] = thisUnit;
|
||||
++hubIndex;
|
||||
hubIndex++;
|
||||
j = 100;
|
||||
}
|
||||
}
|
||||
@ -364,21 +364,21 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
_vm->nukeArray(unitsArray);
|
||||
|
||||
//Check if repair is needed
|
||||
int targetUnit = GetClosestUnit(targetX + 5, targetY, 15, currentPlayer, 1, 0, 0, 0);
|
||||
int targetUnit = getClosestUnit(targetX + 5, targetY, 15, currentPlayer, 1, 0, 0, 0);
|
||||
|
||||
if (targetUnit && (targetUnit != BUILDING_CRAWLER) && (GetBuildingTeam(targetUnit) == GetPlayerTeam(currentPlayer))) {
|
||||
int armor = GetBuildingArmor(targetUnit);
|
||||
if (targetUnit && (targetUnit != BUILDING_CRAWLER) && (getBuildingTeam(targetUnit) == getPlayerTeam(currentPlayer))) {
|
||||
int armor = getBuildingArmor(targetUnit);
|
||||
|
||||
if (armor < GetBuildingMaxArmor(targetUnit)) {
|
||||
unitsArray = GetUnitsWithinRadius(targetX + 5, targetY, 170);
|
||||
if (armor < getBuildingMaxArmor(targetUnit)) {
|
||||
unitsArray = getUnitsWithinRadius(targetX + 5, targetY, 170);
|
||||
int defCount = 0;
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
for (int i = 0; i < 200; i++) {
|
||||
int thisUnit = _vm->_moonbase->readFromArray(unitsArray, 0, i);
|
||||
|
||||
if (thisUnit) {
|
||||
if (((GetBuildingType(thisUnit) == BUILDING_SHIELD) || (GetBuildingType(thisUnit) == BUILDING_ANTI_AIR)) && (GetBuildingOwner(thisUnit) == currentPlayer) && (GetBuildingState(thisUnit) == 0)) {
|
||||
++defCount;
|
||||
if (((getBuildingType(thisUnit) == BUILDING_SHIELD) || (getBuildingType(thisUnit) == BUILDING_ANTI_AIR)) && (getBuildingOwner(thisUnit) == currentPlayer) && (getBuildingState(thisUnit) == 0)) {
|
||||
defCount++;
|
||||
i = 200;
|
||||
}
|
||||
}
|
||||
@ -388,10 +388,10 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
|
||||
if (defCount) {
|
||||
//repair
|
||||
int hubUnit = GetClosestUnit(targetX, targetY, 480, currentPlayer, 1, BUILDING_MAIN_BASE, 1, 110);
|
||||
int hubUnit = getClosestUnit(targetX, targetY, 480, currentPlayer, 1, BUILDING_MAIN_BASE, 1, 110);
|
||||
|
||||
if (hubUnit && (hubUnit != targetUnit)) {
|
||||
int powAngle = abs(GetPowerAngleFromPoint(GetHubX(hubUnit), GetHubY(hubUnit), targetX, targetY, 20));
|
||||
int powAngle = abs(getPowerAngleFromPoint(getHubX(hubUnit), getHubY(hubUnit), targetX, targetY, 20));
|
||||
int power = powAngle / 360;
|
||||
int angle = powAngle - (power * 360);
|
||||
|
||||
@ -410,23 +410,23 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
}
|
||||
|
||||
//For each hub
|
||||
for (int i = 0; i < MIN(NUM_HUBS, hubIndex); ++i) {
|
||||
int hubX = GetHubX(hubArray[i]);
|
||||
int hubY = GetHubY(hubArray[i]);
|
||||
//Get angle to hub
|
||||
for (int i = 0; i < MIN(NUM_HUBS, hubIndex); i++) {
|
||||
int hubX = getHubX(hubArray[i]);
|
||||
int hubY = getHubY(hubArray[i]);
|
||||
//get angle to hub
|
||||
int directAngleToHub = 0;
|
||||
|
||||
//If this hub is the target
|
||||
if ((hubX == targetX) && (hubY == targetY)) {
|
||||
//make the angle seed point at the closest enemy
|
||||
int enemyUnit = GetClosestUnit(hubX, hubY, GetMaxX(), currentPlayer, 0, 0, 0);
|
||||
directAngleToHub = GetAngle(targetX, targetY, GetHubX(enemyUnit), GetHubY(enemyUnit));
|
||||
int enemyUnit = getClosestUnit(hubX, hubY, getMaxX(), currentPlayer, 0, 0, 0);
|
||||
directAngleToHub = calcAngle(targetX, targetY, getHubX(enemyUnit), getHubY(enemyUnit));
|
||||
} else {
|
||||
directAngleToHub = GetAngle(targetX, targetY, hubX, hubY);
|
||||
directAngleToHub = calcAngle(targetX, targetY, hubX, hubY);
|
||||
}
|
||||
|
||||
//Number of random chances to land
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
//Pick random angle and dist within semicircle (-90 to +90) and (40 to 150)
|
||||
int randAngle = directAngleToHub + _vm->_rnd.getRandomNumber(179) - 90;
|
||||
int randDist = _vm->_rnd.getRandomNumber(109) + 40;
|
||||
@ -434,7 +434,7 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
int x = targetX + randDist * cos(degToRad(randAngle));
|
||||
int y = targetY + randDist * sin(degToRad(randAngle));
|
||||
|
||||
int powAngle = GetPowerAngleFromPoint(hubX, hubY, x, y, 20);
|
||||
int powAngle = getPowerAngleFromPoint(hubX, hubY, x, y, 20);
|
||||
|
||||
if (powAngle < 0)
|
||||
continue;
|
||||
@ -443,7 +443,7 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
int angle = powAngle - (power * 360);
|
||||
|
||||
int coords = 0;
|
||||
coords = SimulateBuildingLaunch(hubX, hubY, power, angle, 100, 0);
|
||||
coords = simulateBuildingLaunch(hubX, hubY, power, angle, 100, 0);
|
||||
|
||||
//if valid, return
|
||||
if (coords > 0) {
|
||||
@ -451,28 +451,28 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
|
||||
setSourceX(hubX);
|
||||
setSourceY(hubY);
|
||||
setTargetX((x + GetMaxX()) % GetMaxX());
|
||||
setTargetY((y + GetMaxY()) % GetMaxY());
|
||||
setTargetX((x + getMaxX()) % getMaxX());
|
||||
setTargetY((y + getMaxY()) % getMaxY());
|
||||
setSourceUnit(hubArray[i]);
|
||||
|
||||
int unitsArray2 = GetUnitsWithinRadius(targetX + 5, targetY, 200);
|
||||
int unitsArray2 = getUnitsWithinRadius(targetX + 5, targetY, 200);
|
||||
int shieldCount = 0;
|
||||
|
||||
for (int k = 0; k < 200; ++k) {
|
||||
for (int k = 0; k < 200; k++) {
|
||||
int thisUnit = _vm->_moonbase->readFromArray(unitsArray2, 0, k);
|
||||
|
||||
if (thisUnit) {
|
||||
if ((GetBuildingType(thisUnit) == BUILDING_SHIELD) && (GetBuildingOwner(thisUnit) == currentPlayer))
|
||||
if ((getBuildingType(thisUnit) == BUILDING_SHIELD) && (getBuildingOwner(thisUnit) == currentPlayer))
|
||||
shieldCount++;
|
||||
|
||||
if ((GetBuildingType(thisUnit) == BUILDING_BRIDGE) && (GetBuildingOwner(thisUnit) == currentPlayer)) {
|
||||
if ((getBuildingType(thisUnit) == BUILDING_BRIDGE) && (getBuildingOwner(thisUnit) == currentPlayer)) {
|
||||
shieldCount--;
|
||||
shieldCount = MAX(-1, shieldCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((_vm->_rnd.getRandomNumber((int)pow(3, shieldCount + 1) - 1) == 0) && (GetPlayerEnergy() > 6))
|
||||
if ((_vm->_rnd.getRandomNumber((int)pow(3, shieldCount + 1) - 1) == 0) && (getPlayerEnergy() > 6))
|
||||
setUnit(ITEM_SHIELD);
|
||||
else
|
||||
setUnit(ITEM_ANTIAIR);
|
||||
@ -486,12 +486,11 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
|
||||
if (coords < 0) {
|
||||
//drop a bridge for the cord
|
||||
int yCoord = -coords / GetMaxX();
|
||||
int xCoord = -coords - (yCoord * GetMaxX());
|
||||
int yCoord = -coords / getMaxX();
|
||||
int xCoord = -coords - (yCoord * getMaxX());
|
||||
|
||||
if (CheckIfWaterState(xCoord, yCoord)) {
|
||||
|
||||
int terrainSquareSize = GetTerrainSquareSize();
|
||||
if (checkIfWaterState(xCoord, yCoord)) {
|
||||
int terrainSquareSize = getTerrainSquareSize();
|
||||
xCoord = ((xCoord / terrainSquareSize * terrainSquareSize) + (terrainSquareSize / 2));
|
||||
yCoord = ((yCoord / terrainSquareSize * terrainSquareSize) + (terrainSquareSize / 2));
|
||||
|
||||
@ -503,8 +502,8 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
setTargetX(x);
|
||||
setTargetY(y);
|
||||
|
||||
int nextUnit = GetClosestUnit(x, y, 480, GetCurrentPlayer(), 1, BUILDING_MAIN_BASE, 1, 120);
|
||||
powAngle = GetPowerAngleFromPoint(GetHubX(nextUnit), GetHubY(nextUnit), x, y, 15);
|
||||
int nextUnit = getClosestUnit(x, y, 480, getCurrentPlayer(), 1, BUILDING_MAIN_BASE, 1, 120);
|
||||
powAngle = getPowerAngleFromPoint(getHubX(nextUnit), getHubY(nextUnit), x, y, 15);
|
||||
|
||||
powAngle = abs(powAngle);
|
||||
power = powAngle / 360;
|
||||
@ -530,8 +529,8 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
do {
|
||||
int sourceHub = hubArray[_vm->_rnd.getRandomNumber(hubIndex - 1)];
|
||||
|
||||
setSourceX(GetHubX(sourceHub));
|
||||
setSourceY(GetHubY(sourceHub));
|
||||
setSourceX(getHubX(sourceHub));
|
||||
setSourceY(getHubY(sourceHub));
|
||||
setSourceUnit(sourceHub);
|
||||
setUnit(ITEM_HUB);
|
||||
setPower(_vm->_rnd.getRandomNumber(299) + 200);
|
||||
@ -540,12 +539,12 @@ int Defender::calculateDefenseUnitPosition(int targetX, int targetY, int index)
|
||||
|
||||
if (count > (NUM_HUBS * 3)) break;
|
||||
|
||||
coords = SimulateBuildingLaunch(getSourceX(), getSourceY(), getPower(), getAngle(), 100, 0);
|
||||
coords = simulateBuildingLaunch(getSourceX(), getSourceY(), getPower(), getAngle(), 100, 0);
|
||||
} while (coords <= 0);
|
||||
|
||||
if (coords > 0) {
|
||||
setTargetX(coords % GetMaxX());
|
||||
setTargetY(coords / GetMaxX());
|
||||
setTargetX(coords % getMaxX());
|
||||
setTargetY(coords / getMaxX());
|
||||
} else {
|
||||
setTargetX(0);
|
||||
setTargetY(0);
|
||||
|
@ -48,7 +48,7 @@ Traveller::Traveller(int originX, int originY) {
|
||||
}
|
||||
|
||||
void Traveller::adjustPosX(int offsetX) {
|
||||
int maxX = GetMaxX();
|
||||
int maxX = getMaxX();
|
||||
int deltaX = _posX + offsetX;
|
||||
|
||||
if (deltaX < 0) _posX = maxX + deltaX;
|
||||
@ -57,7 +57,7 @@ void Traveller::adjustPosX(int offsetX) {
|
||||
}
|
||||
|
||||
void Traveller::adjustPosY(int offsetY) {
|
||||
int maxY = GetMaxX();
|
||||
int maxY = getMaxX();
|
||||
int deltaY = _posY + offsetY;
|
||||
|
||||
if (deltaY < 0) _posY = maxY + deltaY;
|
||||
@ -73,7 +73,7 @@ void Traveller::adjustXY(int offsetX, int offsetY) {
|
||||
float Traveller::calcH() {
|
||||
float retVal = 0;
|
||||
// Calc dist from here to target
|
||||
retVal = GetDistance(_posX, _posY, _targetPosX, _targetPosY);
|
||||
retVal = getDistance(_posX, _posY, _targetPosX, _targetPosY);
|
||||
// Divide by _maxDist to get minimum number of jumps to goal
|
||||
retVal /= static_cast<float>(_maxDist);
|
||||
|
||||
@ -82,7 +82,7 @@ float Traveller::calcH() {
|
||||
|
||||
int Traveller::numChildrenToGen() {
|
||||
if (!_numToGen)
|
||||
_numToGen = GetAnimSpeed() + 2;
|
||||
_numToGen = getAnimSpeed() + 2;
|
||||
|
||||
return _numToGen;
|
||||
}
|
||||
@ -103,14 +103,14 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
// Calculate angle between here and target
|
||||
int directAngle = 0;
|
||||
|
||||
if (GetEnergyHogType())
|
||||
directAngle = GetAngle(_posX, _posY, _targetPosX, _targetPosY, 1);
|
||||
if (getEnergyHogType())
|
||||
directAngle = calcAngle(_posX, _posY, _targetPosX, _targetPosY, 1);
|
||||
else
|
||||
directAngle = GetAngle(_posX, _posY, _targetPosX, _targetPosY);
|
||||
directAngle = calcAngle(_posX, _posY, _targetPosX, _targetPosY);
|
||||
|
||||
// Calculate the offset angle for this index
|
||||
if (!_sizeAngleStep)
|
||||
_sizeAngleStep = 52 - (GetAnimSpeed() * 7);
|
||||
_sizeAngleStep = 52 - (getAnimSpeed() * 7);
|
||||
|
||||
dir = _sizeAngleStep * ((static_cast<int>(index / NUM_POWER_STEPS) + 1) >> 1);
|
||||
// Calculate the sign value for the offset for this index
|
||||
@ -120,12 +120,12 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
|
||||
// Calculate power for this index
|
||||
int maxPower = 0;
|
||||
int directDist = GetDistance(_posX, _posY, _targetPosX, _targetPosY);
|
||||
int directDist = getDistance(_posX, _posY, _targetPosX, _targetPosY);
|
||||
|
||||
if (directDist > _maxDist + 120)
|
||||
maxPower = GetMaxPower();
|
||||
maxPower = getMaxPower();
|
||||
else
|
||||
maxPower = (static_cast<float>(directDist) / static_cast<float>(_maxDist + 120)) * GetMaxPower();
|
||||
maxPower = (static_cast<float>(directDist) / static_cast<float>(_maxDist + 120)) * getMaxPower();
|
||||
|
||||
maxPower -= 70;
|
||||
power = maxPower * (1 - ((index % NUM_POWER_STEPS) * SIZE_POWER_STEP));
|
||||
@ -139,7 +139,7 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
int coords = 0;
|
||||
|
||||
if (!(index % NUM_POWER_STEPS) || (!lastSuccessful)) {
|
||||
coords = SimulateBuildingLaunch(_posX, _posY, power, angle, 10, 0);
|
||||
coords = simulateBuildingLaunch(_posX, _posY, power, angle, 10, 0);
|
||||
lastSuccessful = 0;
|
||||
} else {
|
||||
completionState = 1;
|
||||
@ -156,34 +156,34 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
completionState = 1;
|
||||
}
|
||||
|
||||
int whoseTurn = GetCurrentPlayer();
|
||||
int maxX = GetMaxX();
|
||||
int whoseTurn = getCurrentPlayer();
|
||||
int maxX = getMaxX();
|
||||
|
||||
// Check new position to see if landing is clear
|
||||
if (coords > 0) {
|
||||
int yCoord = coords / maxX;
|
||||
int xCoord = coords - (yCoord * maxX);
|
||||
|
||||
int terrain = GetTerrain(xCoord, yCoord);
|
||||
int terrain = getTerrain(xCoord, yCoord);
|
||||
assert(terrain == TERRAIN_TYPE_GOOD);
|
||||
|
||||
float pwr = GetMinPower() * .3;
|
||||
float pwr = getMinPower() * .3;
|
||||
float cosine = cos((static_cast<float>(angle) / 360) * (2 * M_PI));
|
||||
float sine = sin((static_cast<float>(angle) / 360) * (2 * M_PI));
|
||||
int xParam = xCoord + (pwr * cosine);
|
||||
int yParam = yCoord + (pwr * sine);
|
||||
|
||||
if (xParam < 0)
|
||||
xParam += GetMaxX();
|
||||
else if (xParam > GetMaxX())
|
||||
xParam -= GetMaxX();
|
||||
xParam += getMaxX();
|
||||
else if (xParam > getMaxX())
|
||||
xParam -= getMaxX();
|
||||
|
||||
if (yParam < 0)
|
||||
yParam += GetMaxY();
|
||||
else if (yParam > GetMaxY())
|
||||
yParam -= GetMaxY();
|
||||
yParam += getMaxY();
|
||||
else if (yParam > getMaxY())
|
||||
yParam -= getMaxY();
|
||||
|
||||
if (CheckIfWaterState(xParam, yParam)) {
|
||||
if (checkIfWaterState(xParam, yParam)) {
|
||||
delete retTraveller;
|
||||
return NULL;
|
||||
}
|
||||
@ -192,7 +192,7 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
retTraveller->setPosX(xCoord);
|
||||
|
||||
// Iterate through the previous action list, making sure this one isn't on it
|
||||
for (intVecItr i = (lastXCoord[whoseTurn]).begin(), j = (lastYCoord[whoseTurn]).begin(); i != (lastXCoord[whoseTurn]).end(); ++i, ++j) {
|
||||
for (intVecItr i = (lastXCoord[whoseTurn]).begin(), j = (lastYCoord[whoseTurn]).begin(); i != (lastXCoord[whoseTurn]).end(); i++, j++) {
|
||||
// Check if this shot is the same as the last time we tried
|
||||
if ((*i == retTraveller->getPosX()) && (*j == retTraveller->getPosY())) {
|
||||
retTraveller->setDisabled();
|
||||
@ -208,8 +208,8 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
int xCoord = -coords - (yCoord * maxX);
|
||||
|
||||
// If landing fault is because of water, add 1 extra to g and turn on water flag. Also set coords, and adjust power to water fault location
|
||||
if (CheckIfWaterState(xCoord, yCoord)) {
|
||||
int terrainSquareSize = GetTerrainSquareSize();
|
||||
if (checkIfWaterState(xCoord, yCoord)) {
|
||||
int terrainSquareSize = getTerrainSquareSize();
|
||||
xCoord = ((xCoord / terrainSquareSize * terrainSquareSize) + (terrainSquareSize / 2));
|
||||
yCoord = ((yCoord / terrainSquareSize * terrainSquareSize) + (terrainSquareSize / 2));
|
||||
|
||||
@ -218,10 +218,10 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
retTraveller->setPosX(xCoord + (terrainSquareSize * 1.414 * (xDist / (abs(xDist) + 1))));
|
||||
retTraveller->setPosY(yCoord + (terrainSquareSize * 1.414 * (yDist / (abs(yDist) + 1))));
|
||||
|
||||
int closestHub = GetClosestUnit(retTraveller->getPosX(), retTraveller->getPosY(), GetMaxX(), GetCurrentPlayer(), 1, BUILDING_MAIN_BASE, 1, 110);
|
||||
int closestHub = getClosestUnit(retTraveller->getPosX(), retTraveller->getPosY(), getMaxX(), getCurrentPlayer(), 1, BUILDING_MAIN_BASE, 1, 110);
|
||||
|
||||
retTraveller->setWaterSourceX(GetHubX(closestHub));
|
||||
retTraveller->setWaterSourceY(GetHubY(closestHub));
|
||||
retTraveller->setWaterSourceX(getHubX(closestHub));
|
||||
retTraveller->setWaterSourceY(getHubY(closestHub));
|
||||
retTraveller->setWaterDestX(retTraveller->getPosX());
|
||||
retTraveller->setWaterDestY(retTraveller->getPosY());
|
||||
|
||||
@ -242,7 +242,7 @@ IContainedObject *Traveller::createChildObj(int index, int &completionFlag) {
|
||||
}
|
||||
|
||||
int Traveller::checkSuccess() {
|
||||
if (GetDistance(_posX + 1, _posY, _targetPosX, _targetPosY) < _maxDist)
|
||||
if (getDistance(_posX + 1, _posY, _targetPosX, _targetPosY) < _maxDist)
|
||||
return SUCCESS;
|
||||
|
||||
return 0;
|
||||
|
@ -108,7 +108,7 @@ public:
|
||||
|
||||
void enableWaterFlag() { _waterFlag = 1; }
|
||||
void disableWaterFlag() { _waterFlag = 0; }
|
||||
int GetWaterFlag() const { return _waterFlag; }
|
||||
int getWaterFlag() const { return _waterFlag; }
|
||||
|
||||
virtual int numChildrenToGen();
|
||||
virtual IContainedObject *createChildObj(int, int &);
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
|
||||
void duplicateTree(Node *sourceNode, Node *destNode);
|
||||
|
||||
Node *GetBaseNode() const { return pBaseNode; }
|
||||
Node *getBaseNode() const { return pBaseNode; }
|
||||
void setMaxDepth(int maxDepth) { m_maxDepth = maxDepth; }
|
||||
int getMaxDepth() const { return m_maxDepth; }
|
||||
|
||||
|
@ -77,19 +77,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
int GetID() const { return _id; }
|
||||
char *GetNameString() const { return _nameString; }
|
||||
int GetBehaviorVariation() const { return _behaviorVariation; }
|
||||
int GetTargetVariation() const { return _targetVariation; }
|
||||
int GetAngleVariation() const { return _angleVariation; }
|
||||
int GetPowerVariation() const { return _powerVariation; }
|
||||
int getID() const { return _id; }
|
||||
char *getNameString() const { return _nameString; }
|
||||
int getBehaviorVariation() const { return _behaviorVariation; }
|
||||
int getTargetVariation() const { return _targetVariation; }
|
||||
int getAngleVariation() const { return _angleVariation; }
|
||||
int getPowerVariation() const { return _powerVariation; }
|
||||
|
||||
void SetID(int id) { _id = id; }
|
||||
void SetNameString(char *nameString) { _nameString = nameString; }
|
||||
void SetBehaviorVariation(int behaviorVariation) { _behaviorVariation = behaviorVariation; }
|
||||
void SetTargetVariation(int targetVariation) { _targetVariation = targetVariation; }
|
||||
void SetAngleVariation(int angleVariation) { _angleVariation = angleVariation; }
|
||||
void SetPowerVariation(int powerVariation) { _powerVariation = powerVariation; }
|
||||
void setID(int id) { _id = id; }
|
||||
void setNameString(char *nameString) { _nameString = nameString; }
|
||||
void setBehaviorVariation(int behaviorVariation) { _behaviorVariation = behaviorVariation; }
|
||||
void setTargetVariation(int targetVariation) { _targetVariation = targetVariation; }
|
||||
void setAngleVariation(int angleVariation) { _angleVariation = angleVariation; }
|
||||
void setPowerVariation(int powerVariation) { _powerVariation = powerVariation; }
|
||||
};
|
||||
|
||||
} // End of namespace Scumm
|
||||
|
@ -38,6 +38,22 @@ int Moonbase::readFromArray(int array, int y, int x) {
|
||||
return _vm->readArray(116, y, x);
|
||||
}
|
||||
|
||||
int Moonbase::callScummFunction(int scriptNumber, int paramCount,...) {
|
||||
va_list va_params;
|
||||
va_start(va_params, paramCount);
|
||||
int args[25];
|
||||
|
||||
for (int i = 0; i < paramCount; i++)
|
||||
args[i] = va_arg(va_params, int);
|
||||
|
||||
va_end(va_params);
|
||||
|
||||
_vm->runScript(scriptNumber, 0, 1, args);
|
||||
|
||||
return _vm->pop();
|
||||
}
|
||||
|
||||
|
||||
void Moonbase::blitT14WizImage(uint8 *dst, int dstw, int dsth, int dstPitch, const Common::Rect *clipBox,
|
||||
uint8 *wizd, int x, int y, int rawROP, int paramROP) {
|
||||
bool premulAlpa = false;
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
~Moonbase();
|
||||
|
||||
int readFromArray(int array, int y, int x);
|
||||
int callScummFunction(int scriptNumber, int paramCount,...);
|
||||
|
||||
void blitT14WizImage(uint8 *dst, int dstw, int dsth, int dstPitch, const Common::Rect *clipBox,
|
||||
uint8 *wizd, int srcx, int srcy, int rawROP, int paramROP);
|
||||
|
@ -140,6 +140,7 @@ MODULE_OBJS += \
|
||||
he/logic/puttrace.o \
|
||||
he/logic/soccer.o \
|
||||
he/moonbase/ai_defenseunit.o \
|
||||
he/moonbase/ai_main.o \
|
||||
he/moonbase/ai_node.o \
|
||||
he/moonbase/ai_targetacquisition.o \
|
||||
he/moonbase/ai_traveller.o \
|
||||
|
@ -891,6 +891,13 @@ ScummEngine_v90he::ScummEngine_v90he(OSystem *syst, const DetectorResult &dr)
|
||||
|
||||
if (_game.id == GID_MOONBASE)
|
||||
_moonbase = new Moonbase(this);
|
||||
|
||||
VAR_U32_USER_VAR_A = 0xFF;
|
||||
VAR_U32_USER_VAR_B = 0xFF;
|
||||
VAR_U32_USER_VAR_C = 0xFF;
|
||||
VAR_U32_USER_VAR_D = 0xFF;
|
||||
VAR_U32_USER_VAR_E = 0xFF;
|
||||
VAR_U32_USER_VAR_F = 0xFF;
|
||||
}
|
||||
|
||||
ScummEngine_v90he::~ScummEngine_v90he() {
|
||||
|
@ -700,8 +700,9 @@ protected:
|
||||
void ignoreScriptWord() { fetchScriptWord(); }
|
||||
void ignoreScriptByte() { fetchScriptByte(); }
|
||||
void push(int a);
|
||||
|
||||
public: // TODO. FIXME should be protected. Used by Moonbase
|
||||
int pop();
|
||||
public: // TODO. FIXME
|
||||
virtual int readVar(uint var);
|
||||
virtual void writeVar(uint var, int value);
|
||||
|
||||
|
@ -77,7 +77,8 @@ protected:
|
||||
|
||||
void getResultPosIndirect();
|
||||
virtual void getResultPos();
|
||||
public: // TODO. FIXME
|
||||
|
||||
public: // TODO. FIXME. Should be protected. Used by Moonbase
|
||||
virtual int readVar(uint var);
|
||||
virtual void writeVar(uint var, int value);
|
||||
|
||||
|
@ -340,6 +340,14 @@ void ScummEngine_v90he::setupScummVars() {
|
||||
VAR_NUM_PALETTES = 130;
|
||||
VAR_NUM_UNK = 131;
|
||||
}
|
||||
if (_game.id == GID_MOONBASE) {
|
||||
VAR_U32_USER_VAR_A = 108;
|
||||
VAR_U32_USER_VAR_B = 109;
|
||||
VAR_U32_USER_VAR_C = 110;
|
||||
VAR_U32_USER_VAR_D = 111;
|
||||
VAR_U32_USER_VAR_E = 112;
|
||||
VAR_U32_USER_VAR_F = 113;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user