Prepared NEW_ORDERS.
This commit is contained in:
parent
6888515ac7
commit
e2df9ddf70
17 changed files with 1431 additions and 1078 deletions
|
@ -47,15 +47,17 @@ global void HandleActionBuild(Unit* unit)
|
|||
{
|
||||
int x;
|
||||
int y;
|
||||
int dx;
|
||||
int dy;
|
||||
int n;
|
||||
UnitType* type;
|
||||
const UnitStats* stats;
|
||||
Unit* build;
|
||||
Unit* temp;
|
||||
|
||||
#ifdef NEW_ORDERS
|
||||
type=unit->Orders[0].Type;
|
||||
#else
|
||||
type=unit->Command.Data.Build.BuildThis;
|
||||
#endif
|
||||
switch( HandleActionMove(unit) ) { // reached end-point?
|
||||
case PF_UNREACHABLE:
|
||||
// FIXME: use general notify/messages
|
||||
|
@ -73,36 +75,13 @@ global void HandleActionBuild(Unit* unit)
|
|||
}
|
||||
|
||||
// Must be reached!
|
||||
IfDebug(
|
||||
// Check internal code, if really reached?
|
||||
x=unit->X;
|
||||
y=unit->Y;
|
||||
dx=unit->Command.Data.Move.DX;
|
||||
dy=unit->Command.Data.Move.DY;
|
||||
if( type->ShoreBuilding ) {
|
||||
++dx;
|
||||
++dy;
|
||||
}
|
||||
n=type->ShoreBuilding&1;
|
||||
//
|
||||
// Check if building place reached.
|
||||
//
|
||||
DebugLevel3Fn("`%s' %d,%d - %d,%d (%d)\n"
|
||||
,type->Name
|
||||
,dx-n,dy-n
|
||||
,dx+type->TileWidth+n
|
||||
,dy+type->TileHeight+n
|
||||
,n);
|
||||
|
||||
if( x<dx-n || x>=dx+type->TileWidth+n
|
||||
|| y<dy-n || y>=dy+type->TileHeight+n ) {
|
||||
DebugLevel0Fn("Internal error\n");
|
||||
abort();
|
||||
}
|
||||
);
|
||||
|
||||
#ifdef NEW_ORDERS
|
||||
x=unit->Orders[0].X;
|
||||
y=unit->Orders[0].Y;
|
||||
#else
|
||||
x=unit->Command.Data.Move.DX;
|
||||
y=unit->Command.Data.Move.DY;
|
||||
#endif
|
||||
if( type->ShoreBuilding ) { // correct coordinates.
|
||||
++x;
|
||||
++y;
|
||||
|
@ -140,6 +119,19 @@ global void HandleActionBuild(Unit* unit)
|
|||
build->Player->UnitTypesCount[type->Type]--;
|
||||
build->Constructed=1;
|
||||
build->HP=0;
|
||||
#ifdef NEW_ORDERS
|
||||
build->Orders[0].Action=UnitActionBuilded;
|
||||
build->Data.Builded.Sum=0; // FIXME: Is it necessary?
|
||||
build->Data.Builded.Val=stats->HitPoints;
|
||||
n=(stats->Costs[TimeCost]*FRAMES_PER_SECOND/6)/(SpeedBuild*5);
|
||||
build->Data.Builded.Add=stats->HitPoints/n;
|
||||
build->Data.Builded.Sub=n;
|
||||
build->Data.Builded.Cancel=0; // FIXME: Is it necessary?
|
||||
build->Data.Builded.Worker=unit;
|
||||
DebugLevel3Fn("Build Sum %d, Add %d, Val %d, Sub %d\n"
|
||||
,build->Data.Builded.Sum,build->Data.Builded.Add
|
||||
,build->Data.Builded.Val,build->Data.Builded.Sub);
|
||||
#else
|
||||
build->Command.Action=UnitActionBuilded;
|
||||
build->Command.Data.Builded.Sum=0; // FIXME: Is it necessary?
|
||||
build->Command.Data.Builded.Val=stats->HitPoints;
|
||||
|
@ -149,11 +141,10 @@ global void HandleActionBuild(Unit* unit)
|
|||
build->Command.Data.Builded.Cancel=0; // FIXME: Is it necessary?
|
||||
build->Command.Data.Builded.Worker=unit;
|
||||
DebugLevel3Fn("Build Sum %d, Add %d, Val %d, Sub %d\n"
|
||||
,build->Command.Data.Builded.Sum
|
||||
,build->Command.Data.Builded.Add
|
||||
,build->Command.Data.Builded.Val
|
||||
,build->Command.Data.Builded.Sub);
|
||||
build->Wait=5;
|
||||
,build->Command.Data.Builded.Sum,build->Command.Data.Builded.Add
|
||||
,build->Command.Data.Builded.Val,build->Command.Data.Builded.Sub);
|
||||
#endif
|
||||
build->Wait=FRAMES_PER_SECOND/6;
|
||||
|
||||
//
|
||||
// Building oil-platform, must remove oilpatch.
|
||||
|
@ -167,11 +158,15 @@ global void HandleActionBuild(Unit* unit)
|
|||
DestroyUnit(temp); // Destroy oil patch
|
||||
}
|
||||
|
||||
RemoveUnit(unit);/* automaticly: CheckUnitToBeDrawn(unit) */
|
||||
RemoveUnit(unit); /* automaticly: CheckUnitToBeDrawn(unit) */
|
||||
|
||||
unit->X=x;
|
||||
unit->Y=y;
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
#else
|
||||
unit->Command.Action=UnitActionStill;
|
||||
#endif
|
||||
|
||||
CheckUnitToBeDrawn(build);
|
||||
MustRedraw|=RedrawMinimap;
|
||||
|
@ -192,13 +187,23 @@ global void HandleActionBuilded(Unit* unit)
|
|||
//
|
||||
// Check if construction should be canceled...
|
||||
//
|
||||
#ifdef NEW_ORDERS
|
||||
if( unit->Data.Builded.Cancel ) {
|
||||
// Drop out unit
|
||||
peon=unit->Data.Builded.Worker;
|
||||
peon->Reset=1;
|
||||
peon->Wait=1;
|
||||
peon->Orders[0].Action=UnitActionStill;
|
||||
unit->Data.Builded.Worker=NoUnitP;
|
||||
#else
|
||||
if( unit->Command.Data.Builded.Cancel ) {
|
||||
// Drop out unit
|
||||
peon=unit->Command.Data.Builded.Worker;
|
||||
peon->Reset=1;
|
||||
peon->Wait=1;
|
||||
peon->Command.Action=UnitActionStill;
|
||||
unit->Command.Data.Builded.Worker=NULL;
|
||||
unit->Command.Data.Builded.Worker=NoUnitP;
|
||||
#endif
|
||||
unit->Value=peon->Value; // peon holding value while building
|
||||
DropOutOnSide(peon,LookingW,type->TileWidth,type->TileHeight);
|
||||
// Cancel building
|
||||
|
@ -208,6 +213,22 @@ global void HandleActionBuilded(Unit* unit)
|
|||
|
||||
// FIXME: if attacked subtract hit points!!
|
||||
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Data.Builded.Val-=unit->Data.Builded.Sub;
|
||||
if( unit->Data.Builded.Val<0 ) {
|
||||
unit->Data.Builded.Val+=unit->Stats->HitPoints;
|
||||
unit->HP++;
|
||||
unit->Data.Builded.Sum++;
|
||||
}
|
||||
unit->HP+=unit->Data.Builded.Add;
|
||||
unit->Data.Builded.Sum+=unit->Data.Builded.Add;
|
||||
|
||||
//
|
||||
// Check if building ready.
|
||||
//
|
||||
if( unit->Data.Builded.Sum>=unit->Stats->HitPoints
|
||||
|| unit->HP>=unit->Stats->HitPoints ) {
|
||||
#else
|
||||
unit->Command.Data.Builded.Val-=unit->Command.Data.Builded.Sub;
|
||||
if( unit->Command.Data.Builded.Val<0 ) {
|
||||
unit->Command.Data.Builded.Val+=unit->Stats->HitPoints;
|
||||
|
@ -222,10 +243,15 @@ global void HandleActionBuilded(Unit* unit)
|
|||
//
|
||||
if( unit->Command.Data.Builded.Sum>=unit->Stats->HitPoints
|
||||
|| unit->HP>=unit->Stats->HitPoints ) {
|
||||
#endif
|
||||
if( unit->HP>unit->Stats->HitPoints ) {
|
||||
unit->HP=unit->Stats->HitPoints;
|
||||
}
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
#else
|
||||
unit->Command.Action=UnitActionStill;
|
||||
#endif
|
||||
// HACK: the building is ready now
|
||||
unit->Player->UnitTypesCount[type->Type]++;
|
||||
unit->Constructed=0;
|
||||
|
@ -233,8 +259,13 @@ global void HandleActionBuilded(Unit* unit)
|
|||
unit->Reset=1;
|
||||
unit->Wait=1;
|
||||
|
||||
#ifdef NEW_ORDERS
|
||||
peon=unit->Data.Builded.Worker;
|
||||
peon->Orders[0].Action=UnitActionStill;
|
||||
#else
|
||||
peon=unit->Command.Data.Builded.Worker;
|
||||
peon->Command.Action=UnitActionStill;
|
||||
#endif
|
||||
peon->Reset=1;
|
||||
peon->Wait=1;
|
||||
DropOutOnSide(peon,LookingW,type->TileWidth,type->TileHeight);
|
||||
|
@ -245,9 +276,14 @@ global void HandleActionBuilded(Unit* unit)
|
|||
if( type->GivesOil ) {
|
||||
CommandHaulOil(peon,unit,0); // Let the unit haul oil
|
||||
DebugLevel0Fn("Update oil-platform\n");
|
||||
#ifdef NEW_ORDERS
|
||||
DebugLevel0Fn(" =%d\n",unit->Data.Resource.Active);
|
||||
unit->Data.Resource.Active=0;
|
||||
#else
|
||||
DebugLevel0Fn(" =%d\n",unit->Command.Data.Resource.Active);
|
||||
unit->Command.Data.Resource.Active=0;
|
||||
unit->Value=peon->Value; // peon was holding value while building
|
||||
#endif
|
||||
unit->Value=peon->Value; // peon was holding value while building
|
||||
}
|
||||
|
||||
// FIXME: General message system
|
||||
|
@ -286,13 +322,21 @@ global void HandleActionBuilded(Unit* unit)
|
|||
//
|
||||
// Update building states
|
||||
//
|
||||
#ifdef NEW_ORDERS
|
||||
if( unit->Data.Builded.Sum*2>=unit->Stats->HitPoints ) {
|
||||
#else
|
||||
if( unit->Command.Data.Builded.Sum*2>=unit->Stats->HitPoints ) {
|
||||
#endif
|
||||
if( (unit->Frame!=1 || unit->Constructed) ) {
|
||||
CheckUnitToBeDrawn(unit);
|
||||
}
|
||||
unit->Constructed=0;
|
||||
unit->Frame=1;
|
||||
#ifdef NEW_ORDERS
|
||||
} else if( unit->Data.Builded.Sum*4>=unit->Stats->HitPoints ) {
|
||||
#else
|
||||
} else if( unit->Command.Data.Builded.Sum*4>=unit->Stats->HitPoints ) {
|
||||
#endif
|
||||
if( unit->Frame!=1 ) {
|
||||
CheckUnitToBeDrawn(unit);
|
||||
}
|
||||
|
|
|
@ -60,9 +60,14 @@ global void HandleActionDemolish(Unit* unit)
|
|||
// FIXME: reset first!! why? (johns)
|
||||
err=HandleActionMove(unit);
|
||||
if( unit->Reset ) {
|
||||
#ifdef NEW_ORDERS
|
||||
goal=unit->Orders[0].Goal;
|
||||
#else
|
||||
goal=unit->Command.Data.Move.Goal;
|
||||
#endif
|
||||
//
|
||||
// Target is dead, stop demolish
|
||||
// Target is dead, stop demolish.
|
||||
// FIXME: what should I do, go back or explode on place?
|
||||
//
|
||||
if( goal ) {
|
||||
if( goal->Destroyed ) {
|
||||
|
@ -71,8 +76,21 @@ global void HandleActionDemolish(Unit* unit)
|
|||
if( !--goal->Refs ) {
|
||||
ReleaseUnit(goal);
|
||||
}
|
||||
unit->Command.Data.Move.Goal=goal=NoUnitP;
|
||||
// FIXME: perhaps I should choose an alternative
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Goal=goal=NoUnitP;
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
return;
|
||||
} else if( goal->Removed || !goal->HP
|
||||
|| goal->Orders[0].Action==UnitActionDie ) {
|
||||
RefsDebugCheck( !goal->Refs );
|
||||
--goal->Refs;
|
||||
RefsDebugCheck( !goal->Refs );
|
||||
unit->Orders[0].Goal=goal=NoUnitP;
|
||||
// FIXME: perhaps I should choose an alternative
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
#else
|
||||
unit->Command.Data.Move.Goal=goal=NoUnitP;
|
||||
unit->Command.Action=UnitActionStill;
|
||||
return;
|
||||
} else if( goal->Removed || !goal->HP
|
||||
|
@ -80,9 +98,10 @@ global void HandleActionDemolish(Unit* unit)
|
|||
RefsDebugCheck( !goal->Refs );
|
||||
--goal->Refs;
|
||||
RefsDebugCheck( !goal->Refs );
|
||||
unit->Command.Data.Move.Goal=goal=NoUnitP;
|
||||
// FIXME: perhaps I should choose an alternative
|
||||
unit->Command.Data.Move.Goal=goal=NoUnitP;
|
||||
unit->Command.Action=UnitActionStill;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -96,14 +115,22 @@ global void HandleActionDemolish(Unit* unit)
|
|||
unit->SubAction=1;
|
||||
}
|
||||
} else if( MapDistance(unit->X,unit->Y
|
||||
#ifdef NEW_ORDERS
|
||||
,unit->Orders[0].X,unit->Orders[0].Y)<=1 ) {
|
||||
#else
|
||||
,unit->Command.Data.Move.DX
|
||||
,unit->Command.Data.Move.DY)<=1 ) {
|
||||
#endif
|
||||
unit->State=0;
|
||||
unit->SubAction=1;
|
||||
} else if( err==PF_UNREACHABLE ) {
|
||||
return;
|
||||
}
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action=UnitActionDemolish;
|
||||
#else
|
||||
unit->Command.Action=UnitActionDemolish;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -111,12 +138,20 @@ global void HandleActionDemolish(Unit* unit)
|
|||
// Demolish the target.
|
||||
//
|
||||
case 1:
|
||||
#ifdef NEW_ORDERS
|
||||
goal=unit->Orders[0].Goal;
|
||||
#else
|
||||
goal=unit->Command.Data.Move.Goal;
|
||||
#endif
|
||||
if( goal ) {
|
||||
RefsDebugCheck( !goal->Refs );
|
||||
--goal->Refs;
|
||||
RefsDebugCheck( !goal->Refs );
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Goal=NoUnitP;
|
||||
#else
|
||||
unit->Command.Data.Move.Goal=NoUnitP;
|
||||
#endif
|
||||
}
|
||||
|
||||
x=unit->X;
|
||||
|
|
|
@ -346,8 +346,6 @@ local int ReturnWithWood(Unit* unit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
DebugCheck( !destu );
|
||||
|
||||
//
|
||||
// Target is dead, stop harvest
|
||||
//
|
||||
|
@ -373,6 +371,17 @@ local int ReturnWithWood(Unit* unit)
|
|||
unit->SubAction=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unit->Orders[0].Action=UnitActionHarvest;
|
||||
|
||||
//
|
||||
// If depot is still under construction, wait!
|
||||
//
|
||||
if( destu->Orders[0].Action==UnitActionBuilded ) {
|
||||
DebugLevel2Fn("Invalid depot\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
unit->Orders[0].Goal=NoUnitP;
|
||||
|
||||
RefsDebugCheck( !destu->Refs );
|
||||
|
@ -382,15 +391,13 @@ local int ReturnWithWood(Unit* unit)
|
|||
if( i==PF_UNREACHABLE ) {
|
||||
// FIXME: could try another depot, or retry later.
|
||||
DebugLevel2Fn("WOOD-DEPOSIT NOT REACHED %Zd=%d,%d ? %d\n"
|
||||
,UnitNumber(destu),x,y
|
||||
,UnitNumber(destu),destu->X,destu->Y
|
||||
,MapDistanceToUnit(unit->X,unit->Y,destu));
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
unit->SubAction=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unit->Orders[0].Action=UnitActionHarvest;
|
||||
|
||||
#else
|
||||
|
||||
destu=unit->Command.Data.Move.Goal;
|
||||
|
@ -401,8 +408,6 @@ local int ReturnWithWood(Unit* unit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
DebugCheck( !destu );
|
||||
|
||||
//
|
||||
// Target is dead, stop harvest
|
||||
//
|
||||
|
@ -428,6 +433,17 @@ local int ReturnWithWood(Unit* unit)
|
|||
unit->SubAction=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unit->Command.Action=UnitActionHarvest;
|
||||
|
||||
//
|
||||
// If depot is still under construction, wait!
|
||||
//
|
||||
if( destu->Command.Action==UnitActionBuilded ) {
|
||||
DebugLevel2Fn("Invalid depot\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
unit->Command.Data.Move.Goal=NoUnitP;
|
||||
|
||||
RefsDebugCheck( !destu->Refs );
|
||||
|
@ -444,8 +460,6 @@ local int ReturnWithWood(Unit* unit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
unit->Command.Action=UnitActionHarvest;
|
||||
|
||||
#endif
|
||||
|
||||
RemoveUnit(unit);
|
||||
|
|
|
@ -96,7 +96,7 @@ local int MoveToGoldMine(Unit* unit)
|
|||
|
||||
//
|
||||
// Check if mine could be reached.
|
||||
/
|
||||
//
|
||||
if( i==PF_UNREACHABLE ) {
|
||||
// FIXME: could try another mine, or retry later.
|
||||
DebugLevel3Fn("GOLD-MINE NOT REACHED %Zd=%d,%d ? %d\n"
|
||||
|
@ -397,9 +397,17 @@ local int MoveToGoldDeposit(Unit* unit)
|
|||
|
||||
unit->Orders[0].Action=UnitActionMineGold;
|
||||
|
||||
//
|
||||
// If depot is still under construction, wait!
|
||||
//
|
||||
if( destu->Orders[0].Action==UnitActionBuilded ) {
|
||||
DebugLevel2Fn("Invalid depot\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if depot could be reached.
|
||||
/
|
||||
//
|
||||
if( i==PF_UNREACHABLE ) {
|
||||
// FIXME: could try another mine, or retry later.
|
||||
DebugLevel3Fn("GOLD-DEPOT NOT REACHED %Zd=%d,%d ? %d\n"
|
||||
|
@ -455,11 +463,19 @@ local int MoveToGoldDeposit(Unit* unit)
|
|||
unit->Command.Action=UnitActionMineGold;
|
||||
|
||||
//
|
||||
// Check if mine could be reached.
|
||||
// If depot is still under construction, wait!
|
||||
//
|
||||
if( destu->Command.Action==UnitActionBuilded ) {
|
||||
DebugLevel2Fn("Invalid depot\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if depot could be reached.
|
||||
//
|
||||
if( i==PF_UNREACHABLE ) {
|
||||
// FIXME: could try another mine, or retry later.
|
||||
DebugLevel3Fn("GOLD-MINE NOT REACHED %Zd=%d,%d ? %d\n"
|
||||
DebugLevel3Fn("GOLD-DEPOT NOT REACHED %Zd=%d,%d ? %d\n"
|
||||
,UnitNumber(destu),destu->X,destu->Y
|
||||
,MapDistanceToUnit(unit->X,unit->Y,destu));
|
||||
return -1;
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
|
||||
//@{
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Includes
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -31,27 +35,47 @@
|
|||
#include "upgrade.h"
|
||||
#include "interface.h"
|
||||
|
||||
/*
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Unit researches!
|
||||
**
|
||||
** @param unit Pointer of researching unit.
|
||||
*/
|
||||
global void HandleActionResearch(Unit* unit)
|
||||
{
|
||||
Upgrade* upgrade;
|
||||
|
||||
DebugLevel3("Research %Zd\n",UnitNumber(unit));
|
||||
|
||||
#ifdef NEW_ORDERS
|
||||
upgrade=unit->Data.Research.Upgrade;
|
||||
unit->Data.Research.Ticks+=SpeedResearch;
|
||||
|
||||
if( unit->Data.Research.Ticks>=upgrade->Costs[TimeCost] ) {
|
||||
#else
|
||||
upgrade=unit->Command.Data.Research.What;
|
||||
unit->Command.Data.Research.Ticks+=SpeedResearch;
|
||||
|
||||
if( unit->Command.Data.Research.Ticks>=upgrade->Costs[TimeCost] ) {
|
||||
#endif
|
||||
|
||||
// FIXME: should als speak and tell ai. generic notify/message.
|
||||
if( unit->Player==ThisPlayer ) {
|
||||
SetMessage2( unit->X, unit->Y, "%s: Upgrade complete", unit->Type->Name );
|
||||
SetMessage2(unit->X, unit->Y, "%s: Upgrade complete"
|
||||
,unit->Type->Name );
|
||||
}
|
||||
UpgradeAcquire(unit->Player,upgrade);
|
||||
|
||||
unit->Reset=1;
|
||||
unit->Wait=1;
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
#else
|
||||
unit->Command.Action=UnitActionStill;
|
||||
#endif
|
||||
|
||||
// Upgrade can change all
|
||||
UpdateButtonPanel();
|
||||
|
@ -66,6 +90,7 @@ global void HandleActionResearch(Unit* unit)
|
|||
|
||||
unit->Reset=1;
|
||||
unit->Wait=FRAMES_PER_SECOND/6;
|
||||
|
||||
// FIXME: should animations here?
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,11 @@ local int MoveToResource(Unit* unit,const Resource* resource)
|
|||
|
||||
switch( HandleActionMove(unit) ) { // reached end-point?
|
||||
case PF_UNREACHABLE:
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action=resource->Action;
|
||||
#else
|
||||
unit->Command.Action=resource->Action;
|
||||
#endif
|
||||
return -1;
|
||||
case PF_REACHED:
|
||||
break;
|
||||
|
@ -402,7 +406,11 @@ local int MoveToDepot(Unit* unit,const Resource* resource)
|
|||
|
||||
switch( HandleActionMove(unit) ) { // reached end-point?
|
||||
case PF_UNREACHABLE:
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action=resource->Action;
|
||||
#else
|
||||
unit->Command.Action=resource->Action;
|
||||
#endif
|
||||
return -1;
|
||||
case PF_REACHED:
|
||||
break;
|
||||
|
|
|
@ -73,44 +73,62 @@ global int AnimateActionSpellCast(Unit* unit)
|
|||
**
|
||||
** @param unit Unit, for that the spell cast is handled.
|
||||
*/
|
||||
local void SpellMoveToTarget(Unit* unit)
|
||||
local void SpellMoveToTarget(Unit * unit)
|
||||
{
|
||||
Unit* goal;
|
||||
int err;
|
||||
Unit *goal;
|
||||
int err;
|
||||
|
||||
err = HandleActionMove(unit);
|
||||
if ( !unit->Reset ) return;
|
||||
// when reached HandleActionMove changes unit action
|
||||
unit->Command.Action = UnitActionSpellCast;
|
||||
err = HandleActionMove(unit);
|
||||
if (!unit->Reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
goal = unit->Command.Data.Move.Goal;
|
||||
if( goal && MapDistanceToUnit(unit->X,unit->Y,goal)
|
||||
<= unit->Command.Data.Move.Range )
|
||||
{ // there is goal and it is in range
|
||||
unit->State=0;
|
||||
UnitHeadingFromDeltaXY(unit,goal->X - unit->X,
|
||||
goal->Y - unit->Y);
|
||||
unit->SubAction = 1; // cast the spell
|
||||
return;
|
||||
} else
|
||||
if( !goal && MapDistance(unit->X,unit->Y,
|
||||
unit->Command.Data.Move.DX,unit->Command.Data.Move.DY)
|
||||
<= unit->Command.Data.Move.Range )
|
||||
{ // there is no goal and target spot is in range
|
||||
unit->State=0;
|
||||
UnitHeadingFromDeltaXY(unit,
|
||||
unit->Command.Data.Move.DX - unit->X,
|
||||
unit->Command.Data.Move.DY - unit->Y);
|
||||
unit->SubAction = 1; // cast the spell
|
||||
return;
|
||||
} else
|
||||
if( err )
|
||||
{ // goal/spot out of range -- move to target
|
||||
// FIXME: Should handle new return codes (err) here (for Fabrice)
|
||||
unit->State=0;
|
||||
unit->SubAction=0;
|
||||
}
|
||||
DebugCheck( unit->Type->Vanishes || unit->Destroyed );
|
||||
// when reached HandleActionMove changes unit action
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action = UnitActionSpellCast;
|
||||
|
||||
goal = unit->Orders[0].Goal;
|
||||
if (goal && MapDistanceToUnit(unit->X, unit->Y, goal)
|
||||
<= unit->Orders[0].RangeX) {
|
||||
#else
|
||||
unit->Command.Action = UnitActionSpellCast;
|
||||
|
||||
goal = unit->Command.Data.Move.Goal;
|
||||
if (goal && MapDistanceToUnit(unit->X, unit->Y, goal)
|
||||
<= unit->Command.Data.Move.Range) {
|
||||
#endif
|
||||
|
||||
// there is goal and it is in range
|
||||
unit->State = 0;
|
||||
UnitHeadingFromDeltaXY(unit, goal->X - unit->X, goal->Y - unit->Y);
|
||||
unit->SubAction = 1; // cast the spell
|
||||
return;
|
||||
#ifdef NEW_ORDERS
|
||||
} else if (!goal && MapDistance(unit->X, unit->Y, unit->Orders[0].X,
|
||||
unit->Orders[0].Y) <= unit->Orders[0].RangeX) {
|
||||
// there is no goal and target spot is in range
|
||||
unit->State = 0;
|
||||
UnitHeadingFromDeltaXY(unit, unit->Orders[0].X - unit->X,
|
||||
unit->Orders[0].Y - unit->Y);
|
||||
#else
|
||||
} else if (!goal
|
||||
&& MapDistance(unit->X, unit->Y, unit->Command.Data.Move.DX,
|
||||
unit->Command.Data.Move.DY)
|
||||
<= unit->Command.Data.Move.Range) {
|
||||
// there is no goal and target spot is in range
|
||||
unit->State = 0;
|
||||
UnitHeadingFromDeltaXY(unit, unit->Command.Data.Move.DX - unit->X,
|
||||
unit->Command.Data.Move.DY - unit->Y);
|
||||
#endif
|
||||
unit->SubAction = 1; // cast the spell
|
||||
return;
|
||||
} else if (err) {
|
||||
// goal/spot out of range -- move to target
|
||||
// FIXME: Should handle new return codes (err) here (for Fabrice)
|
||||
unit->State = 0;
|
||||
unit->SubAction = 0;
|
||||
}
|
||||
DebugCheck(unit->Type->Vanishes || unit->Destroyed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,60 +136,84 @@ local void SpellMoveToTarget(Unit* unit)
|
|||
**
|
||||
** @param unit Unit, for that the spell cast is handled.
|
||||
*/
|
||||
global void HandleActionSpellCast(Unit* unit)
|
||||
global void HandleActionSpellCast(Unit * unit)
|
||||
{
|
||||
int repeat = 0; // repeat spell on next pass? (defaults to `no')
|
||||
int repeat;
|
||||
const SpellType *spell;
|
||||
|
||||
DebugLevel3Fn("SpellCast %Zd\n",UnitNumber(unit));
|
||||
repeat = 0; // repeat spell on next pass? (defaults to `no')
|
||||
|
||||
switch( unit->SubAction ) {
|
||||
DebugLevel3Fn("SpellCast %Zd\n", UnitNumber(unit));
|
||||
|
||||
case 0: // Move to the target.
|
||||
SpellMoveToTarget(unit);
|
||||
break;
|
||||
switch (unit->SubAction) {
|
||||
|
||||
case 1: // Cast spell on the target.
|
||||
{
|
||||
const SpellType* spell = SpellTypeById( unit->Command.Data.Move.SpellId );
|
||||
if ( unit->Mana < spell->ManaCost )
|
||||
{
|
||||
if( unit->Player==ThisPlayer )
|
||||
{
|
||||
SetMessage( "%s: not enough mana to cast spell: %s",
|
||||
unit->Type->Name, spell->Ident );
|
||||
}
|
||||
repeat = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnitShowAnimation(unit,unit->Type->Animations->Attack);
|
||||
if ( !unit->Reset ) return;
|
||||
if ( unit->Command.Data.Move.Goal &&
|
||||
unit->Command.Data.Move.Goal->Destroyed )
|
||||
repeat = 0;
|
||||
else
|
||||
repeat = SpellCast(unit->Command.Data.Move.SpellId,
|
||||
unit,
|
||||
unit->Command.Data.Move.Goal,
|
||||
unit->Command.Data.Move.DX,
|
||||
unit->Command.Data.Move.DY );
|
||||
}
|
||||
if ( !repeat ) {
|
||||
unit->Command.Action=UnitActionStill;
|
||||
unit->SubAction=0;
|
||||
unit->Wait = 1;
|
||||
if ( unit->Command.Data.Move.Goal ) {
|
||||
RefsDebugCheck( !unit->Command.Data.Move.Goal->Refs );
|
||||
unit->Command.Data.Move.Goal->Refs--;
|
||||
RefsDebugCheck( !unit->Command.Data.Move.Goal->Refs );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0: // Move to the target.
|
||||
SpellMoveToTarget(unit);
|
||||
break;
|
||||
|
||||
default:
|
||||
unit->SubAction = 0; // Move to the target
|
||||
case 1: // Cast spell on the target.
|
||||
#ifdef NEW_ORDERS
|
||||
spell = unit->Orders[0].Arg1;
|
||||
#else
|
||||
spell = SpellTypeById(unit->Command.Data.Move.SpellId);
|
||||
#endif
|
||||
// FIXME: Use the general unified message system.
|
||||
if (unit->Mana < spell->ManaCost) {
|
||||
if (unit->Player == ThisPlayer) {
|
||||
SetMessage("%s: not enough mana to cast spell: %s",
|
||||
unit->Type->Name, spell->Ident);
|
||||
}
|
||||
repeat = 0;
|
||||
} else {
|
||||
UnitShowAnimation(unit, unit->Type->Animations->Attack);
|
||||
if (!unit->Reset) {
|
||||
return;
|
||||
}
|
||||
// FIXME: what todo, if unit/goal is removed?
|
||||
#ifdef NEW_ORDERS
|
||||
if (unit->Orders[0].Goal && unit->Orders[0].Goal->Destroyed) {
|
||||
repeat = 0;
|
||||
} else {
|
||||
repeat = SpellCast(unit->Orders[0].Arg1, unit,
|
||||
unit->Orders[0].Goal,unit->Orders[0].X,unit->Orders[0].Y);
|
||||
}
|
||||
}
|
||||
if (!repeat) {
|
||||
unit->Orders[0].Action = UnitActionStill;
|
||||
unit->SubAction = 0;
|
||||
unit->Wait = 1;
|
||||
if (unit->Orders[0].Goal) {
|
||||
RefsDebugCheck(!unit->Orders[0].Goal->Refs);
|
||||
unit->Orders[0].Goal->Refs--;
|
||||
RefsDebugCheck(!unit->Orders[0].Goal->Refs);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (unit->Command.Data.Move.Goal
|
||||
&& unit->Command.Data.Move.Goal->Destroyed) {
|
||||
repeat = 0;
|
||||
} else {
|
||||
repeat = SpellCast(spell, unit,
|
||||
unit->Command.Data.Move.Goal,
|
||||
unit->Command.Data.Move.DX,unit->Command.Data.Move.DY);
|
||||
}
|
||||
}
|
||||
if (!repeat) {
|
||||
unit->Command.Action = UnitActionStill;
|
||||
unit->SubAction = 0;
|
||||
unit->Wait = 1;
|
||||
if (unit->Command.Data.Move.Goal) {
|
||||
RefsDebugCheck(!unit->Command.Data.Move.Goal->Refs);
|
||||
unit->Command.Data.Move.Goal->Refs--;
|
||||
RefsDebugCheck(!unit->Command.Data.Move.Goal->Refs);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
unit->SubAction = 0; // Move to the target
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -49,28 +49,23 @@
|
|||
global void HandleActionTrain(Unit* unit)
|
||||
{
|
||||
Unit* nunit;
|
||||
UnitType* type;
|
||||
const UnitType* type;
|
||||
Player* player;
|
||||
|
||||
#if 0
|
||||
// JOHNS: should be checked by the user-interface
|
||||
if( &Players[unit->Player]==ThisPlayer ) {
|
||||
// FIXME: If so used you get millions of messages.
|
||||
if( ThisPlayer->Food<=ThisPlayer->Units
|
||||
&& unit->Command.Data.Train.Ticks ) {
|
||||
SetMessage( "You need more farms!" );
|
||||
} else {
|
||||
AiNeedMoreFarms(unit);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
player=unit->Player;
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Data.Train.Ticks+=SpeedTrain;
|
||||
// FIXME: Should count down
|
||||
if( unit->Data.Train.Ticks
|
||||
>=unit->Data.Train.What[0]
|
||||
->Stats[player->Player].Costs[TimeCost] ) {
|
||||
#else
|
||||
unit->Command.Data.Train.Ticks+=SpeedTrain;
|
||||
// FIXME: Should count down
|
||||
if( unit->Command.Data.Train.Ticks
|
||||
>=unit->Command.Data.Train.What[0]
|
||||
->Stats[player->Player].Costs[TimeCost] ) {
|
||||
#endif
|
||||
|
||||
//
|
||||
// Check if enough food available.
|
||||
|
@ -86,14 +81,21 @@ global void HandleActionTrain(Unit* unit)
|
|||
// AiNeedMoreFarms(unit);
|
||||
}
|
||||
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Data.Train.Ticks-=SpeedTrain;
|
||||
#else
|
||||
unit->Command.Data.Train.Ticks-=SpeedTrain;
|
||||
#endif
|
||||
unit->Reset=1;
|
||||
unit->Wait=FRAMES_PER_SECOND/6;
|
||||
return;
|
||||
}
|
||||
|
||||
nunit=MakeUnit(&UnitTypes[unit->Command.Data.Train.What[0]->Type]
|
||||
,player);
|
||||
#ifdef NEW_ORDERS
|
||||
nunit=MakeUnit(unit->Data.Train.What[0],player);
|
||||
#else
|
||||
nunit=MakeUnit(unit->Command.Data.Train.What[0],player);
|
||||
#endif
|
||||
nunit->X=unit->X;
|
||||
nunit->Y=unit->Y;
|
||||
type=unit->Type;
|
||||
|
@ -110,6 +112,30 @@ global void HandleActionTrain(Unit* unit)
|
|||
unit->Reset=1;
|
||||
unit->Wait=1;
|
||||
|
||||
#ifdef NEW_ORDERS
|
||||
if ( --unit->Data.Train.Count ) {
|
||||
int z;
|
||||
for( z = 0; z < unit->Data.Train.Count ; z++ ) {
|
||||
unit->Data.Train.What[z]=unit->Data.Train.What[z+1];
|
||||
}
|
||||
unit->Data.Train.Ticks=0;
|
||||
} else {
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
}
|
||||
|
||||
nunit->Orders[0]=unit->NewOrder;
|
||||
|
||||
//
|
||||
// FIXME: Pending command uses any references?
|
||||
//
|
||||
if( nunit->Orders[0].Goal ) {
|
||||
if( nunit->Orders[0].Goal->Destroyed ) {
|
||||
DebugLevel0Fn("FIXME: you have found a bug, please fix it.\n");
|
||||
}
|
||||
RefsDebugCheck( !nunit->Orders[0].Goal->Refs );
|
||||
nunit->Orders[0].Goal->Refs++;
|
||||
}
|
||||
#else
|
||||
if ( --unit->Command.Data.Train.Count ) {
|
||||
int z;
|
||||
for( z = 0; z < unit->Command.Data.Train.Count ; z++ ) {
|
||||
|
@ -131,6 +157,7 @@ global void HandleActionTrain(Unit* unit)
|
|||
}
|
||||
nunit->Command.Data.Move.Goal->Refs++;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( IsSelected(unit) ) {
|
||||
UpdateButtonPanel();
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
//
|
||||
/**name action_upgradeto.c - The unit upgrading to new action. */
|
||||
//
|
||||
// (c) Copyright 1998,2000 by Lutz Sammer
|
||||
// (c) Copyright 1998,2000,2001 by Lutz Sammer
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
@ -49,12 +49,21 @@ global void HandleActionUpgradeTo(Unit* unit)
|
|||
DebugLevel3Fn(" %Zd\n",UnitNumber(unit));
|
||||
|
||||
player=unit->Player;
|
||||
#ifdef NEW_ORDERS
|
||||
type=unit->Data.UpgradeTo.What;
|
||||
stats=&type->Stats[player->Player];
|
||||
|
||||
// FIXME: Should count down here
|
||||
unit->Data.UpgradeTo.Ticks+=SpeedUpgrade;
|
||||
if( unit->Data.UpgradeTo.Ticks>=stats->Costs[TimeCost] ) {
|
||||
#else
|
||||
type=unit->Command.Data.UpgradeTo.What;
|
||||
stats=&type->Stats[player->Player];
|
||||
|
||||
// FIXME: Should count down here
|
||||
unit->Command.Data.UpgradeTo.Ticks+=SpeedUpgrade;
|
||||
if( unit->Command.Data.UpgradeTo.Ticks>=stats->Costs[TimeCost] ) {
|
||||
#endif
|
||||
|
||||
unit->HP+=stats->HitPoints-unit->Type->Stats[player->Player].HitPoints;
|
||||
// don't have such unit now
|
||||
|
@ -74,7 +83,11 @@ global void HandleActionUpgradeTo(Unit* unit)
|
|||
}
|
||||
unit->Reset=1;
|
||||
unit->Wait=1;
|
||||
#ifdef NEW_ORDERS
|
||||
unit->Orders[0].Action=UnitActionStill;
|
||||
#else
|
||||
unit->Command.Action=UnitActionStill;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Update possible changed buttons.
|
||||
|
|
1922
src/ai/old_ai.cpp
1922
src/ai/old_ai.cpp
File diff suppressed because it is too large
Load diff
|
@ -89,7 +89,8 @@ extern void CommandCancelResearch(Unit* unit);
|
|||
/// Prepare command demolish
|
||||
extern void CommandDemolish(Unit* unit,int x,int y,Unit* dest,int flush);
|
||||
/// Prepare command spellcast
|
||||
extern void CommandSpellCast(Unit* unit,int x,int y,Unit* dest,int spellid, int flush);
|
||||
extern void CommandSpellCast(Unit* unit,int x,int y,Unit* dest
|
||||
,int spellid, int flush);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Actions: in action_<name>.c
|
||||
|
|
|
@ -108,7 +108,8 @@ extern SpellType* SpellTypeById( int Id );
|
|||
extern int CanCastSpell( const Unit* unit, int SpellId );
|
||||
*/
|
||||
/// fire spell on target unit or place at x,y
|
||||
extern int SpellCast( int SpellId, Unit* unit, Unit* target, int x, int y );
|
||||
extern int SpellCast( const SpellType* SpellId, Unit* unit, Unit* target,
|
||||
int x, int y );
|
||||
|
||||
//@}
|
||||
|
||||
|
|
|
@ -162,6 +162,14 @@ struct _command_ {
|
|||
struct {
|
||||
unsigned Active; /// how much units are in the resource
|
||||
} Resource; /// generic resource
|
||||
struct {
|
||||
int Sum; /// HP for building
|
||||
int Add; /// added to sum
|
||||
int Val; /// counter
|
||||
int Sub; /// subtracted from counter
|
||||
int Cancel; /// Cancel construction
|
||||
Unit* Worker; /// Worker building the unit
|
||||
} Builded; // builded:
|
||||
} Data; /// data for action
|
||||
};
|
||||
#endif
|
||||
|
@ -306,6 +314,21 @@ struct _unit_ {
|
|||
struct _order_harvest_ {
|
||||
unsigned WoodToHarvest; /// Ticks for harvest
|
||||
} Harvest; /// Harvest action
|
||||
struct _order_research_ {
|
||||
unsigned Ticks; /// Ticks for research
|
||||
Upgrade* Upgrade; /// Upgrade researched
|
||||
} Research; /// Research action
|
||||
struct _order_upgradeto_ {
|
||||
unsigned Ticks; /// Ticks to complete
|
||||
UnitType* What; /// Unit upgraded to
|
||||
} UpgradeTo; /// Upgrade to action
|
||||
struct _order_traub_ {
|
||||
unsigned Ticks; /// Ticks to complete
|
||||
unsigned Count; /// Units in training queue
|
||||
// FIXME: vladi: later we should train more units or automatic
|
||||
#define MAX_UNIT_TRAIN 6
|
||||
UnitType* What[MAX_UNIT_TRAIN]; /// Unit trained
|
||||
} Train; /// Train units action
|
||||
} Data; /// Storage room for different commands
|
||||
|
||||
#else //}{-------------------------------------------
|
||||
|
@ -462,11 +485,11 @@ extern void DropOutNearest(Unit* unit,int x,int y,int addx,int addy);
|
|||
extern void DropOutAll(const Unit* unit);
|
||||
|
||||
/// FIXME: more docu
|
||||
extern int CanBuildHere(UnitType* type,unsigned x,unsigned y);
|
||||
extern int CanBuildHere(const UnitType* type,unsigned x,unsigned y);
|
||||
/// FIXME: more docu
|
||||
extern int CanBuildOn(int x,int y,int mask);
|
||||
/// FIXME: more docu
|
||||
extern int CanBuildUnitType(Unit* unit,UnitType* type,int x,int y);
|
||||
extern int CanBuildUnitType(const Unit* unit,const UnitType* type,int x,int y);
|
||||
|
||||
/// Find nearest gold mine
|
||||
extern Unit* FindGoldMine(const Unit*,int,int);
|
||||
|
|
|
@ -426,10 +426,12 @@ global int CanCastSpell( Unit* unit, int SpellId )
|
|||
** @return 0 if spell should/can continue or =! 0 to stop
|
||||
**
|
||||
*/
|
||||
global int SpellCast( int SpellId, Unit* unit, Unit* target, int x, int y )
|
||||
global int SpellCast( const SpellType* spell, Unit* unit, Unit* target,
|
||||
int x, int y )
|
||||
{
|
||||
int repeat = 0;
|
||||
const SpellType* spell = SpellTypeById( SpellId );
|
||||
int repeat;
|
||||
|
||||
repeat = 0;
|
||||
/*
|
||||
this does not work when no target unit
|
||||
DebugLevel0Fn("Spell cast: %d (%s), %s -> %s (%d,%d)",
|
||||
|
|
|
@ -1171,7 +1171,11 @@ global void UIHandleButtonUp(int b)
|
|||
// Other clicks.
|
||||
//
|
||||
if( NumSelected==1 ) {
|
||||
#ifdef NEW_ORDERS
|
||||
if( Selected[0]->Orders[0].Action==UnitActionBuilded ) {
|
||||
#else
|
||||
if( Selected[0]->Command.Action==UnitActionBuilded ) {
|
||||
#endif
|
||||
//if( Selected[0]->Constructed )
|
||||
PlayUnitSound(Selected[0],VoiceBuilding);
|
||||
} else if( Selected[0]->Burning ) {
|
||||
|
|
|
@ -1433,7 +1433,7 @@ global void DropOutAll(const Unit* source)
|
|||
** @param y Map Y position.
|
||||
** @return True if could build here, otherwise false.
|
||||
*/
|
||||
global int CanBuildHere(UnitType* type,unsigned x,unsigned y)
|
||||
global int CanBuildHere(const UnitType* type,unsigned x,unsigned y)
|
||||
{
|
||||
Unit* table[MAX_UNITS];
|
||||
int n;
|
||||
|
@ -1566,7 +1566,7 @@ global int CanBuildOn(int x,int y,int mask)
|
|||
/**
|
||||
** Can build unit-type on this point.
|
||||
*/
|
||||
global int CanBuildUnitType(Unit* unit,UnitType* type,int x,int y)
|
||||
global int CanBuildUnitType(const Unit* unit,const UnitType* type,int x,int y)
|
||||
{
|
||||
int w;
|
||||
int h;
|
||||
|
|
|
@ -376,7 +376,7 @@ local void DrawDecoration(Unit* unit,const UnitType* type,int x,int y)
|
|||
color=ColorRed;
|
||||
}
|
||||
if ( ShowHealthHorizontal ) {
|
||||
#ifdef DEBUG
|
||||
#if defined(DEBUG) && !defined(NEW_ORDERS)
|
||||
// Johns: I want to see fast moving.
|
||||
VideoFillRectangleClip(unit->Command.Data.Move.Fast
|
||||
? ColorBlack : ColorWhite
|
||||
|
|
Loading…
Add table
Reference in a new issue