Replace pointer by reference for CUnit.

Change some position by Vec2i
TODO : Regenerate tolua.cpp
This commit is contained in:
Joris 2010-11-07 17:36:03 +01:00
parent 15bd9db0cb
commit 545cb0bba7
3 changed files with 30 additions and 40 deletions

View file

@ -1253,7 +1253,7 @@ extern void UnitClearOrders(CUnit &unit);
/// @todo more docu
extern void UpdateForNewUnit(const CUnit &unit, int upgrade);
/// @todo more docu
extern void NearestOfUnit(const CUnit &unit, int tx, int ty, int *dx, int *dy);
extern void NearestOfUnit(const CUnit &unit, int tx, int ty, Vec2i *dpos);
/// Call when an Unit goes under fog.
extern void UnitGoesUnderFog(CUnit &unit, const CPlayer *player);

View file

@ -360,8 +360,6 @@ void FireMissile(CUnit &unit)
{
int x;
int y;
int dx;
int dy;
CUnit *goal = unit.CurrentOrder()->GetGoal();
//
@ -389,26 +387,24 @@ void FireMissile(CUnit &unit)
if (unit.Type->Missile.Missile->Class == MissileClassNone) {
// No goal, take target coordinates
if (!goal) {
dx = unit.CurrentOrder()->goalPos.x;
dy = unit.CurrentOrder()->goalPos.y;
if (Map.WallOnMap(dx, dy)) {
if (Map.HumanWallOnMap(dx, dy)) {
Map.HitWall(dx, dy,
const Vec2i& goalPos = unit.CurrentOrder()->goalPos;
if (Map.WallOnMap(goalPos.x, goalPos.y)) {
if (Map.HumanWallOnMap(goalPos.x, goalPos.y)) {
Map.HitWall(goalPos.x, goalPos.y,
CalculateDamageStats(*unit.Stats,
*UnitTypeHumanWall->Stats, unit.Variable[BLOODLUST_INDEX].Value));
} else {
Map.HitWall(dx, dy,
Map.HitWall(goalPos.x, goalPos.y,
CalculateDamageStats(*unit.Stats,
*UnitTypeOrcWall->Stats, unit.Variable[BLOODLUST_INDEX].Value));
}
return;
}
DebugPrint("Missile-none hits no unit, shouldn't happen!\n");
return;
}
HitUnit(&unit, *goal, CalculateDamage(unit, *goal));
return;
}
@ -421,6 +417,7 @@ void FireMissile(CUnit &unit)
y = unit.tilePos.y * TileSizeY + TileSizeY / 2;
}
Vec2i dpos;
if (goal) {
Assert(goal->Type); // Target invalid?
//
@ -435,20 +432,19 @@ void FireMissile(CUnit &unit)
// Fire to nearest point of the unit!
// If Firing from inside a Bunker
if (unit.Container) {
NearestOfUnit(*goal, unit.Container->tilePos.x, unit.Container->tilePos.y, &dx, &dy);
NearestOfUnit(*goal, unit.Container->tilePos.x, unit.Container->tilePos.y, &dpos);
} else {
NearestOfUnit(*goal, unit.tilePos.x, unit.tilePos.y, &dx, &dy);
NearestOfUnit(*goal, unit.tilePos.x, unit.tilePos.y, &dpos);
}
} else {
dx = unit.CurrentOrder()->goalPos.x;
dy = unit.CurrentOrder()->goalPos.y;
dpos = unit.CurrentOrder()->goalPos;
// FIXME: Can this be too near??
}
// Fire to the tile center of the destination.
dx = dx * TileSizeX + TileSizeX / 2;
dy = dy * TileSizeY + TileSizeY / 2;
Missile *missile = MakeMissile(unit.Type->Missile.Missile, x, y, dx, dy);
dpos.x = dpos.x * TileSizeX + TileSizeX / 2;
dpos.y = dpos.y * TileSizeY + TileSizeY / 2;
Missile *missile = MakeMissile(unit.Type->Missile.Missile, x, y, dpos.x, dpos.y);
//
// Damage of missile
//

View file

@ -1069,27 +1069,26 @@ void UpdateForNewUnit(const CUnit &unit, int upgrade)
** @param unit Pointer to unit.
** @param tx X tile map postion.
** @param ty Y tile map postion.
** @param dx Out: nearest point X tile map postion to (tx,ty).
** @param dy Out: nearest point Y tile map postion to (tx,ty).
** @param dpos Out: nearest point tile map postion to (tx,ty).
*/
void NearestOfUnit(const CUnit &unit, int tx, int ty, int *dx, int *dy)
void NearestOfUnit(const CUnit &unit, int tx, int ty, Vec2i *dpos)
{
int x = unit.tilePos.x;
int y = unit.tilePos.y;
if (tx >= x + unit.Type->TileWidth) {
*dx = x + unit.Type->TileWidth - 1;
dpos->x = x + unit.Type->TileWidth - 1;
} else if (tx < x) {
*dx = x;
dpos->x = x;
} else {
*dx = tx;
dpos->x = tx;
}
if (ty >= y + unit.Type->TileHeight) {
*dy = y + unit.Type->TileHeight - 1;
dpos->y = y + unit.Type->TileHeight - 1;
} else if (ty < y) {
*dy = y;
dpos->y = y;
} else {
*dy = ty;
dpos->y = ty;
}
}
@ -2290,21 +2289,19 @@ CUnit *UnitFindResource(const CUnit &unit, int x, int y, int range, int resource
unsigned char *matrix;
CUnit *mine;
CUnit *bestmine;
int destx;
int desty;
Vec2i dest = {x, y};
int bestd = 99999, bestw = 99999, besta = 99999;
int cdist;
const ResourceInfo *resinfo = unit.Type->ResInfo[resource];
destx = x;
desty = y;
size = std::min<int>(Map.Info.MapWidth * Map.Info.MapHeight / 4, range * range * 5);
points = new Vec2i[size];
// Find the nearest gold depot
if (!destu) destu = FindDepositNearLoc(unit.Player,x,y,range,resource);
if (!destu)
destu = FindDepositNearLoc(unit.Player,x,y,range,resource);
if (destu) {
NearestOfUnit(*destu, x, y, &destx, &desty);
NearestOfUnit(*destu, x, y, &dest);
}
// Make movement matrix. FIXME: can create smaller matrix.
@ -2366,7 +2363,7 @@ CUnit *UnitFindResource(const CUnit &unit, int x, int y, int range, int resource
bool better = (mine != bestmine);
if(better) {
n = std::max<int>(MyAbs(destx - x), MyAbs(desty - y));
n = std::max<int>(MyAbs(dest.x - x), MyAbs(dest.y - y));
if(check_usage && mine->Type->MaxOnBoard) {
int assign = mine->Data.Resource.Assigned -
mine->Type->MaxOnBoard;
@ -2511,21 +2508,18 @@ CUnit *UnitFindMiningArea(const CUnit &unit, int x, int y, int range, int resou
const CUnit *destu;
CUnit *mine;
CUnit *bestmine;
int destx;
int desty;
Vec2i dest = {x, y};
int bestd;
int cdist;
//const ResourceInfo *resinfo = unit.Type->ResInfo[resource];
destx = x;
desty = y;
size = std::min<int>(Map.Info.MapWidth * Map.Info.MapHeight / 4, range * range * 5);
points = new Vec2i[size];
// Find the nearest resource depot
if ((destu = FindDepositNearLoc(unit.Player,x,y,range,resource)))
{
NearestOfUnit(*destu, x, y, &destx, &desty);
NearestOfUnit(*destu, x, y, &dest);
}
bestd = 99999;
// Make movement matrix. FIXME: can create smaller matrix.
@ -2577,7 +2571,7 @@ CUnit *UnitFindMiningArea(const CUnit &unit, int x, int y, int range, int resou
//
if ((mine = ResourceOnMap(x, y, resource, false))) {
if (destu) {
n = std::max<int>(MyAbs(destx - x), MyAbs(desty - y));
n = std::max<int>(MyAbs(dest.x - x), MyAbs(dest.y - y));
if (n < bestd) {
bestd = n;
bestmine = mine;