[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src action/action_resource.c ai/ai_bu...
From: |
address@hidden |
Subject: |
[Stratagus-CVS] stratagus/src action/action_resource.c ai/ai_bu... |
Date: |
29 Jan 2004 23:50:40 +1100 |
CVSROOT: /home/strat
Module name: stratagus
Changes by: <address@hidden> 04/01/29 23:50:38
Modified files:
src/action : action_resource.c
src/ai : ai_building.c ai_plan.c ai_resource.c
src/game : trigger.c
src/include : unit.h
src/missile : missile.c
src/network : commands.c
src/stratagus : script_player.c selection.c spells.c
src/unit : script_unit.c unit.c unit_cache.c unit_draw.c
unit_find.c
Log message:
Fix resource bug.
Remove SelectUnits SelectUnitsOnTile.
Patches:
Index: stratagus/src/action/action_resource.c
diff -u stratagus/src/action/action_resource.c:1.74
stratagus/src/action/action_resource.c:1.75
--- stratagus/src/action/action_resource.c:1.74 Thu Jan 15 09:31:01 2004
+++ stratagus/src/action/action_resource.c Thu Jan 29 23:50:29 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_resource.c,v 1.74 2004/01/14 22:31:01 nobody_ Exp $
+// $Id: action_resource.c,v 1.75 2004/01/29 12:50:29 nobody_ Exp $
//@{
@@ -712,7 +712,8 @@
unit->Reset = 1;
unit->Orders[0].X = unit->Orders[0].Y = -1;
unit->SubAction = 0;
- if (unit->Type->ResInfo[unit->CurrentResource]->LoseResources &&
+ if (unit->CurrentResource &&
+
unit->Type->ResInfo[unit->CurrentResource]->LoseResources &&
unit->Value <
unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) {
unit->Value = 0;
unit->CurrentResource = 0;
@@ -752,12 +753,16 @@
// Drop other resources.
unit->Value = 0;
}
- unit->CurrentResource = newres;
- NewResetPath(unit);
- DebugLevel3Fn("Started mining. reset path.\n");
- unit->SubAction = SUB_MOVE_TO_RESOURCE;
+ if ((unit->CurrentResource = newres)) {
+ NewResetPath(unit);
+ DebugLevel3Fn("Started mining. reset path.\n");
+ unit->SubAction = SUB_MOVE_TO_RESOURCE;
+ } else {
+ unit->Value = 0;
+ ResourceGiveUp(unit);
+ return;
+ }
}
- DebugCheck(!unit->CurrentResource);
// Move to the resource location.
if (unit->SubAction >= SUB_MOVE_TO_RESOURCE &&
Index: stratagus/src/ai/ai_building.c
diff -u stratagus/src/ai/ai_building.c:1.46 stratagus/src/ai/ai_building.c:1.47
--- stratagus/src/ai/ai_building.c:1.46 Fri Jan 2 08:24:03 2004
+++ stratagus/src/ai/ai_building.c Thu Jan 29 23:50:30 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_building.c,v 1.46 2004/01/01 21:24:03 jsalmon3 Exp $
+// $Id: ai_building.c,v 1.47 2004/01/29 12:50:30 nobody_ Exp $
//@{
@@ -388,7 +388,7 @@
maxy = TheMap.Height;
}
- nunits = SelectUnits(minx, miny, maxx,
maxy, units);
+ nunits = UnitCacheSelect(minx, miny,
maxx, maxy, units);
for (j = 0; j < nunits; ++j) {
// Enemy near mine
if (AiPlayer->Player->Enemy &
(1 << units[j]->Player->Player)) {
Index: stratagus/src/ai/ai_plan.c
diff -u stratagus/src/ai/ai_plan.c:1.29 stratagus/src/ai/ai_plan.c:1.30
--- stratagus/src/ai/ai_plan.c:1.29 Thu Jan 15 09:31:03 2004
+++ stratagus/src/ai/ai_plan.c Thu Jan 29 23:50:30 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_plan.c,v 1.29 2004/01/14 22:31:03 nobody_ Exp $
+// $Id: ai_plan.c,v 1.30 2004/01/29 12:50:30 nobody_ Exp $
//@{
@@ -71,7 +71,7 @@
int n;
int i;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
best = NoUnitP;
for (i = 0; i < n; ++i) {
unit = table[i];
Index: stratagus/src/ai/ai_resource.c
diff -u stratagus/src/ai/ai_resource.c:1.89 stratagus/src/ai/ai_resource.c:1.90
--- stratagus/src/ai/ai_resource.c:1.89 Mon Jan 19 09:36:23 2004
+++ stratagus/src/ai/ai_resource.c Thu Jan 29 23:50:30 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_resource.c,v 1.89 2004/01/18 22:36:23 nobody_ Exp $
+// $Id: ai_resource.c,v 1.90 2004/01/29 12:50:30 nobody_ Exp $
//@{
@@ -206,7 +206,7 @@
//
x = unit->X;
y = unit->Y;
- n = SelectUnits(x - range, y - range, x + range + 1, y + range + 1,
table);
+ n = UnitCacheSelect(x - range, y - range, x + range + 1, y + range + 1,
table);
player = unit->Player;
type = unit->Type;
Index: stratagus/src/game/trigger.c
diff -u stratagus/src/game/trigger.c:1.60 stratagus/src/game/trigger.c:1.61
--- stratagus/src/game/trigger.c:1.60 Wed Jan 21 11:46:37 2004
+++ stratagus/src/game/trigger.c Thu Jan 29 23:50:31 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: trigger.c,v 1.60 2004/01/21 00:46:37 jsalmon3 Exp $
+// $Id: trigger.c,v 1.61 2004/01/29 12:50:31 nobody_ Exp $
//@{
@@ -339,7 +339,7 @@
// FIXME: I hope SelectUnits checks bounds?
// FIXME: Yes, but caller should check.
// NOTE: +1 right,bottom isn't inclusive :(
- an = SelectUnits(x1, y1, x2 + 1, y2 + 1, table);
+ an = UnitCacheSelect(x1, y1, x2 + 1, y2 + 1, table);
//
// Count the requested units
//
@@ -424,11 +424,11 @@
// FIXME: Yes, but caller should check.
// NOTE: +1 right,bottom isn't inclusive :(
if (unit->Type->UnitType == UnitTypeLand) {
- an = SelectUnits(unit->X - 1, unit->Y - 1,
+ an = UnitCacheSelect(unit->X - 1, unit->Y - 1,
unit->X + unit->Type->TileWidth + 1,
unit->Y + unit->Type->TileHeight + 1, around);
} else {
- an = SelectUnits(unit->X - 2, unit->Y - 2,
+ an = UnitCacheSelect(unit->X - 2, unit->Y - 2,
unit->X + unit->Type->TileWidth + 2,
unit->Y + unit->Type->TileHeight + 2, around);
}
@@ -524,11 +524,11 @@
// FIXME: Yes, but caller should check.
// NOTE: +1 right,bottom isn't inclusive :(
if (unit->Type->UnitType == UnitTypeLand) {
- an = SelectUnits(unit->X - 1, unit->Y - 1,
+ an = UnitCacheSelect(unit->X - 1, unit->Y - 1,
unit->X + unit->Type->TileWidth + 1,
unit->Y + unit->Type->TileHeight + 1, around);
} else {
- an = SelectUnits(unit->X - 2, unit->Y - 2,
+ an = UnitCacheSelect(unit->X - 2, unit->Y - 2,
unit->X + unit->Type->TileWidth + 2,
unit->Y + unit->Type->TileHeight + 2, around);
}
Index: stratagus/src/include/unit.h
diff -u stratagus/src/include/unit.h:1.251 stratagus/src/include/unit.h:1.252
--- stratagus/src/include/unit.h:1.251 Fri Jan 23 05:12:23 2004
+++ stratagus/src/include/unit.h Thu Jan 29 23:50:32 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.h,v 1.251 2004/01/22 18:12:23 nobody_ Exp $
+// $Id: unit.h,v 1.252 2004/01/29 12:50:32 nobody_ Exp $
#ifndef __UNIT_H__
#define __UNIT_H__
@@ -945,10 +945,6 @@
extern void ShowOrder(const Unit* unit);
// in unit_find.c
- /// Select units in rectangle range
-extern int SelectUnits(int x1, int y1, int x2, int y2, Unit** table);
- /// Select units on map tile
-extern int SelectUnitsOnTile(int x, int y, Unit** table);
/// Find all units of this type
extern int FindUnitsByType(const UnitType* type, Unit** table);
/// Find all units of this type of the player
Index: stratagus/src/missile/missile.c
diff -u stratagus/src/missile/missile.c:1.133
stratagus/src/missile/missile.c:1.134
--- stratagus/src/missile/missile.c:1.133 Sun Jan 25 16:51:44 2004
+++ stratagus/src/missile/missile.c Thu Jan 29 23:50:33 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: missile.c,v 1.133 2004/01/25 05:51:44 wizzard Exp $
+// $Id: missile.c,v 1.134 2004/01/29 12:50:33 nobody_ Exp $
//@{
@@ -1035,7 +1035,7 @@
// Hits all units in range.
//
i = missile->Type->Range;
- n = SelectUnits(x - i + 1, y - i + 1, x + i, y + i, table);
+ n = UnitCacheSelect(x - i + 1, y - i + 1, x + i, y + i, table);
DebugCheck(missile->SourceUnit == NULL);
for (i = 0; i < n; ++i) {
goal = table[i];
@@ -1289,7 +1289,7 @@
DebugCheck(file == NULL);
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.133
2004/01/25 05:51:44 wizzard Exp $\n\n");
+ CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.134
2004/01/29 12:50:33 nobody_ Exp $\n\n");
//
// Original number to internal missile-type name.
@@ -1411,7 +1411,7 @@
Missile* const* missiles;
CLprintf(file,"\n--- -----------------------------------------\n");
- CLprintf(file,"--- MODULE: missiles $Id: missile.c,v 1.133 2004/01/25
05:51:44 wizzard Exp $\n\n");
+ CLprintf(file,"--- MODULE: missiles $Id: missile.c,v 1.134 2004/01/29
12:50:33 nobody_ Exp $\n\n");
for (missiles = GlobalMissiles; *missiles; ++missiles) {
SaveMissile(*missiles, file);
@@ -1807,7 +1807,7 @@
if (missile->TTL & 7) {
return;
}
- n = SelectUnits(ux - 1, uy - 1, ux + 1 + 1, uy + 1 + 1, table);
+ n = UnitCacheSelect(ux - 1, uy - 1, ux + 1 + 1, uy + 1 + 1, table);
for (i = 0; i < n; ++i) {
if (table[i] == unit) {
// cannot hit target unit
@@ -1837,7 +1837,7 @@
x = missile->X / TileSizeX;
y = missile->Y / TileSizeY;
- n = SelectUnitsOnTile(x, y, table);
+ n = UnitCacheOnTile(x, y, table);
for (i = 0; i < n; ++i) {
if (table[i]->Type->UnitType != UnitTypeFly &&
table[i]->HP &&
@@ -1988,7 +1988,7 @@
x = missile->DX / TileSizeX;
y = missile->DY / TileSizeY;
- n = SelectUnits(x - 2, y - 2, x + 2, y + 2, table);
+ n = UnitCacheSelect(x - 2, y - 2, x + 2, y + 2, table);
if (n == 0) {
return;
}
Index: stratagus/src/network/commands.c
diff -u stratagus/src/network/commands.c:1.101
stratagus/src/network/commands.c:1.102
--- stratagus/src/network/commands.c:1.101 Thu Jan 29 20:01:14 2004
+++ stratagus/src/network/commands.c Thu Jan 29 23:50:34 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: commands.c,v 1.101 2004/01/29 09:01:14 wizzard Exp $
+// $Id: commands.c,v 1.102 2004/01/29 12:50:34 nobody_ Exp $
//@{
@@ -173,7 +173,7 @@
replay->Comment1 = strdup("Generated by Stratagus Version " VERSION "");
replay->Comment2 = strdup("Visit http://Stratagus.Org for more
information");
- replay->Comment3 = strdup("$Id: commands.c,v 1.101 2004/01/29 09:01:14
wizzard Exp $");
+ replay->Comment3 = strdup("$Id: commands.c,v 1.102 2004/01/29 12:50:34
nobody_ Exp $");
if (GameSettings.NetGameType == SettingsSinglePlayerGame) {
replay->Type = ReplaySinglePlayer;
@@ -821,14 +821,14 @@
// Replay without the 'sync info
NotifyPlayer(ThisPlayer, NotifyYellow, 0, 0, "No sync
info for this replay !");
} else {
- NotifyPlayer(ThisPlayer, NotifyYellow, 0, 0, "Replay
got out of sync (%lu)! ", GameCycle);
- DebugLevel0("OUT OF SYNC %u != %u" _C_ SyncRandSeed _C_
ReplayStep->SyncRandSeed);
+ NotifyPlayer(ThisPlayer, NotifyYellow, 0, 0, "Replay
got out of sync (%lu) !", GameCycle);
+ DebugLevel0("OUT OF SYNC %u != %u\n" _C_ SyncRandSeed
_C_ ReplayStep->SyncRandSeed);
// ReplayStep = 0;
// NextLogCycle = ~0UL;
// return;
}
#else
- NotifyPlayer(ThisPlayer, NotifyYellow, 0, 0, "Replay
got out of sync !");
+ NotifyPlayer(ThisPlayer, NotifyYellow, 0, 0, "Replay got out of
sync !");
ReplayStep = 0;
NextLogCycle = ~0UL;
return;
Index: stratagus/src/stratagus/script_player.c
diff -u stratagus/src/stratagus/script_player.c:1.58
stratagus/src/stratagus/script_player.c:1.59
--- stratagus/src/stratagus/script_player.c:1.58 Wed Jan 28 08:12:04 2004
+++ stratagus/src/stratagus/script_player.c Thu Jan 29 23:50:35 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: script_player.c,v 1.58 2004/01/27 21:12:04 jsalmon3 Exp $
+// $Id: script_player.c,v 1.59 2004/01/29 12:50:35 nobody_ Exp $
//@{
@@ -408,7 +408,7 @@
y2 = LuaToNumber(l, -1);
lua_pop(l, 1);
- n = SelectUnits(x1, y1, x2, y2, table);
+ n = UnitCacheSelect(x1, y1, x2, y2, table);
oldp = LuaToNumber(l, 3);
newp = LuaToNumber(l, 4);
while (n) {
Index: stratagus/src/stratagus/selection.c
diff -u stratagus/src/stratagus/selection.c:1.69
stratagus/src/stratagus/selection.c:1.70
--- stratagus/src/stratagus/selection.c:1.69 Thu Jan 22 17:18:21 2004
+++ stratagus/src/stratagus/selection.c Thu Jan 29 23:50:35 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: selection.c,v 1.69 2004/01/22 06:18:21 wizzard Exp $
+// $Id: selection.c,v 1.70 2004/01/29 12:50:35 nobody_ Exp $
//@{
@@ -347,7 +347,7 @@
/* FIXME: this should probably be cleaner implemented if
SelectUnitsByType()
* took parameters of the selection rectangle as arguments */
vp = TheUI.MouseViewport;
- r = SelectUnits(vp->MapX - 1, vp->MapY - 1, vp->MapX + vp->MapWidth + 1,
+ r = UnitCacheSelect(vp->MapX - 1, vp->MapY - 1, vp->MapX + vp->MapWidth
+ 1,
vp->MapY + vp->MapHeight + 1, table);
// if unit is a cadaver or hidden (not on map)
@@ -445,7 +445,7 @@
// StephanR: should be (MapX,MapY,MapX+MapWidth-1,MapY+MapHeight-1) ???
// FIXME: this should probably be cleaner implemented if
SelectUnitsByType()
// took parameters of the selection rectangle as arguments */
- r = SelectUnits(TheUI.MouseViewport->MapX - 1,
+ r = UnitCacheSelect(TheUI.MouseViewport->MapX - 1,
TheUI.MouseViewport->MapY - 1,
TheUI.MouseViewport->MapX + TheUI.MouseViewport->MapWidth + 1,
TheUI.MouseViewport->MapY + TheUI.MouseViewport->MapHeight + 1,
table);
@@ -674,7 +674,7 @@
}
// If no unit in rectangle area... do nothing
- toggle_num = SelectUnits((x0 / TileSizeX) - 2, (y0 / TileSizeY) - 2,
+ toggle_num = UnitCacheSelect((x0 / TileSizeX) - 2, (y0 / TileSizeY) - 2,
(x1 / TileSizeX) + 2 + 1, (y1 / TileSizeX) + 2 + 1, table);
if (!toggle_num) {
return NumSelected;
@@ -731,7 +731,7 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = UnitCacheSelect(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
//
@@ -826,7 +826,7 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = UnitCacheSelect(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
for (n = i = 0; i < r; ++i) {
@@ -881,7 +881,7 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = UnitCacheSelect(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
for (n = i = 0; i < r; ++i) {
@@ -950,7 +950,7 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = UnitCacheSelect(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
for (n = i = 0; i < r; ++i) {
@@ -1024,7 +1024,7 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = UnitCacheSelect(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
for (n = i = 0; i < r; ++i) {
@@ -1086,7 +1086,7 @@
char* ref;
CLprintf(file, "\n--- -----------------------------------------\n");
- CLprintf(file, "--- MODULE: selection $Id: selection.c,v 1.69
2004/01/22 06:18:21 wizzard Exp $\n\n");
+ CLprintf(file, "--- MODULE: selection $Id: selection.c,v 1.70
2004/01/29 12:50:35 nobody_ Exp $\n\n");
CLprintf(file, "SetGroupId(%d)\n", GroupId);
CLprintf(file, "Selection(%d, {", NumSelected);
Index: stratagus/src/stratagus/spells.c
diff -u stratagus/src/stratagus/spells.c:1.142
stratagus/src/stratagus/spells.c:1.143
--- stratagus/src/stratagus/spells.c:1.142 Sun Jan 25 16:10:09 2004
+++ stratagus/src/stratagus/spells.c Thu Jan 29 23:50:35 2004
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: spells.c,v 1.142 2004/01/25 05:10:09 wizzard Exp $
+// $Id: spells.c,v 1.143 2004/01/29 12:50:35 nobody_ Exp $
/*
** And when we cast our final spell
@@ -135,7 +135,7 @@
// Effect of the explosion on units. Don't bother if
damage is 0
//
if (action->Data.Demolish.Damage) {
- n = SelectUnits(xmin, ymin, xmax, ymax, table);
+ n = UnitCacheSelect(xmin, ymin, xmax, ymax, table);
for (i = 0; i < n; ++i) {
DebugLevel3("Hit an unit at %d %d?\n" _C_ table[i]->X
_C_ table[i]->Y);
if (table[i]->Type->UnitType != UnitTypeFly &&
table[i]->HP &&
@@ -235,7 +235,7 @@
DebugCheck(!spell);
DebugCheck(!action);
// Get all the units around the unit
- nunits = SelectUnits(x - spell->Range,
+ nunits = UnitCacheSelect(x - spell->Range,
y - spell->Range,
x + spell->Range + caster->Type->Width,
y + spell->Range + caster->Type->Height,
@@ -892,7 +892,7 @@
//
// Select all units aroung the caster
//
- nunits = SelectUnits(caster->X - range, caster->Y - range,
+ nunits = UnitCacheSelect(caster->X - range, caster->Y - range,
caster->X + range + caster->Type->TileWidth,
caster->Y + range + caster->Type->TileHeight, table);
//
Index: stratagus/src/unit/script_unit.c
diff -u stratagus/src/unit/script_unit.c:1.99
stratagus/src/unit/script_unit.c:1.100
--- stratagus/src/unit/script_unit.c:1.99 Thu Jan 29 19:30:54 2004
+++ stratagus/src/unit/script_unit.c Thu Jan 29 23:50:36 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: script_unit.c,v 1.99 2004/01/29 08:30:54 wizzard Exp $
+// $Id: script_unit.c,v 1.100 2004/01/29 12:50:36 nobody_ Exp $
//@{
@@ -1163,7 +1163,7 @@
}
order = LuaToString(l, 5);
- an = SelectUnits(x1, y1, x2 + 1, y2 + 1, table);
+ an = UnitCacheSelect(x1, y1, x2 + 1, y2 + 1, table);
for (j = 0; j < an; ++j) {
unit = table[j];
if (unittype == ANY_UNIT ||
@@ -1294,7 +1294,7 @@
y2 = LuaToNumber(l, -1);
lua_pop(l, 1);
- an = SelectUnits(x1, y1, x2 + 1, y2 + 1, table);
+ an = UnitCacheSelect(x1, y1, x2 + 1, y2 + 1, table);
for (j = s = 0; j < an && s < q; ++j) {
unit = table[j];
if (unittype == ANY_UNIT ||
Index: stratagus/src/unit/unit.c
diff -u stratagus/src/unit/unit.c:1.377 stratagus/src/unit/unit.c:1.378
--- stratagus/src/unit/unit.c:1.377 Wed Jan 28 07:54:46 2004
+++ stratagus/src/unit/unit.c Thu Jan 29 23:50:36 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.c,v 1.377 2004/01/27 20:54:46 jsalmon3 Exp $
+// $Id: unit.c,v 1.378 2004/01/29 12:50:36 nobody_ Exp $
//@{
@@ -1006,7 +1006,7 @@
Unit* units[UnitMax];
Unit* unit;
- n = SelectUnitsOnTile(x, y,units);
+ n = UnitCacheOnTile(x, y,units);
DebugLevel3Fn("I can see %d units from here.\n" _C_ n);
while (n) {
unit = units[--n];
@@ -1046,7 +1046,7 @@
Unit* units[UnitMax];
Unit* unit;
- n = SelectUnitsOnTile(x, y, units);
+ n = UnitCacheOnTile(x, y, units);
DebugLevel3Fn("I can see %d units from here.\n" _C_ n);
while (n) {
unit = units[--n];
@@ -1612,12 +1612,12 @@
// FIXME: Yes, but caller should check.
// NOTE: +1 right,bottom isn't inclusive :(
if (unit->Type->UnitType == UnitTypeLand) {
- n = SelectUnits(
+ n = UnitCacheSelect(
unit->X - 1, unit->Y -
1,
unit->X +
unit->Type->TileWidth + 1,
unit->Y +
unit->Type->TileHeight + 1, around);
} else {
- n = SelectUnits(
+ n = UnitCacheSelect(
unit->X - 2, unit->Y -
2,
unit->X +
unit->Type->TileWidth + 2,
unit->Y +
unit->Type->TileHeight + 2, around);
@@ -3770,7 +3770,7 @@
int j;
CLprintf(file, "\n--- -----------------------------------------\n");
- CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.377 2004/01/27
20:54:46 jsalmon3 Exp $\n\n");
+ CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.378 2004/01/29
12:50:36 nobody_ Exp $\n\n");
#if 0
//
Index: stratagus/src/unit/unit_cache.c
diff -u stratagus/src/unit/unit_cache.c:1.47
stratagus/src/unit/unit_cache.c:1.48
--- stratagus/src/unit/unit_cache.c:1.47 Thu Jan 29 21:20:09 2004
+++ stratagus/src/unit/unit_cache.c Thu Jan 29 23:50:37 2004
@@ -30,7 +30,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_cache.c,v 1.47 2004/01/29 10:20:09 nobody_ Exp $
+// $Id: unit_cache.c,v 1.48 2004/01/29 12:50:37 nobody_ Exp $
//@{
@@ -186,33 +186,6 @@
}
/**
-** Select unit on X,Y of type naval,fly,land.
-**
-** @param x Map X tile position.
-** @param y Map Y tile position.
-** @param type UnitType::UnitType, naval,fly,land.
-**
-** @return Unit, if an unit of correct
type is on the field.
-*/
-global Unit* UnitCacheOnXY(int x, int y, unsigned type)
-{
- Unit* table[UnitMax];
- int n;
-
- n = UnitCacheOnTile(x, y, table);
- while (n--) {
- if ((unsigned)table[n]->Type->UnitType == type) {
- break;
- }
- }
- if (n > -1) {
- return table[n];
- } else {
- return NoUnitP;
- }
-}
-
-/**
** Print unit-cache statistic.
*/
global void UnitCacheStatistic(void)
@@ -326,6 +299,11 @@
int n;
UnitListItem* listitem;
+ // Optimize small searches.
+ if (x1 == x2 && y1 == y2) {
+ return UnitCacheOnTile(x1, y1, table);
+ }
+
//
// Reduce to map limits. FIXME: should the caller check?
//
@@ -398,33 +376,6 @@
}
return n;
-}
-
-/**
-** Select unit on X,Y of type naval,fly,land.
-**
-** @param x Map X tile position.
-** @param y Map Y tile position.
-** @param type UnitType::UnitType, naval,fly,land.
-**
-** @return Unit, if an unit of correct
type is on the field.
-*/
-global Unit* UnitCacheOnXY(int x, int y, unsigned type)
-{
- Unit* table[UnitMax];
- int n;
-
- n = UnitCacheOnTile(x, y, table);
- while (n--) {
- if ((unsigned)table[n]->Type->UnitType == type) {
- break;
- }
- }
- if (n > -1) {
- return table[n];
- } else {
- return NoUnitP;
- }
}
/**
Index: stratagus/src/unit/unit_draw.c
diff -u stratagus/src/unit/unit_draw.c:1.215
stratagus/src/unit/unit_draw.c:1.216
--- stratagus/src/unit/unit_draw.c:1.215 Sat Jan 24 09:01:40 2004
+++ stratagus/src/unit/unit_draw.c Thu Jan 29 23:50:37 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_draw.c,v 1.215 2004/01/23 22:01:40 wizzard Exp $
+// $Id: unit_draw.c,v 1.216 2004/01/29 12:50:37 nobody_ Exp $
//@{
@@ -644,7 +644,7 @@
{
#if 0
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.215
2004/01/23 22:01:40 wizzard Exp $\n\n");
+ CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.216
2004/01/29 12:50:37 nobody_ Exp $\n\n");
CLprintf(file, "(mana-sprite \"%s\" %d %d %d %d)\n",
ManaSprite.File, ManaSprite.HotX, ManaSprite.HotY,
@@ -2054,7 +2054,7 @@
//
// Select all units touching the viewpoint.
//
- n = SelectUnits(vp->MapX - 1, vp->MapY - 1, vp->MapX + vp->MapWidth + 1,
+ n = UnitCacheSelect(vp->MapX - 1, vp->MapY - 1, vp->MapX + vp->MapWidth
+ 1,
vp->MapY + vp->MapHeight + 1, table);
if (n) {
Index: stratagus/src/unit/unit_find.c
diff -u stratagus/src/unit/unit_find.c:1.70 stratagus/src/unit/unit_find.c:1.71
--- stratagus/src/unit/unit_find.c:1.70 Mon Jan 19 09:36:31 2004
+++ stratagus/src/unit/unit_find.c Thu Jan 29 23:50:37 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_find.c,v 1.70 2004/01/18 22:36:31 nobody_ Exp $
+// $Id: unit_find.c,v 1.71 2004/01/29 12:50:37 nobody_ Exp $
//@{
@@ -76,40 +76,33 @@
----------------------------------------------------------------------------*/
/**
-** Select units in rectangle range.
+** Select unit on X,Y of type naval,fly,land.
**
-** @param x1 Left column of selection rectangle
-** @param y1 Top row of selection rectangle
-** @param x2 Right column of selection rectangle
-** @param y2 Bottom row of selection rectangle
-** @param table All units in the selection rectangle
+** @param x Map X tile position.
+** @param y Map Y tile position.
+** @param type UnitType::UnitType, naval,fly,land.
**
-** @return Returns the number of units
found
+** @return Unit, if an unit of correct
type is on the field.
*/
-global int SelectUnits(int x1, int y1, int x2, int y2, Unit** table)
+global Unit* UnitCacheOnXY(int x, int y, unsigned type)
{
- if (x1 == x2 && y1 == y2) {
- return UnitCacheOnTile(x1, y1, table);
+ Unit* table[UnitMax];
+ int n;
+
+ n = UnitCacheOnTile(x, y, table);
+ while (n--) {
+ if ((unsigned)table[n]->Type->UnitType == type) {
+ break;
+ }
+ }
+ if (n > -1) {
+ return table[n];
} else {
- return UnitCacheSelect(x1, y1, x2, y2, table);
+ return NoUnitP;
}
}
/**
-** Select units on tile.
-**
-** @param x Map X tile position
-** @param y Map Y tile position
-** @param table All units in the selection rectangle
-**
-** @return Returns the number of units
found
-*/
-global int SelectUnitsOnTile(int x, int y, Unit** table)
-{
- return UnitCacheOnTile(x, y, table);
-}
-
-/**
** Find all units of type.
**
** @param type type of unit requested
@@ -180,7 +173,7 @@
int n;
int i;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
for (i = 0; i < n; ++i) {
// Note: this is less restrictive than UnitActionDie...
// Is it normal?
@@ -207,7 +200,7 @@
int n;
int i;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
for (i = 0; i < n; ++i) {
if (table[i]->Type->RepairHP && table[i]->HP &&
table[i]->HP < table[i]->Stats->HitPoints) {
@@ -235,7 +228,7 @@
int n;
int i;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
best = NoUnitP;
for (i = 0; i < n; ++i) {
unit = table[i];
@@ -282,7 +275,7 @@
int n;
int i;
- n = SelectUnits(x1, y1, x2, y2, table);
+ n = UnitCacheSelect(x1, y1, x2, y2, table);
best = NoUnitP;
for (i = 0; i < n; ++i) {
unit = table[i];
@@ -322,7 +315,7 @@
int n;
int i;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
for (i = 0; i < n; ++i) {
if (table[i]->Type->Transporter) {
return table[i];
@@ -380,7 +373,7 @@
int i;
int n;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
for (i = 0; i < n; ++i) {
if (table[i]->Type == type) {
return table[i];
@@ -404,7 +397,7 @@
int i;
int n;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
for (i = 0; i < n; ++i) {
if (UnitUnusable(table[i]) || !table[i]->Type->CanHarvest ||
table[i]->Value == 0) {
@@ -432,7 +425,7 @@
int i;
int n;
- n = SelectUnitsOnTile(tx, ty, table);
+ n = UnitCacheOnTile(tx, ty, table);
for (i = 0; i < n; ++i) {
if (UnitUnusable(table[i])) {
continue;
@@ -511,13 +504,13 @@
if (u->Removed) {
x = u->Container->X;
y = u->Container->Y;
- n = SelectUnits(x - missile_range, y - missile_range,
+ n = UnitCacheSelect(x - missile_range, y - missile_range,
x + missile_range + u->Container->Type->TileWidth,
y + missile_range + u->Container->Type->TileHeight,
table);
} else {
x = u->X;
y = u->Y;
- n = SelectUnits(x - missile_range, y - missile_range,
+ n = UnitCacheSelect(x - missile_range, y - missile_range,
x + missile_range + u->Type->TileWidth,
y + missile_range + u->Type->TileHeight, table);
}
@@ -772,7 +765,7 @@
x = unit->X;
y = unit->Y;
type = unit->Type;
- n = SelectUnits(x - range, y - range, x + range + type->TileWidth - 1,
+ n = UnitCacheSelect(x - range, y - range, x + range + type->TileWidth -
1,
y + range + type->TileHeight - 1, table);
best_unit = NoUnitP;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src action/action_resource.c ai/ai_bu...,
address@hidden <=