FindGoldMine gets also source unit pointer and checks reachable.
FindUnitsByType gets now unit type pointer. Some const added. More NEW_UNIT code.
This commit is contained in:
parent
9b1c073b76
commit
62b5318b8a
13 changed files with 329 additions and 88 deletions
|
@ -308,7 +308,7 @@ global void HandleActionMineGold(Unit* unit)
|
|||
if( !unit->Value ) {
|
||||
// FIXME: return to last position!
|
||||
// FIXME: Ari says, don't automatic search a new mine.
|
||||
if( !(destu=FindGoldMine(unit->X,unit->Y)) ) {
|
||||
if( !(destu=FindGoldMine(unit,unit->X,unit->Y)) ) {
|
||||
DropOutOnSide(unit,HeadingW
|
||||
,UnitTypes[UnitGreatHall].TileWidth
|
||||
,UnitTypes[UnitGreatHall].TileHeight);
|
||||
|
|
|
@ -224,20 +224,27 @@ local void HandleUnitAction(Unit* unit)
|
|||
|
||||
/**
|
||||
** Update the actions of all units each frame.
|
||||
**
|
||||
** IDEA: to improve the preformance use slots for waiting.
|
||||
*/
|
||||
global void UnitActions(void)
|
||||
{
|
||||
#ifdef NEW_UNIT
|
||||
UnitConflicts(); // start attacking
|
||||
Unit** table;
|
||||
|
||||
DebugLevel0("FIXME:\n");
|
||||
//
|
||||
// Do all actions
|
||||
//
|
||||
for( table=Units; table<Units+NumUnits; table++ ) {
|
||||
if( --(*table)->Wait ) { // Wait until counter reached
|
||||
continue;
|
||||
}
|
||||
HandleUnitAction(*table);
|
||||
}
|
||||
#else
|
||||
Unit* unit;
|
||||
int i;
|
||||
|
||||
UnitConflicts(); // start attacking
|
||||
|
||||
//
|
||||
// Do all actions
|
||||
//
|
||||
|
|
|
@ -483,7 +483,7 @@ global int AiNearHall(Unit* hall,Unit* worker,UnitType* type,int* dx,int *dy)
|
|||
return 99998;
|
||||
}
|
||||
|
||||
num_goldmine=FindUnitsByType(UnitGoldMine,goldmines);
|
||||
num_goldmine=FindUnitsByType(UnitTypeGoldMine,goldmines);
|
||||
DebugLevel3("\tGoldmines %d\n",num_goldmine);
|
||||
wx=worker->X; wy=worker->Y;
|
||||
x=hall->X; y=hall->Y;
|
||||
|
@ -534,7 +534,7 @@ global int AiNearHall(Unit* hall,Unit* worker,UnitType* type,int* dx,int *dy)
|
|||
// Check if too near to goldmine
|
||||
for(g=0; g<num_goldmine; ++g)
|
||||
{
|
||||
if(MapDistanceToType(x,y,&UnitTypes[UnitGoldMine]
|
||||
if(MapDistanceToType(x,y,UnitTypeGoldMine
|
||||
,goldmines[g]->X,goldmines[g]->Y)<4) {break;}
|
||||
}
|
||||
if(g!=num_goldmine) {continue;} //too near goldmine
|
||||
|
@ -578,7 +578,7 @@ local int AiBuildHall(int type)
|
|||
if(!num_worker) {return -1;} // QUESTION: only not working ??
|
||||
|
||||
// Find all goldmines.
|
||||
num_goldmine=FindUnitsByType(UnitGoldMine,goldmines);
|
||||
num_goldmine=FindUnitsByType(UnitTypeGoldMine,goldmines);
|
||||
DebugLevel3("\tGoldmines %d\n",num_goldmine);
|
||||
if(!num_goldmine ) {return -1;}
|
||||
|
||||
|
@ -736,11 +736,12 @@ local void AiMineGold(Unit* unit)
|
|||
{
|
||||
Unit* dest;
|
||||
DebugLevel3(__FUNCTION__": %d\n",UnitNumber(unit));
|
||||
dest=FindGoldMine(unit->X,unit->Y);
|
||||
dest=FindGoldMine(unit,unit->X,unit->Y);
|
||||
if(!dest)
|
||||
{
|
||||
DebugLevel0(__FUNCTION__": no goldmine\n");
|
||||
AiPlayer->NoGold=1;
|
||||
// FIXME: now not really, no goldmine.
|
||||
DebugLevel0(__FUNCTION__": goldmine not reachable\n");
|
||||
//AiPlayer->NoGold=1;
|
||||
return;
|
||||
}
|
||||
CommandMineGold(unit,dest,1);
|
||||
|
|
|
@ -293,9 +293,9 @@ extern char* strdcat3(const char* l, const char *m, const char* r);
|
|||
#define BitsOf(n) (sizeof(n)*8)
|
||||
|
||||
/// How long stay in a gold-mine
|
||||
#define MINE_FOR_GOLD (UnitTypes[UnitGoldMine]._Costs[TimeCost]/SpeedMine)
|
||||
#define MINE_FOR_GOLD (UnitTypeGoldMine->_Costs[TimeCost]/SpeedMine)
|
||||
/// How long stay in a gold-deposit
|
||||
#define WAIT_FOR_GOLD (UnitTypes[UnitGoldMine]._Costs[TimeCost]/SpeedGold)
|
||||
#define WAIT_FOR_GOLD (UnitTypeGoldMine->_Costs[TimeCost]/SpeedGold)
|
||||
/// How much I must chop for 1 wood
|
||||
#define CHOP_FOR_WOOD (52/SpeedChop)
|
||||
/// How long stay in a wood-deposit
|
||||
|
|
|
@ -63,9 +63,9 @@ extern unsigned char* CreateMatrix(void);
|
|||
///
|
||||
extern int NewPath(Unit* unit,int* xdp,int* ydp);
|
||||
///
|
||||
extern int PlaceReachable(Unit* unit,int x,int y);
|
||||
extern int PlaceReachable(const Unit* unit,int x,int y);
|
||||
///
|
||||
extern int UnitReachable(Unit* unit,Unit* dest);
|
||||
extern int UnitReachable(const Unit* unit,const Unit* dest);
|
||||
|
||||
//
|
||||
// in astar.c
|
||||
|
|
|
@ -165,11 +165,10 @@ struct _unit_ {
|
|||
#ifdef NEW_UNIT
|
||||
short Refs; /// Reference counter
|
||||
UnitRef Slot; /// Assignd slot number
|
||||
UnitRef UnitSlot; /// slot number in Units
|
||||
UnitRef PlayerSlot; /// slot number in Player->Units
|
||||
Unit** UnitSlot; /// slot pointer of Units
|
||||
Unit** PlayerSlot; /// slot pointer of Player->Units
|
||||
Unit* Next; /// generic link pointer
|
||||
#else
|
||||
// FIXME: this will be removed
|
||||
unsigned Id; /// unique unit id
|
||||
#endif
|
||||
|
||||
|
@ -368,7 +367,8 @@ extern int CanBuildHere(UnitType* type,unsigned x,unsigned y);
|
|||
extern int CanBuildOn(int x,int y,int mask);
|
||||
extern int CanBuildUnitType(Unit* unit,UnitType* type,int x,int y);
|
||||
|
||||
extern Unit* FindGoldMine(int x,int y);
|
||||
/// Find nearest gold mine
|
||||
extern Unit* FindGoldMine(const Unit*,int x,int y);
|
||||
extern Unit* GoldDepositOnMap(int tx,int ty);
|
||||
extern Unit* FindGoldDeposit(const Player* player,int x,int y);
|
||||
|
||||
|
@ -395,8 +395,6 @@ extern int ViewPointDistanceToUnit(Unit* dest);
|
|||
extern int IsEnemy(const Player* player,const Unit* dest);
|
||||
extern int CanTarget(const UnitType* type,const UnitType* dest);
|
||||
|
||||
extern void UnitConflicts(void);
|
||||
|
||||
extern void SaveUnit(const Unit* unit,FILE* file); /// save unit-structure
|
||||
extern void SaveUnits(FILE* file); /// save all units
|
||||
|
||||
|
@ -424,7 +422,8 @@ extern void DrawUnits(void);
|
|||
|
||||
// in unit_find.c
|
||||
extern int SelectUnits(int x1,int y1,int x2,int y2,Unit** table);
|
||||
extern int FindUnitsByType(int type,Unit** table);
|
||||
/// Find all units of this type
|
||||
extern int FindUnitsByType(const UnitType* type,Unit** table);
|
||||
extern int FindPlayerUnitsByType(const Player* player,int type,Unit** table);
|
||||
extern Unit* UnitOnMapTile(unsigned tx,unsigned ty);
|
||||
extern Unit* TargetOnMapTile(Unit* unit,unsigned tx,unsigned ty);
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
// FreeCraft - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name unittype.h - The unit types headerfile. */
|
||||
/*
|
||||
** (c) Copyright 1998-2000 by Lutz Sammer
|
||||
**
|
||||
** $Id$
|
||||
*/
|
||||
//
|
||||
// (c) Copyright 1998-2000 by Lutz Sammer
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
|
||||
#ifndef __UNITTYPE_H__
|
||||
#define __UNITTYPE_H__
|
||||
|
@ -72,15 +72,6 @@ typedef struct _missile_config_ {
|
|||
void* Missile; /// identifier to use to run time
|
||||
} MissileConfig;
|
||||
|
||||
#if 0
|
||||
#define CorpseNone 0 /// Unit has no corpse
|
||||
#define CorpseHuman 1 /// Unit has a human corpse
|
||||
#define CorpseOrc 2 /// Unit has a orc corpse
|
||||
#define CorpseShip 3 /// Unit has a ship corpse
|
||||
#define CorpseLandSite 4 /// Unit has a land corpse
|
||||
#define CorpseWaterSite 5 /// Unit has a water corpse
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Typedef of base structure of unit-type
|
||||
*/
|
||||
|
@ -109,7 +100,7 @@ struct _unit_type_ {
|
|||
MissileConfig Missile; /// missile weapon
|
||||
|
||||
char* CorpseName; /// corpse type name
|
||||
UnitType* CorpseType; /// corpse unit-type
|
||||
UnitType* CorpseType; /// corpse unit-type
|
||||
int CorpseScript; /// corpse script start
|
||||
|
||||
int _Speed; /// movement speed
|
||||
|
@ -305,7 +296,7 @@ struct _unit_type_ {
|
|||
#define UnitStronghold 0x59
|
||||
#define UnitCastle 0x5A
|
||||
#define UnitFortress 0x5B
|
||||
#define UnitGoldMine 0x5C
|
||||
//#define UnitGoldMine 0x5C
|
||||
#define UnitOilPatch 0x5D
|
||||
#define UnitStartLocationHuman 0x5E
|
||||
#define UnitStartLocationOrc 0x5F
|
||||
|
@ -348,7 +339,9 @@ struct _unit_type_ {
|
|||
|
||||
extern char UnitTypeType[]; /// unit type type
|
||||
// FIXME: this limit must be removed!
|
||||
extern UnitType UnitTypes[UnitTypeInternalMax]; /// all unit types
|
||||
extern UnitType UnitTypes[UnitTypeInternalMax]; /// all unit types
|
||||
|
||||
extern UnitType*UnitTypeGoldMine; /// Gold-mine unit type pointer.
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
|
|
|
@ -217,7 +217,14 @@ global void DrawMinimap(int vx,int vy)
|
|||
int flags;
|
||||
int x;
|
||||
int y;
|
||||
#ifndef NEW_UNIT
|
||||
#ifdef NEW_UNIT
|
||||
UnitType* type;
|
||||
Unit** table;
|
||||
Unit* unit;
|
||||
int w;
|
||||
int h;
|
||||
int h0;
|
||||
#else
|
||||
UnitType* type;
|
||||
Unit* unit;
|
||||
int i;
|
||||
|
@ -253,7 +260,69 @@ global void DrawMinimap(int vx,int vy)
|
|||
}
|
||||
|
||||
#ifdef NEW_UNIT
|
||||
DebugLevel0("FIXME:");
|
||||
//
|
||||
// Draw units on map
|
||||
// FIXME: I should rewrite this complet
|
||||
// FIXME: make a bitmap of the units, and update it with the moves
|
||||
// FIXME: and other changes
|
||||
//
|
||||
for( table=Units; table<Units+NumUnits; table++ ) {
|
||||
SysColors color;
|
||||
|
||||
unit=*table;
|
||||
|
||||
flags=TheMap.Fields[unit->X+unit->Y*TheMap.Width].Flags;
|
||||
// Draw only units on explored fields
|
||||
if( !(flags&MapFieldExplored) ) {
|
||||
continue;
|
||||
}
|
||||
// Draw only units on visible fields
|
||||
if( !TheMap.NoFogOfWar && !(flags&MapFieldVisible) ) {
|
||||
continue;
|
||||
}
|
||||
// FIXME: buildings under fog of war.
|
||||
// FIXME: submarine not visible
|
||||
|
||||
type=unit->Type;
|
||||
if( unit->Player->Player==PlayerNumNeutral ) {
|
||||
if( type->Critter ) {
|
||||
color=ColorNPC;
|
||||
} else if( type->OilPatch ) {
|
||||
color=ColorBlack;
|
||||
} else {
|
||||
color=ColorYellow;
|
||||
}
|
||||
} else if( unit->Player==ThisPlayer ) {
|
||||
if( unit->Attacked && RedPhase ) {
|
||||
color=ColorRed;
|
||||
// better to clear to fast, than to clear never :?)
|
||||
unit->Attacked=0;
|
||||
} else if( MinimapShowSelected && unit->Selected ) {
|
||||
color=ColorWhite;
|
||||
} else {
|
||||
color=ColorGreen;
|
||||
}
|
||||
} else {
|
||||
color=unit->Player->Color;
|
||||
}
|
||||
|
||||
mx=x+1+MinimapX+Map2MinimapX[unit->X];
|
||||
my=y+1+MinimapY+Map2MinimapY[unit->Y];
|
||||
w=Map2MinimapX[type->TileWidth];
|
||||
if( mx+w>=x+MINIMAP_W ) { // clip right side
|
||||
w=x+MINIMAP_W-mx;
|
||||
}
|
||||
h0=Map2MinimapY[type->TileHeight];
|
||||
if( my+h0>=y+MINIMAP_H ) { // clip bottom side
|
||||
h0=y+MINIMAP_H-my;
|
||||
}
|
||||
while( w-->=0 ) {
|
||||
h=h0;
|
||||
while( h-->=0 ) {
|
||||
VideoDrawPixel(color,mx+w,my+h);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Draw units on map
|
||||
|
|
|
@ -142,7 +142,7 @@ local void MarkPlaceInMatrix(int x,int y,int w,int h,unsigned char* matrix)
|
|||
** rggr
|
||||
** rrrr
|
||||
*/
|
||||
local void MarkGoalInMatrix(Unit* unit,int range,unsigned char* matrix)
|
||||
local void MarkGoalInMatrix(const Unit* unit,int range,unsigned char* matrix)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
@ -226,7 +226,7 @@ local void PathTraceBack(const unsigned char* matrix,int x,int y,int n
|
|||
/*
|
||||
** Mark path to goal.
|
||||
*/
|
||||
local int MarkPathInMatrix(Unit* unit,unsigned char* matrix)
|
||||
local int MarkPathInMatrix(const Unit* unit,unsigned char* matrix)
|
||||
{
|
||||
static int xoffset[]={ 0,-1,+1, 0, -1,+1,-1,+1 };
|
||||
static int yoffset[]={ -1, 0, 0,+1, -1,-1,+1,+1 };
|
||||
|
@ -317,7 +317,7 @@ local int MarkPathInMatrix(Unit* unit,unsigned char* matrix)
|
|||
/*
|
||||
** Can the unit 'src' reach the place x,y.
|
||||
*/
|
||||
global int PlaceReachable(Unit* src,int x,int y)
|
||||
global int PlaceReachable(const Unit* src,int x,int y)
|
||||
{
|
||||
unsigned char* matrix;
|
||||
|
||||
|
@ -340,7 +340,7 @@ global int PlaceReachable(Unit* src,int x,int y)
|
|||
/*
|
||||
** Can the unit 'src' reach the unit 'dst'.
|
||||
*/
|
||||
global int UnitReachable(Unit* src,Unit* dst)
|
||||
global int UnitReachable(const Unit* src,const Unit* dst)
|
||||
{
|
||||
unsigned char* matrix;
|
||||
|
||||
|
|
224
unit/unit.cpp
224
unit/unit.cpp
|
@ -41,6 +41,7 @@
|
|||
#include "interface.h"
|
||||
#include "sound.h"
|
||||
#include "ai.h"
|
||||
#include "pathfinder.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Variables
|
||||
|
@ -116,39 +117,46 @@ global void InitUnitsMemory(void)
|
|||
}
|
||||
|
||||
/**
|
||||
** Free the memory for a unit slot.
|
||||
** Free the memory for an unit slot. Update all units tables.
|
||||
**
|
||||
** @param unit Point to unit.
|
||||
** @param unit Pointer to unit.
|
||||
*/
|
||||
global void FreeUnitMemory(Unit* unit)
|
||||
{
|
||||
#ifdef NEW_UNIT
|
||||
Player* player;
|
||||
Unit** slot;
|
||||
Unit* temp;
|
||||
|
||||
if( unit->Refs>1 ) {
|
||||
DebugLevel0(__FUNCTION__": too much references\n");
|
||||
}
|
||||
|
||||
// Remove the unit from the player's units list.
|
||||
// FIXME: a backpointer is faster
|
||||
// Remove the unit from the player's units table.
|
||||
|
||||
player=unit->Player;
|
||||
if( player ) {
|
||||
// looking for the unit slot...
|
||||
for( slot=player->Units; *slot!=unit; slot++ ) {
|
||||
;
|
||||
}
|
||||
*slot=player->Units[--player->TotalNumUnits];
|
||||
if( (player=unit->Player) ) {
|
||||
DebugCheck( *unit->PlayerSlot!=unit );
|
||||
temp=player->Units[--player->TotalNumUnits];
|
||||
player->Units[player->TotalNumUnits]=NULL;
|
||||
temp->PlayerSlot=unit->PlayerSlot;
|
||||
*unit->PlayerSlot=temp;
|
||||
}
|
||||
|
||||
// Remove the unit from the global units table.
|
||||
|
||||
DebugCheck( *unit->UnitSlot!=unit );
|
||||
temp=Units[--NumUnits];
|
||||
Units[NumUnits]=NULL;
|
||||
temp->UnitSlot=unit->UnitSlot;
|
||||
*unit->UnitSlot=temp;
|
||||
|
||||
// Remove from slot table
|
||||
|
||||
slot=UnitSlots+unit->Slot;
|
||||
DebugCheck( *slot!=unit );
|
||||
|
||||
*slot=(void*)UnitSlotFree;
|
||||
free(unit);
|
||||
|
||||
#else
|
||||
Unit** tmp;
|
||||
unsigned tmp_id;
|
||||
|
@ -185,7 +193,7 @@ global void FreeUnitMemory(Unit* unit)
|
|||
}
|
||||
|
||||
/**
|
||||
** Create new unit.
|
||||
** Create a new unit.
|
||||
**
|
||||
** @param type Pointer to unit-type.
|
||||
** @param player Pointer to owning player.
|
||||
|
@ -210,6 +218,9 @@ global Unit* MakeUnit(UnitType* type,Player* player)
|
|||
DebugLevel3(__FUNCTION__": %s(%Zd)\n",type->Name,player-Players);
|
||||
|
||||
#ifdef NEW_UNIT
|
||||
//
|
||||
// Allocate structure
|
||||
//
|
||||
if( !(slot=UnitSlotFree) ) { // should not happen!
|
||||
DebugLevel0(__FUNCTION__": Maximum of units reached\n");
|
||||
return NoUnitP;
|
||||
|
@ -217,9 +228,25 @@ global Unit* MakeUnit(UnitType* type,Player* player)
|
|||
UnitSlotFree=(void*)*slot;
|
||||
*slot=unit=calloc(1,sizeof(Unit));
|
||||
unit->Refs=1;
|
||||
unit->Slot=slot-UnitSlots;
|
||||
unit->Slot=slot-UnitSlots; // back index
|
||||
|
||||
...
|
||||
//
|
||||
// Build all unit table
|
||||
//
|
||||
unit->UnitSlot=&Units[NumUnits]; // back pointer
|
||||
Units[NumUnits++]=unit;
|
||||
|
||||
//
|
||||
// Build player unit table
|
||||
//
|
||||
if( player ) {
|
||||
unit->PlayerSlot=player->Units+player->TotalNumUnits++;
|
||||
*unit->PlayerSlot=unit;
|
||||
|
||||
player->UnitTypesCount[type->Type]++;
|
||||
}
|
||||
|
||||
DebugLevel3(__FUNCTION__": %p %Zd\n",unit,UnitNumber(unit));
|
||||
#else
|
||||
if( NumFreeUnits ) {
|
||||
unit=FreeUnits[--NumFreeUnits];
|
||||
|
@ -229,12 +256,12 @@ global Unit* MakeUnit(UnitType* type,Player* player)
|
|||
DebugLevel0("Maximum of units reached\n");
|
||||
return NoUnitP;
|
||||
}
|
||||
#endif
|
||||
|
||||
DebugLevel3(__FUNCTION__": %p %Zd\n",unit,UnitNumber(unit));
|
||||
|
||||
player->Units[player->TotalNumUnits++]=unit;
|
||||
player->UnitTypesCount[type->Type]++;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Initialise unit structure (must be zero filled!)
|
||||
|
@ -658,13 +685,37 @@ global int UnitVisible(const Unit* unit)
|
|||
}
|
||||
|
||||
/**
|
||||
** Increment mana of all magic units.
|
||||
** Increment mana of all magic units. Called each second.
|
||||
** Also clears the blink flag.
|
||||
*/
|
||||
global void UnitIncrementMana(void)
|
||||
{
|
||||
#ifdef NEW_UNIT
|
||||
DebugLevel0("FIXME:");
|
||||
Unit** table;
|
||||
Unit* unit;
|
||||
|
||||
for( table=Units; table<Units+NumUnits; table++ ) {
|
||||
unit=*table;
|
||||
// FIXME: This isn't the correct position or the correct function name
|
||||
if( unit->Blink ) { // clear blink flag
|
||||
--unit->Blink;
|
||||
}
|
||||
|
||||
if( unit->Type->CanCastSpell ) {
|
||||
if( unit->Mana!=255 ) {
|
||||
unit->Mana++;
|
||||
/* Done currently by color cycle!
|
||||
// FIXME: if mana is shown on map
|
||||
if( UnitVisible(unit) ) {
|
||||
MustRedraw|=RedrawMap;
|
||||
}
|
||||
*/
|
||||
if( unit->Selected ) {
|
||||
MustRedraw|=RedrawInfoPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
Unit* unit;
|
||||
int i;
|
||||
|
@ -697,8 +748,13 @@ global void UnitIncrementMana(void)
|
|||
*/
|
||||
global void ChangeUnitOwner(Unit* unit,Player* oldplayer,Player* newplayer)
|
||||
{
|
||||
#ifdef NEW_UNIT
|
||||
Unit* temp;
|
||||
int i;
|
||||
#else
|
||||
Unit** tmp;
|
||||
int i;
|
||||
#endif
|
||||
|
||||
// For st*rcr*ft (dark archons),
|
||||
if( unit->Type->Transporter ) {
|
||||
|
@ -709,6 +765,19 @@ global void ChangeUnitOwner(Unit* unit,Player* oldplayer,Player* newplayer)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef NEW_UNIT
|
||||
// Remove from old player table
|
||||
|
||||
temp=oldplayer->Units[--oldplayer->TotalNumUnits];
|
||||
oldplayer->Units[oldplayer->TotalNumUnits]=NULL;
|
||||
temp->PlayerSlot=unit->PlayerSlot;
|
||||
*unit->PlayerSlot=temp;
|
||||
|
||||
// Insert into new player table.
|
||||
|
||||
unit->PlayerSlot=newplayer->Units+newplayer->TotalNumUnits++;
|
||||
*unit->PlayerSlot=unit;
|
||||
#else
|
||||
newplayer->Units[newplayer->TotalNumUnits++]=unit;
|
||||
|
||||
// looking for the unit slot...
|
||||
|
@ -717,6 +786,7 @@ global void ChangeUnitOwner(Unit* unit,Player* oldplayer,Player* newplayer)
|
|||
}
|
||||
*tmp=oldplayer->Units[--oldplayer->TotalNumUnits];
|
||||
oldplayer->Units[oldplayer->TotalNumUnits]=NULL;
|
||||
#endif
|
||||
|
||||
unit->Player=newplayer;
|
||||
}
|
||||
|
@ -1024,7 +1094,21 @@ global void DropOutNearest(Unit* unit,int gx,int gy,int addx,int addy)
|
|||
global void DropOutAll(const Unit* source)
|
||||
{
|
||||
#ifdef NEW_UNIT
|
||||
DebugLevel0("FIXME:");
|
||||
// FIXME: Rewrite this use source->Next;
|
||||
Unit** table;
|
||||
Unit* unit;
|
||||
|
||||
for( table=Units; table<Units+NumUnits; table++ ) {
|
||||
unit=*table;
|
||||
if( !unit->Removed ) { // unusable unit
|
||||
continue;
|
||||
}
|
||||
if( unit->X==source->X
|
||||
&& unit->Y==source->Y ) {
|
||||
DropOutOnSide(unit,HeadingW
|
||||
,source->Type->TileWidth,source->Type->TileHeight);
|
||||
}
|
||||
}
|
||||
#else
|
||||
Unit* unit;
|
||||
int i;
|
||||
|
@ -1063,11 +1147,9 @@ global int CanBuildHere(UnitType* type,unsigned x,unsigned y)
|
|||
Unit* table[MAX_UNITS];
|
||||
int n;
|
||||
int i;
|
||||
#ifndef NEW_UNIT
|
||||
Unit* unit;
|
||||
int dx;
|
||||
int dy;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Can't build outside the map
|
||||
|
@ -1085,9 +1167,32 @@ global int CanBuildHere(UnitType* type,unsigned x,unsigned y)
|
|||
//
|
||||
// FIXME: use unit-cache here.
|
||||
#ifdef NEW_UNIT
|
||||
DebugLevel0("FIXME:");
|
||||
int i;
|
||||
|
||||
for( i=0; i<NumUnits; i++ ) {
|
||||
unit=Units[i];
|
||||
if( unit->Type->GoldMine ) {
|
||||
DebugLevel3("Check goldmine %d,%d\n"
|
||||
,unit->X,unit->Y);
|
||||
if( unit->X<x ) {
|
||||
dx=x-unit->X-unit->Type->TileWidth;
|
||||
} else {
|
||||
dx=unit->X-x-type->TileWidth;
|
||||
}
|
||||
if( unit->Y<y ) {
|
||||
dy=y-unit->Y-unit->Type->TileHeight;
|
||||
} else {
|
||||
dy=unit->Y-y-type->TileHeight;
|
||||
}
|
||||
DebugLevel3("Distance %d,%d\n",dx,dy);
|
||||
if( dx<GOLDMINE_DISTANCE && dy<GOLDMINE_DISTANCE ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
int i;
|
||||
|
||||
for( i=0; i<NumUnits; i++ ) {
|
||||
unit=Units[i];
|
||||
if( unit->Type->GoldMine ) {
|
||||
|
@ -1137,10 +1242,34 @@ next:
|
|||
// Oil deposit can't be build too near to oil-patch.
|
||||
//
|
||||
#ifdef NEW_UNIT
|
||||
DebugLevel0("FIXME:");
|
||||
// FIXME: use unit-cache here.
|
||||
int i;
|
||||
|
||||
for( i=0; i<NumUnits; i++ ) {
|
||||
unit=Units[i];
|
||||
if( unit->Type->OilPatch ) {
|
||||
DebugLevel3("Check oilpatch %d,%d\n"
|
||||
,unit->X,unit->Y);
|
||||
if( unit->X<x ) {
|
||||
dx=x-unit->X-unit->Type->TileWidth;
|
||||
} else {
|
||||
dx=unit->X-x-type->TileWidth;
|
||||
}
|
||||
if( unit->Y<y ) {
|
||||
dy=y-unit->Y-unit->Type->TileHeight;
|
||||
} else {
|
||||
dy=unit->Y-y-type->TileHeight;
|
||||
}
|
||||
DebugLevel3("Distance %d,%d\n",dx,dy);
|
||||
if( dx<OILPATCH_DISTANCE && dy<OILPATCH_DISTANCE ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// FIXME: use unit-cache here.
|
||||
int i;
|
||||
|
||||
for( i=0; i<NumUnits; i++ ) {
|
||||
unit=Units[i];
|
||||
if( unit->Type->OilPatch ) {
|
||||
|
@ -1272,14 +1401,45 @@ global int CanBuildUnitType(Unit* unit,UnitType* type,int x,int y)
|
|||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Find gold mine.
|
||||
** Find the nearest gold mine for unit from x,y.
|
||||
**
|
||||
** @param unit Pointer for source unit.
|
||||
** @param x X tile position to start.
|
||||
** @param y Y tile position to start.
|
||||
**
|
||||
** @returns Pointer to the nearest gold mine.
|
||||
*/
|
||||
global Unit* FindGoldMine(int x,int y)
|
||||
global Unit* FindGoldMine(const Unit* source,int x,int y)
|
||||
{
|
||||
#ifdef NEW_UNIT
|
||||
DebugLevel0("FIXME:");
|
||||
Unit** table;
|
||||
Unit* unit;
|
||||
Unit* best;
|
||||
int best_d;
|
||||
int d;
|
||||
|
||||
return NULL;
|
||||
// FIXME: this is not the best one
|
||||
// We need the deposit with the shortest way!
|
||||
// At least it must be reachable!
|
||||
// Should use the same pathfinder flood fill, like the attacking
|
||||
// code.
|
||||
|
||||
best=NoUnitP;
|
||||
best_d=99999;
|
||||
for( table=Units; table<Units+NumUnits; table++ ) {
|
||||
unit=*table;
|
||||
// Want gold-mine and not dieing.
|
||||
if( !unit->Type->GoldMine || UnitUnusable(unit) ) {
|
||||
continue;
|
||||
}
|
||||
d=MapDistanceToUnit(x,y,unit);
|
||||
if( d<best_d && UnitReachable(source,unit) ) {
|
||||
best_d=d;
|
||||
best=unit;
|
||||
}
|
||||
}
|
||||
DebugLevel3(__FUNCTION__": %Zd %d,%d\n",UnitNumber(best),best->X,best->Y);
|
||||
return best;
|
||||
#else
|
||||
Unit* unit;
|
||||
Unit* best;
|
||||
|
@ -2165,16 +2325,6 @@ global int CanTarget(const UnitType* source,const UnitType* dest)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
** Start conflicts.
|
||||
**
|
||||
** Attack units in reaction range.
|
||||
*/
|
||||
global void UnitConflicts(void)
|
||||
{
|
||||
// FIXME: here I can resolve all conflicts
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- SAVE/LOAD
|
||||
----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -55,18 +55,28 @@ global int SelectUnits(int x1,int y1,int x2,int y2,Unit** table)
|
|||
**
|
||||
** @return Returns the number of units found.
|
||||
*/
|
||||
global int FindUnitsByType(int type,Unit** table)
|
||||
global int FindUnitsByType(const UnitType* type,Unit** table)
|
||||
{
|
||||
#ifdef NEW_UNIT
|
||||
DebugLevel0("FIXME:");
|
||||
return 1;
|
||||
Unit* unit;
|
||||
int i;
|
||||
int num;
|
||||
|
||||
for( num=i=0; i<NumUnits; i++ ) {
|
||||
unit=Units[i];
|
||||
if( unit->Type==type && !UnitUnusable(unit) ) {
|
||||
table[num++]=unit;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
#else
|
||||
Unit* unit;
|
||||
int num,i;
|
||||
int i;
|
||||
int num;
|
||||
|
||||
for( num=0, i=0; i<NumUnits; i++ ) {
|
||||
for( num=i=0; i<NumUnits; i++ ) {
|
||||
unit=Units[i];
|
||||
if( unit->Type->Type==type && !UnitUnusable(unit) ) {
|
||||
if( unit->Type==type && !UnitUnusable(unit) ) {
|
||||
table[num++]=unit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,11 @@
|
|||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
** Next unit type are used hardcoded in the source.
|
||||
*/
|
||||
global UnitType* UnitTypeGoldMine; /// Gold mine unit type pointer.
|
||||
|
||||
/**
|
||||
** Lookup table for unit-type names
|
||||
*/
|
||||
|
@ -1040,6 +1045,11 @@ global void InitUnitTypes(void)
|
|||
*(UnitType**)hash_add(UnitTypeHash,UnitTypes[type].Ident)
|
||||
=&UnitTypes[type];
|
||||
}
|
||||
|
||||
//
|
||||
// Setup hardcoded unit types.
|
||||
//
|
||||
UnitTypeGoldMine=UnitTypeByIdent("unit-gold-mine");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -387,6 +387,7 @@ global void InvalidateArea(int x,int y,int w,int h)
|
|||
y=0;
|
||||
}
|
||||
if( !w<=0 && !h<=0 ) {
|
||||
DebugLevel3("X %d,%d -> %d,%d\n",x,y,w,h);
|
||||
XClearArea(TheDisplay,TheMainWindow,x,y,w,h,False);
|
||||
}
|
||||
}
|
||||
|
@ -1049,6 +1050,7 @@ global void RealizeVideoMemory(void)
|
|||
{
|
||||
// in X11 it does flushing the output queue
|
||||
XFlush(TheDisplay);
|
||||
//XSync(TheDisplay,False);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue