[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/clone unit.c unit_find.c
From: |
Russell Smith |
Subject: |
[Stratagus-CVS] stratagus/src/clone unit.c unit_find.c |
Date: |
Fri, 17 Oct 2003 00:56:20 -0400 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Russell Smith <address@hidden> 03/10/17 00:56:20
Modified files:
src/clone : unit.c unit_find.c
Log message:
Removed Qsort, it's two slow for large units. Other Solutions for
UnitReachable will be used
Patches:
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.308 stratagus/src/clone/unit.c:1.309
--- stratagus/src/clone/unit.c:1.308 Tue Oct 7 08:03:39 2003
+++ stratagus/src/clone/unit.c Fri Oct 17 00:56:20 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.c,v 1.308 2003/10/07 12:03:39 martinxyz Exp $
+// $Id: unit.c,v 1.309 2003/10/17 04:56:20 mr-russ Exp $
//@{
@@ -3172,7 +3172,7 @@
**
** @return The distance between in tiles.
*/
-global int MapDistanceBetweenUnits(const Unit* src,const Unit* dst)
+global int MapDistanceBetweenUnits(const Unit* src, const Unit* dst)
{
int dx;
int dy;
@@ -3539,9 +3539,9 @@
// SEE unit loading code.
if( unit->Container && unit->Removed ) {
CLprintf(file," 'host-info '(%d %d %d %d) ",
- unit->Next->X,unit->Next->Y,
- unit->Next->Type->TileWidth,
- unit->Next->Type->TileHeight);
+ unit->Container->X,unit->Container->Y,
+ unit->Container->Type->TileWidth,
+ unit->Container->Type->TileHeight);
}
CLprintf(file," 'visible \"");
for( i=0; i<PlayerMax; ++i ) {
@@ -3715,7 +3715,7 @@
int InRun, RunStart;
CLprintf(file,"\n;;; -----------------------------------------\n");
- CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.308 2003/10/07 12:03:39
martinxyz Exp $\n\n");
+ CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.309 2003/10/17 04:56:20
mr-russ Exp $\n\n");
//
// Local variables
Index: stratagus/src/clone/unit_find.c
diff -u stratagus/src/clone/unit_find.c:1.61
stratagus/src/clone/unit_find.c:1.62
--- stratagus/src/clone/unit_find.c:1.61 Thu Oct 9 23:56:41 2003
+++ stratagus/src/clone/unit_find.c Fri Oct 17 00:56:20 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_find.c,v 1.61 2003/10/10 03:56:41 jsalmon3 Exp $
+// $Id: unit_find.c,v 1.62 2003/10/17 04:56:20 mr-russ Exp $
//@{
@@ -69,8 +69,6 @@
/*----------------------------------------------------------------------------
-- Local Data
----------------------------------------------------------------------------*/
-//FIXME: mr-russ Really bad hack to improve UnitsInDistance calculation
-local Unit* localunit;
/*----------------------------------------------------------------------------
-- Functions
@@ -456,33 +454,6 @@
return NoUnitP;
}
-/**
-** Compare distance from me to a unit
-**
-** @param v1 item to compare
-** @param v2 item to compare with
-**
-** @return which unit should be sorted first
-**
-**/
-local int InDistanceCompare(const void* v1, const void* v2)
-{
- int unit1dist;
- int unit2dist;
-
- unit1dist = MapDistanceBetweenUnits(*(Unit**)v1, localunit);
- unit2dist = MapDistanceBetweenUnits(*(Unit**)v2, localunit);
-
- if (unit1dist < unit2dist) {
- return -1;
- } else if (unit1dist > unit2dist) {
- return 1;
- } else {
- return (*(Unit**)v1)->Slot - (*(Unit**)v2)->Slot;
- }
-
-}
-
/*----------------------------------------------------------------------------
-- Finding units for attack
----------------------------------------------------------------------------*/
@@ -562,9 +533,6 @@
}
enemy_count = 0;
- // FIXME: (mr-russ) Breaks all good coding rules...
- localunit = u;
- qsort((void*)table, n, sizeof(Unit*), InDistanceCompare);
// FILL good/bad...
for (i = 0; i < n; ++i) {
dest = table[i];
@@ -657,7 +625,7 @@
}
d = MapDistanceBetweenUnits(u, dest);
- if (d <= range && UnitReachable(u, dest, attackrange)) {
+ if (d <= attackrange || (d <= range && UnitReachable(u, dest,
attackrange))) {
++enemy_count;
} else {
table[i] = 0;
@@ -784,7 +752,6 @@
int attackrange;
int cost;
int best_cost;
- int tried_units;
const Player* player;
Unit* best_unit;
@@ -807,7 +774,6 @@
best_unit = NoUnitP;
best_cost = INT_MAX;
- tried_units = 0;
player = unit->Player;
attackrange = unit->Stats->AttackRange;
@@ -816,9 +782,6 @@
// Find the best unit to attack
//
- // FIXME: (mr-russ) Breaks all good coding rules...
- localunit = unit;
- qsort((void*)table, n, sizeof(Unit*), InDistanceCompare);
for (i = 0; i < n; ++i) {
dest = table[i];
//
@@ -879,15 +842,8 @@
//
// Take this target?
//
- // If we failed 5 closest units, we probably can't get anything
- if (tried_units >= 5 && best_cost == INT_MAX) {
- best_unit = NULL;
- break;
- }
- if (cost < best_cost && d > attackrange &&
- !UnitReachable(unit, dest, attackrange)) {
- ++tried_units;
- } else {
+ if (cost < best_cost && (d < attackrange ||
+ UnitReachable(unit, dest, attackrange))) {
best_unit = dest;
best_cost = cost;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/clone unit.c unit_find.c,
Russell Smith <=