[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus doc/ChangeLog.html src/action/action_...
From: |
Crestez Leonard |
Subject: |
[Stratagus-CVS] stratagus doc/ChangeLog.html src/action/action_... |
Date: |
Mon, 10 Nov 2003 22:06:56 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Crestez Leonard <address@hidden> 03/11/10 22:06:55
Modified files:
doc : ChangeLog.html
src/action : action_build.c action_die.c action_move.c
action_resource.c action_still.c
action_upgradeto.c actions.c command.c
src/clone : unit.c unit_draw.c
src/include : unit.h
src/map : map.c map_fog.c
src/unit : ccl_unit.c
Log message:
New seen mechanism.
Patches:
Index: stratagus/doc/ChangeLog.html
diff -u stratagus/doc/ChangeLog.html:1.572 stratagus/doc/ChangeLog.html:1.573
--- stratagus/doc/ChangeLog.html:1.572 Mon Nov 10 04:24:05 2003
+++ stratagus/doc/ChangeLog.html Mon Nov 10 22:06:50 2003
@@ -2,7 +2,7 @@
<html>
<head>
<!--
----- $Id: ChangeLog.html,v 1.572 2003/11/10 09:24:05 mr-russ Exp $
+---- $Id: ChangeLog.html,v 1.573 2003/11/11 03:06:50 n0body Exp $
---- (c) Copyright 1998-2003 by Lutz Sammer
@@ -36,6 +36,7 @@
<li>Future 2.00 Release<p>
<ul>
<li>++
+ <li>Fixed Bug #6427 and added a brand new seen mechanism (from Crestez
Leonard).
<li>Fixed Bug #6391: Infinite loop in UpdateMinimap() (from Russell Smith).
<li>Major clean-up in checking goals that disappear and unit reference
counting (from Crestez Leonard).
<li>Fixed Bug #5992: Little undesirable effects with invisibility and
flameShield spell (from Crestez Leonard).
Index: stratagus/src/action/action_build.c
diff -u stratagus/src/action/action_build.c:1.101
stratagus/src/action/action_build.c:1.102
--- stratagus/src/action/action_build.c:1.101 Sun Nov 9 17:13:56 2003
+++ stratagus/src/action/action_build.c Mon Nov 10 22:06:51 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_build.c,v 1.101 2003/11/09 22:13:56 n0body Exp $
+// $Id: action_build.c,v 1.102 2003/11/11 03:06:51 n0body Exp $
//@{
@@ -77,7 +77,6 @@
unit->Data.Builded.Frame = cframe;
unit->Frame = cframe->Frame;
CheckUnitToBeDrawn(unit);
- UnitMarkSeen(unit);
}
}
@@ -277,12 +276,11 @@
unit->SubAction = 0;
unit->Wait = 1;
RefsIncrease(build);
- UnitMarkSeen(unit);
// Mark the new building seen.
MapMarkUnitSight(build);
}
UpdateConstructionFrame(build);
- UnitMarkSeen(build);
+ UnitCountSeen(build);
}
/**
Index: stratagus/src/action/action_die.c
diff -u stratagus/src/action/action_die.c:1.52
stratagus/src/action/action_die.c:1.53
--- stratagus/src/action/action_die.c:1.52 Fri Oct 3 16:31:24 2003
+++ stratagus/src/action/action_die.c Mon Nov 10 22:06:52 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_die.c,v 1.52 2003/10/03 20:31:24 jsalmon3 Exp $
+// $Id: action_die.c,v 1.53 2003/11/11 03:06:52 n0body Exp $
//@{
@@ -72,7 +72,6 @@
DebugLevel3("Die complete %d\n" _C_ UnitNumber(unit));
if (!unit->Type->CorpseType) {
- UnitMarkSeen(unit);
ReleaseUnit(unit);
return;
}
@@ -100,7 +99,6 @@
// FIXME: perhaps later or never is better
//ChangeUnitOwner(unit, &Players[PlayerNumNeutral]);
}
- UnitMarkSeen(unit);
}
//@}
Index: stratagus/src/action/action_move.c
diff -u stratagus/src/action/action_move.c:1.71
stratagus/src/action/action_move.c:1.72
--- stratagus/src/action/action_move.c:1.71 Sun Nov 9 17:13:56 2003
+++ stratagus/src/action/action_move.c Mon Nov 10 22:06:52 2003
@@ -21,7 +21,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
-// $Id: action_move.c,v 1.71 2003/11/09 22:13:56 n0body Exp $
+// $Id: action_move.c,v 1.72 2003/11/11 03:06:52 n0body Exp $
//@{
@@ -176,6 +176,11 @@
unit->IY = -yd * TileSizeY;
unit->Frame = 0;
UnitHeadingFromDeltaXY(unit, xd, yd);
+
+ //
+ // Unit has moved, reference count is screwed.
+ //
+ UnitCountSeen(unit);
} else {
xd = Heading2X[unit->Direction / NextDirection];
yd = Heading2Y[unit->Direction / NextDirection];
Index: stratagus/src/action/action_resource.c
diff -u stratagus/src/action/action_resource.c:1.68
stratagus/src/action/action_resource.c:1.69
--- stratagus/src/action/action_resource.c:1.68 Sun Nov 9 19:54:55 2003
+++ stratagus/src/action/action_resource.c Mon Nov 10 22:06:52 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_resource.c,v 1.68 2003/11/10 00:54:55 n0body Exp $
+// $Id: action_resource.c,v 1.69 2003/11/11 03:06:52 n0body Exp $
//@{
@@ -223,7 +223,6 @@
// Activate the resource
goal->Data.Resource.Active++;
- UnitMarkSeen(goal);
//
// Place unit inside the resource
//
@@ -420,7 +419,6 @@
unit->Value += addload;
source->Value -= addload;
- UnitMarkSeen(source);
if (IsOnlySelected(source)) {
MustRedraw |= RedrawInfoPanel;
}
Index: stratagus/src/action/action_still.c
diff -u stratagus/src/action/action_still.c:1.74
stratagus/src/action/action_still.c:1.75
--- stratagus/src/action/action_still.c:1.74 Sun Nov 9 17:13:56 2003
+++ stratagus/src/action/action_still.c Mon Nov 10 22:06:53 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_still.c,v 1.74 2003/11/09 22:13:56 n0body Exp $
+// $Id: action_still.c,v 1.75 2003/11/11 03:06:53 n0body Exp $
//@{
@@ -101,7 +101,6 @@
if (unit->State == 1 && type->GivesResource == OilCost) {
unit->Frame = unit->Data.Resource.Active ? 2 : 0;
}
- UnitMarkSeen(unit);
}
if (!unit->Reset) { // animation can't be aborted here
Index: stratagus/src/action/action_upgradeto.c
diff -u stratagus/src/action/action_upgradeto.c:1.39
stratagus/src/action/action_upgradeto.c:1.40
--- stratagus/src/action/action_upgradeto.c:1.39 Fri Oct 3 18:42:30 2003
+++ stratagus/src/action/action_upgradeto.c Mon Nov 10 22:06:53 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_upgradeto.c,v 1.39 2003/10/03 22:42:30 jsalmon3 Exp $
+// $Id: action_upgradeto.c,v 1.40 2003/11/11 03:06:53 n0body Exp $
//@{
@@ -70,7 +70,6 @@
type = unit->Orders[0].Type;
stats = &type->Stats[player->Player];
- UnitMarkSeen(unit);
// FIXME: Should count down here
unit->Data.UpgradeTo.Ticks += SpeedUpgrade;
if (unit->Data.UpgradeTo.Ticks >= stats->Costs[TimeCost]) {
Index: stratagus/src/action/actions.c
diff -u stratagus/src/action/actions.c:1.106
stratagus/src/action/actions.c:1.107
--- stratagus/src/action/actions.c:1.106 Sun Nov 9 19:54:56 2003
+++ stratagus/src/action/actions.c Mon Nov 10 22:06:53 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: actions.c,v 1.106 2003/11/10 00:54:56 n0body Exp $
+// $Id: actions.c,v 1.107 2003/11/11 03:06:53 n0body Exp $
//@{
@@ -68,6 +68,7 @@
*/
global int GoalGone(const Unit* unit, const Unit* goal)
{
+ int p;
//
// Check for dead/removed goals.
//
@@ -81,6 +82,7 @@
goal->Removed) {
return 1;
}
+ p = unit->Player->Player;
//
// Check if we have an unit for this goal.
//
@@ -89,31 +91,23 @@
if (IsSharedVision(unit->Player, goal) || unit->Player==goal->Player) {
return 0;
} else {
- int x;
- int y;
// Goal is invisible (by spell)
if (goal->Invisible) {
return 1;
}
// Goal is cloaked for this player
- if (!(goal->Visible & (1 << unit->Player->Player))) {
+ if (!(goal->Visible & (1 << p))) {
return 1;
}
//
// Check if under fog of war.
// Don't bother for goals visible under fog.
//
- if (goal->Type->VisibleUnderFog) {
- return 0;
- }
- for (x = goal->X; x < goal->X + goal->Type->TileWidth; x++) {
- for (y = goal->Y; y < goal->Y + goal->Type->TileHeight; y++) {
- if (IsMapFieldVisible(unit->Player, x, y)) {
- return 0;
- }
- }
+ if (!goal->Type->VisibleUnderFog &&
+ !goal->VisCount[p]) {
+ return 1;
}
- return 1;
+ return 0;
}
} else {
return 0;
Index: stratagus/src/action/command.c
diff -u stratagus/src/action/command.c:1.116
stratagus/src/action/command.c:1.117
--- stratagus/src/action/command.c:1.116 Sun Nov 9 17:13:56 2003
+++ stratagus/src/action/command.c Mon Nov 10 22:06:53 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: command.c,v 1.116 2003/11/09 22:13:56 n0body Exp $
+// $Id: command.c,v 1.117 2003/11/11 03:06:53 n0body Exp $
//@{
@@ -1311,7 +1311,7 @@
for (y = 0; y < TheMap.Height; ++y) {
if (IsMapFieldVisible(ThisPlayer, i, y)) {
MapMarkSeenTile(i, y);
- UnitsMarkSeen(i, y);
+ //UnitsMarkSeen(i, y);
}
}
}
@@ -1320,7 +1320,7 @@
// MUST update seen buildings when vision is shared or unshared
for (i = 0; i < NumUnits; ++i) {
unit = Units[i];
- UnitMarkSeen(unit);
+ UnitCountSeen(unit);
}
}
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.331 stratagus/src/clone/unit.c:1.332
--- stratagus/src/clone/unit.c:1.331 Mon Nov 10 04:24:06 2003
+++ stratagus/src/clone/unit.c Mon Nov 10 22:06:53 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.c,v 1.331 2003/11/10 09:24:06 mr-russ Exp $
+// $Id: unit.c,v 1.332 2003/11/11 03:06:53 n0body Exp $
//@{
@@ -546,7 +546,7 @@
MustRedraw |= RedrawMinimap;
CheckUnitToBeDrawn(unit);
- UnitMarkSeen(unit);
+ UnitCountSeen(unit);
}
/**
@@ -1030,90 +1030,134 @@
}
/**
-** FIXME: docu
+** This function fills in the Seen fields of an unit from current fields.
+** To be called when unit goes out of view.
+**
+** @param unit The unit to work on
+*/
+local void FillSeenValues(Unit* unit)
+{
+ // Seen values are undefined for visible units.
+ unit->SeenIY = unit->IY;
+ unit->SeenIX = unit->IX;
+ unit->SeenFrame = unit->Frame;
+ unit->SeenState = (unit->Orders[0].Action == UnitActionBuilded) |
+ ((unit->Orders[0].Action == UnitActionUpgradeTo) << 1);
+ if (unit->Orders[0].Action == UnitActionDie) {
+ unit->SeenState = 3;
+ }
+ unit->SeenType = unit->Type;
+ unit->SeenConstructed = unit->Constructed;
+ unit->SeenDestroyed = unit->Destroyed;
+ unit->SeenCFrame = unit->Data.Builded.Frame;
+}
+
+/**
+** This function marks units on x, y as seen. It uses a reference count.
**
** @param x x location to check if building is on, and mark as seen
** @param y y location to check if building is on, and mark as seen
*/
-global void UnitsMarkSeen(int x, int y)
+global void UnitsMarkSeen(const Player* player, int x, int y)
{
int n;
Unit* units[UnitMax];
Unit* unit;
- if (IsMapFieldVisible(ThisPlayer, x, y)) {
- n = SelectUnitsOnTile(x, y,units);
- DebugLevel3Fn("I can see %d units from here.\n" _C_ n);
- // FIXME: need to handle Dead buldings
- while (n) {
- unit = units[n - 1];
- if (unit->SeenFrame == UnitNotSeen) {
- DebugLevel3Fn("unit %d at %d,%d first seen at %lu.\n" _C_
- unit->Slot _C_ unit->X _C_ unit->Y _C_ GameCycle);
- }
- unit->SeenIY = unit->IY;
- unit->SeenIX = unit->IX;
- unit->SeenFrame = unit->Frame;
- unit->SeenState = (unit->Orders[0].Action == UnitActionBuilded) |
- ((unit->Orders[0].Action == UnitActionUpgradeTo) << 1);
- if (unit->Orders[0].Action == UnitActionDie) {
- unit->SeenState = 3;
- }
- if (unit->SeenState == 2) {
- unit->SeenType = unit->Orders[0].Type;
- } else {
- unit->SeenType = unit->Type;
+ n = SelectUnitsOnTile(x, y,units);
+ DebugLevel3Fn("I can see %d units from here.\n" _C_ n);
+ while (n) {
+ unit = units[n - 1];
+ if (unit->SeenFrame == UnitNotSeen) {
+ DebugLevel3Fn("unit %d at %d,%d first seen at %lu.\n" _C_
+ unit->Slot _C_ unit->X _C_ unit->Y _C_ GameCycle);
+ }
+ unit->VisCount[player->Player]++;
+ --n;
+ }
+}
+
+/**
+** This function unmarks units on x, y as seen. It uses a reference count.
+**
+** @param x x location to check if building is on, and mark as seen
+** @param y y location to check if building is on, and mark as seen
+*/
+global void UnitsUnmarkSeen(const Player* player, int x, int y)
+{
+ int n;
+ Unit* units[UnitMax];
+ Unit* unit;
+
+ n = SelectUnitsOnTile(x, y,units);
+ DebugLevel3Fn("I can see %d units from here.\n" _C_ n);
+ while (n) {
+ unit = units[n - 1];
+ DebugCheck(!unit->VisCount[player->Player]);
+ unit->VisCount[player->Player]--;
+ //
+ // Check if building goes under FOW.
+ //
+ if (!unit->VisCount[player->Player]) {
+ DebugLevel3Fn("unit %d at %d,%d is now under fog time %lu.\n" _C_
+ unit->Slot _C_ unit->X _C_ unit->Y _C_ GameCycle);
+ if (player == ThisPlayer) {
+ FillSeenValues(unit);
}
- unit->SeenConstructed = unit->Constructed;
- unit->SeenDestroyed = unit->Destroyed;
- --n;
}
+ --n;
}
}
+
/**
-** FIXME: docu
+** Makes an unit count it's visibility again.
**
** @param unit pointer to the unit to check if seen
*/
-global void UnitMarkSeen(Unit* unit)
+global void UnitCountSeen(Unit* unit)
{
int x;
int y;
-
- // Update Building Seen
- if (!unit->Type) {
- DebugLevel0Fn("UnitMarkSeen: Type is NULL\n");
- return;
- }
- for (x = 0; x < unit->Type->TileWidth; ++x) {
- for (y = 0; y < unit->Type->TileHeight; ++y) {
- if (IsMapFieldVisible(ThisPlayer, unit->X + x, unit->Y + y)) {
- unit->SeenIY = unit->IY;
- unit->SeenIX = unit->IX;
- if (unit->SeenFrame == UnitNotSeen) {
- DebugLevel3Fn("unit %d at %d,%d first seen at %lu.\n" _C_
- unit->Slot _C_ unit->X _C_ unit->Y _C_ GameCycle);
- }
- unit->SeenFrame = unit->Frame;
- unit->SeenState = (unit->Orders[0].Action == UnitActionBuilded)
|
- ((unit->Orders[0].Action == UnitActionUpgradeTo) << 1);
- if (unit->Orders[0].Action == UnitActionDie) {
- unit->SeenState = 3;
- }
- if (unit->SeenState == 2) {
- unit->SeenType = unit->Orders[0].Type;
- } else {
- unit->SeenType = unit->Type;
+ int p;
+ int oldv;
+ int newv;
+
+ DebugCheck(!unit->Type);
+
+ // FIXME: optimize, only work on certain players?
+ // This is for instance good for updating shared vision...
+ for (p = 0; p < PlayerMax; ++p) {
+ //
+ // First calculate the new visibility count.
+ //
+ oldv = unit->VisCount[p];
+ newv = 0;
+ for (x = 0; x < unit->Type->TileWidth; ++x) {
+ for (y = 0; y < unit->Type->TileHeight; ++y) {
+ if (IsMapFieldVisible(&Players[p], unit->X + x, unit->Y + y)) {
+ newv++;
}
- unit->SeenConstructed = unit->Constructed;
- unit->SeenDestroyed = unit->Destroyed;
- x = unit->Type->TileWidth;
- y = unit->Type->TileHeight;
- // If we found one visible square, END.
- break;
}
}
+#ifdef DEBUG
+ if ((oldv == 0) && (newv)) {
+ DebugLevel3Fn("unit %d(%s) at %d,%d popped into player %d's sight
at cycle %lu.\n" _C_
+ unit->Slot _C_ unit->Type->Name _C_ unit->X _C_ unit->Y _C_
p _C_ GameCycle);
+ }
+#endif
+ //
+ // If the unit goes out of sight we have to fill in seen data.
+ //
+ if ((oldv) && (newv == 0)) {
+ DebugLevel3Fn("unit %d(%s) at %d,%d got out of player %d's sight at
cycle %lu.\n" _C_
+ unit->Slot _C_ unit->Type->Name _C_ unit->X _C_ unit->Y _C_
p _C_ GameCycle);
+ if (p == ThisPlayer->Player) {
+ FillSeenValues(unit);
+ }
+ }
+ // Now set the new visibility count
+ unit->VisCount[p] = newv;
}
}
@@ -2867,16 +2911,16 @@
DeadBuildingCacheInsert(unit); //Insert into corpse list
// FIXME: (mr-russ) Hack to make sure we see our own building
destroyed
MapMarkUnitSight(unit);
- UnitMarkSeen(unit);
+ UnitCountSeen(unit);
MapUnmarkUnitSight(unit);
- UnitMarkSeen(unit);
+ UnitCountSeen(unit);
return;
}
// no corpse available
// FIXME: (mr-russ) Hack to make sure we see our own building destroyed
MapMarkUnitSight(unit);
- UnitMarkSeen(unit);
+ UnitCountSeen(unit);
MapUnmarkUnitSight(unit);
ReleaseUnit(unit);
return;
@@ -3516,14 +3560,13 @@
char* ref;
Unit* uins;
int i;
+ ConstructionFrame* cframe;
+ int frame;
CLprintf(file, "\n(unit %d ", UnitNumber(unit));
// 'type and 'player must be first, needed to create the unit slot
CLprintf(file, "'type '%s ", unit->Type->Ident);
- if (unit->SeenType) {
- CLprintf(file, "'seen-type '%s ", unit->SeenType->Ident);
- }
CLprintf(file, "'player %d\n ", unit->Player->Player);
@@ -3553,17 +3596,10 @@
CLprintf(file, "'stats %d\n ", unit->Player->Player);
#endif
CLprintf(file, "'pixel '(%d %d) ", unit->IX, unit->IY);
- CLprintf(file, "'seen-pixel '(%d %d) ", unit->SeenIX, unit->SeenIY);
CLprintf(file, "'%sframe %d ",
unit->Frame < 0 ? "flipped-" : "",
unit->Frame < 0 ? -unit->Frame : unit->Frame);
- if (unit->SeenFrame != UnitNotSeen) {
- CLprintf(file, "'%sseen %d ",
- unit->SeenFrame < 0 ? "flipped-" : "",
- unit->SeenFrame < 0 ? -unit->SeenFrame : unit->SeenFrame);
- } else {
- CLprintf(file, "'not-seen ");
- }
+
CLprintf(file, "'direction %d\n ", unit->Direction);
CLprintf(file, "'attacked %lu\n ", unit->Attacked);
CLprintf(file, " 'current-sight-range %d", unit->CurrentSightRange);
@@ -3573,9 +3609,6 @@
if (unit->Destroyed) {
CLprintf(file, " 'destroyed");
}
- if (unit->SeenDestroyed) {
- CLprintf(file, " 'seen-destroyed");
- }
if (unit->Removed) {
CLprintf(file, " 'removed");
}
@@ -3603,13 +3636,48 @@
if (unit->Constructed) {
CLprintf(file, " 'constructed");
}
- if (unit->SeenConstructed) {
- CLprintf(file, " 'seen-constructed");
- }
- CLprintf(file, " 'seen-state %d ", unit->SeenState);
if (unit->Active) {
CLprintf(file, " 'active");
}
+
+ //
+ // Now save Seen stuff.
+ //
+ CLprintf(file, "\n 'vis-count #(%d", unit->VisCount[0]);
+ for (i = 1; i < PlayerMax; ++i) {
+ CLprintf(file, " %d", unit->VisCount[i]);
+ }
+ CLprintf(file, ")\n ");
+ if (unit->VisCount[ThisPlayer->Player]==0 && unit->Type->VisibleUnderFog) {
+ CLprintf(file, "'seen-pixel '(%d %d) ", unit->SeenIX, unit->SeenIY);
+ if (unit->SeenType) {
+ CLprintf(file, "'seen-type '%s ", unit->SeenType->Ident);
+ }
+ if (unit->SeenFrame != UnitNotSeen) {
+ CLprintf(file, "'%sseen %d ",
+ unit->SeenFrame < 0 ? "flipped-" : "",
+ unit->SeenFrame < 0 ? -unit->SeenFrame : unit->SeenFrame);
+ } else {
+ CLprintf(file, "'not-seen ");
+ }
+ if (unit->SeenConstructed) {
+ CLprintf(file, " 'seen-constructed");
+ }
+ if (unit->SeenDestroyed) {
+ CLprintf(file, " 'seen-destroyed");
+ }
+ CLprintf(file, " 'seen-state %d ", unit->SeenState);
+ if (unit->Orders->Action == UnitActionBuilded) {
+ cframe = unit->Type->Construction->Frames;
+ frame = 0;
+ while (cframe != unit->SeenCFrame) {
+ cframe = cframe->Next;
+ ++frame;
+ }
+ CLprintf(file," 'seen-construction-frame %d");
+ }
+ }
+
CLprintf(file, " 'mana %d", unit->Mana);
CLprintf(file, " 'hp %d", unit->HP);
CLprintf(file, " 'xp %d", unit->XP);
@@ -3684,9 +3752,6 @@
break;
case UnitActionBuilded:
{
- ConstructionFrame* cframe;
- int frame;
-
cframe = unit->Type->Construction->Frames;
frame = 0;
while (cframe != unit->Data.Builded.Frame) {
@@ -3773,7 +3838,7 @@
int RunStart;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: units $Id: unit.c,v 1.331 2003/11/10 09:24:06
mr-russ Exp $\n\n");
+ CLprintf(file, ";;; MODULE: units $Id: unit.c,v 1.332 2003/11/11 03:06:53
n0body Exp $\n\n");
//
// Local variables
Index: stratagus/src/clone/unit_draw.c
diff -u stratagus/src/clone/unit_draw.c:1.177
stratagus/src/clone/unit_draw.c:1.178
--- stratagus/src/clone/unit_draw.c:1.177 Sat Nov 8 21:42:05 2003
+++ stratagus/src/clone/unit_draw.c Mon Nov 10 22:06:54 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_draw.c,v 1.177 2003/11/09 02:42:05 n0body Exp $
+// $Id: unit_draw.c,v 1.178 2003/11/11 03:06:54 n0body Exp $
//@{
@@ -583,7 +583,7 @@
global void SaveDecorations(CLFile* file)
{
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.177
2003/11/09 02:42:05 n0body Exp $\n\n");
+ CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.178
2003/11/11 03:06:54 n0body Exp $\n\n");
CLprintf(file, "(mana-sprite \"%s\" %d %d %d %d)\n",
ManaSprite.File, ManaSprite.HotX, ManaSprite.HotY,
@@ -1551,6 +1551,12 @@
const UnitStats* stats;
int r;
+#if 0 // This is for showing vis counts.
+ char buf[10];
+ sprintf(buf, "%d", unit->VisCount[ThisPlayer->Player]);
+ VideoDrawTextClip(x + 10, y + 10, 1, buf);
+#endif
+
stats = unit->Stats;
//
@@ -1725,11 +1731,9 @@
** @param x X position.
** @param y Y position.
*/
-local void DrawConstruction(const Unit* unit, int frame, int x, int y)
+local void DrawConstruction(const Unit* unit, ConstructionFrame* cframe,
+ Graphic* sprite, int frame, int x, int y)
{
- ConstructionFrame* cframe;
-
- cframe = unit->Data.Builded.Frame;
if (cframe->File == ConstructionFileConstruction) {
const Construction* construction;
@@ -1741,26 +1745,14 @@
} else {
x -= unit->Type->TileWidth * TileSizeX / 2;
y -= unit->Type->TileHeight * TileSizeY / 2;
- GraphicUnitPixels(unit, unit->Type->Sprite);
- DrawUnitType(unit->Type, unit->Type->Sprite, frame, x, y);
+ GraphicUnitPixels(unit, sprite);
+ DrawUnitType(unit->Type, sprite, frame, x, y);
#ifdef USE_OPENGL
DrawUnitPlayerColor(unit->Type, unit->Player->Player, frame, x, y);
#endif
}
}
-/*
-** Units on map:
-**
-** 1) Must draw underground/underwater units. (FUTURE extension)
-** 2) Must draw buildings and corpse.
-** 3) Must draw land/sea units.
-** 4) Must draw decoration units. (FUTURE extension)
-** 5) Must draw low air units.
-** 6) Must draw middle air units. (FUTURE extension)
-** 7) Must draw hight air units. (FUTURE extension)
-*/
-
/**
** Draw unit on map.
**
@@ -1773,6 +1765,7 @@
int frame;
int state;
int constructed;
+ ConstructionFrame* cframe;
Graphic* sprite;
ResourceInfo* resinfo;
const UnitType* type;
@@ -1782,23 +1775,36 @@
return;
}
- if (ReplayRevealMap || !unit->Type->VisibleUnderFog) {
+ //
+ // This should be obviousely false.
+ //
+ DebugCheck(unit->VisCount[ThisPlayer->Player] >
+ unit->Type->TileWidth * unit->Type->TileHeight);
+ //
+ // If we are in replay reveal map or the unit is visible(not under fog).
+ //
+ if (ReplayRevealMap || unit->VisCount[ThisPlayer->Player]) {
type = unit->Type;
frame = unit->Frame;
- y = unit->IY;
x = unit->IX;
+ y = unit->IY;
state = (unit->Orders[0].Action == UnitActionBuilded) |
((unit->Orders[0].Action == UnitActionUpgradeTo) << 1);
constructed = unit->Constructed;
+ // This is trash unless the unit is building... but we only
+ // use it if it's building.
+ cframe = unit->Data.Builded.Frame;
} else {
- y = unit->SeenIY;
- x = unit->SeenIX;
- frame = unit->SeenFrame;
type = unit->SeenType;
- constructed = unit->SeenConstructed;
+ frame = unit->SeenFrame;
+ x = unit->SeenIX;
+ y = unit->SeenIY;
state = unit->SeenState;
+ constructed = unit->SeenConstructed;
+ cframe = unit->SeenCFrame;
}
+ DebugCheck(!type);
if (frame == UnitNotSeen) {
DebugLevel0Fn("FIXME: Something is wrong, unit %d not seen but drawn
time %lu?.\n" _C_
unit->Slot _C_ GameCycle);
@@ -1824,12 +1830,12 @@
//
DrawUnitSelection(unit);
- GraphicUnitPixels(unit, type->Sprite);
+ sprite = type->Sprite;
+ GraphicUnitPixels(unit, sprite);
//
// Adjust sprite for Harvesters.
//
- sprite = type->Sprite;
if (type->Harvester && unit->CurrentResource) {
resinfo = type->ResInfo[unit->CurrentResource];
if (unit->Value) {
@@ -1849,7 +1855,7 @@
//
if (state == 1) {
if (constructed) {
- DrawConstruction(unit, frame,
+ DrawConstruction(unit, cframe, sprite, frame,
x + (type->TileWidth * TileSizeX) / 2,
y + (type->TileHeight * TileSizeY) / 2);
}
@@ -1859,6 +1865,8 @@
} else if (state == 2) {
// FIXME: this frame is hardcoded!!!
GraphicUnitPixels(unit, type->Sprite);
+/* DebugLevel0Fn("building in upgrade, frame %d t %s g %X\n" _C_
+ (frame < 0 ? -1 :1) _C_ type->Name _C_ (unsigned
int)type->Sprite);*/
DrawUnitType(type, sprite, frame < 0 ? -1 : 1, x, y);
#ifdef USE_OPENGL
DrawUnitPlayerColor(type, unit->Player->Player,
Index: stratagus/src/include/unit.h
diff -u stratagus/src/include/unit.h:1.233 stratagus/src/include/unit.h:1.234
--- stratagus/src/include/unit.h:1.233 Sun Nov 9 17:13:58 2003
+++ stratagus/src/include/unit.h Mon Nov 10 22:06:54 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.h,v 1.233 2003/11/09 22:13:58 n0body Exp $
+// $Id: unit.h,v 1.234 2003/11/11 03:06:54 n0body Exp $
#ifndef __UNIT_H__
#define __UNIT_H__
@@ -206,6 +206,12 @@
** Unit::Visible&(1<<player-nr) is non-zero, the unit could be
** seen on the map.
**
+** Unit::VisCount[PlayerMax]
+**
+** Used to keep track of visible units on the map, it counts the
+** Number of seen tiles for each player. This is only modified
+** in UnitsMarkSeen and UnitsUnmarkSeen, from fow.
+**
** Unit::Destroyed
**
** FIXME: @todo
@@ -229,6 +235,9 @@
** Last seen state of construction. Used to draw correct building
** frame. See Unit::Constructed for more information.
**
+** Unit::SeenCFrame
+** Seen construction frame. This gets copied from
Data.Builded.Frame
+**
** Unit::SeenState
** The Seen State of the building.
** 01 The building in being built when last seen.
@@ -503,7 +512,6 @@
int Y; /// Map position Y
UnitType* Type; /// Pointer to unit-type (peon,...)
- UnitType* SeenType; /// Pointer to last seen unit-type
Player* Player; /// Owner of this unit
UnitStats* Stats; /// Current unit stats
int CurrentSightRange; /// Unit's Current Sight Range
@@ -513,9 +521,15 @@
signed char IX; /// X image displacement to map
position
signed char IY; /// Y image displacement to map
position
int Frame; /// Image frame: <0 is mirrored
+
int SeenFrame; /// last seen frame/stage of
buildings
- signed char SeenIX; /// Seen X image displacement
to map position
- signed char SeenIY; /// seen Y image displacement
to map position
+ UnitType* SeenType; /// Pointer to last seen unit-type
+ signed char SeenIX; /// Unit seen X image
displacement to map position
+ signed char SeenIY; /// Unit seen Y image
displacement to map position
+ unsigned SeenConstructed : 1; /// Unit seen construction
+ unsigned SeenState : 3; /// Unit seen build/upgrade state
+ unsigned SeenDestroyed : 1; /// Unit seen destroyed or not
+ ConstructionFrame* SeenCFrame; /// Unit seen construction frame
unsigned Direction : 8; /// angle (0-255) unit looking
@@ -526,11 +540,9 @@
unsigned Removed : 1; /// unit is removed (not on map)
unsigned Selected : 1; /// unit is selected
+ unsigned char VisCount[PlayerMax]; /// Unit visibility counts.
unsigned Visible : 16; /// Unit is visible (submarine)
unsigned Constructed : 1; /// Unit is in construction
- unsigned SeenConstructed : 1; /// Unit seen construction
- unsigned SeenState : 3; /// Unit seen build/upgrade state
- unsigned SeenDestroyed : 1; /// Unit seen destroyed or not
unsigned Active : 1; /// Unit is active for AI
Player* RescuedFrom; /// The original owner of a rescued
unit.
/// NULL if the unit was not rescued.
@@ -764,10 +776,12 @@
/// Returns true, if building is known on the map
extern int BuildingVisibleOnMap(const Unit* unit);
- /// Updates seen data
-extern void UnitsMarkSeen(int x, int y);
- /// Checks and updates if a Unit's seen information
-extern void UnitMarkSeen(Unit* unit);
+ /// Marks unit seen. (increases visibility count)
+extern void UnitsMarkSeen(const Player* player, int x, int y);
+ /// Unmarks unit seen. (decreases visibility count)
+extern void UnitsUnmarkSeen(const Player* player, int x, int y);
+ /// Calculated an unit's seen information itself
+extern void UnitCountSeen(Unit* unit);
/// Returns true, if unit is known on the map
extern int UnitKnownOnMap(const Unit* unit);
Index: stratagus/src/map/map.c
diff -u stratagus/src/map/map.c:1.61 stratagus/src/map/map.c:1.62
--- stratagus/src/map/map.c:1.61 Sun Nov 9 17:13:58 2003
+++ stratagus/src/map/map.c Mon Nov 10 22:06:54 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: map.c,v 1.61 2003/11/09 22:13:58 n0body Exp $
+// $Id: map.c,v 1.62 2003/11/11 03:06:54 n0body Exp $
//@{
@@ -135,6 +135,7 @@
int ix;
int iy;
+ DebugLevel1Fn("\n");
for (ix = 0; ix < TheMap.Width; ++ix) {
for (iy = 0; iy < TheMap.Height; ++iy) {
int i;
@@ -144,7 +145,7 @@
}
}
MapMarkSeenTile(ix, iy);
- UnitsMarkSeen(ix, iy);
+ //UnitsMarkSeen(ix, iy);
}
}
}
Index: stratagus/src/map/map_fog.c
diff -u stratagus/src/map/map_fog.c:1.111 stratagus/src/map/map_fog.c:1.112
--- stratagus/src/map/map_fog.c:1.111 Mon Oct 20 18:24:55 2003
+++ stratagus/src/map/map_fog.c Mon Nov 10 22:06:54 2003
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: map_fog.c,v 1.111 2003/10/20 22:24:55 jsalmon3 Exp $
+// $Id: map_fog.c,v 1.112 2003/11/11 03:06:54 n0body Exp $
//@{
@@ -249,6 +249,7 @@
case 1: // Unseen
// FIXME: mark for screen update
v = 2;
+ UnitsMarkSeen(player, x, y);
if (player->Type == PlayerPerson) {
corpses = &DestroyedBuildings;
while (*corpses) {
@@ -259,7 +260,7 @@
if (x >= unit->X && y >= unit->Y &&
x < unit->X+w && y < unit->Y+h) {
unit->Visible &= ~(1 << player->Player);
- UnitMarkSeen(unit);
+// UnitMarkSeen(unit);
}
}
remove = unit;
@@ -273,7 +274,6 @@
TheMap.Fields[x + y * TheMap.Width].Visible[player->Player] = v;
if (IsTileVisible(ThisPlayer, x, y) > 1) {
MapMarkSeenTile(x, y);
- UnitsMarkSeen(x, y);
}
return;
@@ -313,10 +313,11 @@
DebugCheck(1);
break;
case 2:
+ UnitsUnmarkSeen(player, x, y);
// Check visible Tile, then deduct...
if (IsTileVisible(ThisPlayer, x, y) > 1) {
MapMarkSeenTile(x, y);
- UnitsMarkSeen(x, y);
+ //UnitsMarkSeen(x, y);
}
default: // seen -> seen
v--;
@@ -468,7 +469,7 @@
for (x = 0; x < TheMap.Width; ++x) {
if (IsMapFieldExplored(ThisPlayer, x, y)) {
MapMarkSeenTile(x, y);
- UnitsMarkSeen(x, y);
+ //UnitsMarkSeen(x, y);
}
}
}
Index: stratagus/src/unit/ccl_unit.c
diff -u stratagus/src/unit/ccl_unit.c:1.72 stratagus/src/unit/ccl_unit.c:1.73
--- stratagus/src/unit/ccl_unit.c:1.72 Sat Nov 1 06:33:10 2003
+++ stratagus/src/unit/ccl_unit.c Mon Nov 10 22:06:54 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_unit.c,v 1.72 2003/11/01 11:33:10 pludov Exp $
+// $Id: ccl_unit.c,v 1.73 2003/11/11 03:06:54 n0body Exp $
//@{
@@ -534,10 +534,6 @@
type=UnitTypeByIdent(str = gh_scm2newstr(gh_car(list),NULL));
free(str);
list = gh_cdr(list);
- } else if (gh_eq_p(value, gh_symbol2scm("seen-type"))) {
- seentype=UnitTypeByIdent(str = gh_scm2newstr(gh_car(list),NULL));
- free(str);
- list = gh_cdr(list);
} else if (gh_eq_p(value, gh_symbol2scm("name"))) {
unit->Name = gh_scm2newstr(gh_car(list),NULL);
list = gh_cdr(list);
@@ -589,17 +585,15 @@
list = gh_cdr(list);
unit->IX = gh_scm2int(gh_car(value));
unit->IY = gh_scm2int(gh_cadr(value));
- } else if (gh_eq_p(value, gh_symbol2scm("seen-pixel"))) {
- value = gh_car(list);
- list = gh_cdr(list);
- unit->SeenIX = gh_scm2int(gh_car(value));
- unit->SeenIY = gh_scm2int(gh_cadr(value));
} else if (gh_eq_p(value, gh_symbol2scm("frame"))) {
unit->Frame = gh_scm2int(gh_car(list));
list = gh_cdr(list);
} else if (gh_eq_p(value, gh_symbol2scm("flipped-frame"))) {
unit->Frame = -gh_scm2int(gh_car(list));
list = gh_cdr(list);
+ //
+ // Here is the seen stuff.
+ //
} else if (gh_eq_p(value, gh_symbol2scm("seen"))) {
unit->SeenFrame = gh_scm2int(gh_car(list));
list = gh_cdr(list);
@@ -608,6 +602,39 @@
list = gh_cdr(list);
} else if (gh_eq_p(value, gh_symbol2scm("not-seen"))) {
unit->SeenFrame = UnitNotSeen;
+ } else if (gh_eq_p(value, gh_symbol2scm("seen-type"))) {
+ unit->SeenType = seentype = UnitTypeByIdent(str =
gh_scm2newstr(gh_car(list),NULL));
+ free(str);
+ list = gh_cdr(list);
+ } else if (gh_eq_p(value, gh_symbol2scm("seen-pixel"))) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ unit->SeenIX = gh_scm2int(gh_car(value));
+ unit->SeenIY = gh_scm2int(gh_cadr(value));
+ } else if (gh_eq_p(value, gh_symbol2scm("seen-destroyed"))) {
+ unit->SeenDestroyed = 1;
+ } else if (gh_eq_p(value, gh_symbol2scm("seen-constructed"))) {
+ unit->SeenConstructed = 1;
+ } else if (gh_eq_p(value, gh_symbol2scm("seen-state"))) {
+ unit->SeenState = gh_scm2int(gh_car(list));
+ list = gh_cdr(list);
+ } else if (gh_eq_p(value, gh_symbol2scm("seen-construction-frame"))) {
+ int frame;
+ frame = gh_scm2int(gh_car(list));
+ unit->SeenCFrame = unit->Type->Construction->Frames;
+ while (frame--) {
+ unit->SeenCFrame = unit->SeenCFrame->Next;
+ }
+ list = gh_cdr(list);
+ } else if (gh_eq_p(value, gh_symbol2scm("vis-count"))) {
+ sublist = gh_car(list);
+ for (i = 0; i < PlayerMax; ++i) {
+ value = gh_vector_ref(sublist, gh_int2scm(i));
+ if (!gh_null_p(value)) {
+ unit->VisCount[i] = gh_scm2int(value);
+ }
+ }
+ list = gh_cdr(list);
} else if (gh_eq_p(value, gh_symbol2scm("direction"))) {
unit->Direction = gh_scm2int(gh_car(list));
list = gh_cdr(list);
@@ -619,8 +646,6 @@
unit->Burning = 1;
} else if (gh_eq_p(value, gh_symbol2scm("destroyed"))) {
unit->Destroyed = 1;
- } else if (gh_eq_p(value, gh_symbol2scm("seen-destroyed"))) {
- unit->SeenDestroyed = 1;
} else if (gh_eq_p(value, gh_symbol2scm("removed"))) {
unit->Removed = 1;
} else if (gh_eq_p(value, gh_symbol2scm("selected"))) {
@@ -641,11 +666,6 @@
free(str);
} else if (gh_eq_p(value, gh_symbol2scm("constructed"))) {
unit->Constructed = 1;
- } else if (gh_eq_p(value, gh_symbol2scm("seen-constructed"))) {
- unit->SeenConstructed = 1;
- } else if (gh_eq_p(value, gh_symbol2scm("seen-state"))) {
- unit->SeenState = gh_scm2int(gh_car(list));
- list = gh_cdr(list);
} else if (gh_eq_p(value, gh_symbol2scm("active"))) {
unit->Active = 1;
} else if (gh_eq_p(value, gh_symbol2scm("resource-active"))) {