Removed unused resource code
This commit is contained in:
parent
a2e50ec8c0
commit
a087d2bfe1
20 changed files with 80 additions and 898 deletions
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
/**@name action_build.cpp - The build building action. */
|
||||
//
|
||||
// (c) Copyright 1998-2005 by Lutz Sammer, Jimmy Salmon, and
|
||||
// (c) Copyright 1998-2007 by Lutz Sammer, Jimmy Salmon, and
|
||||
// Russell Smith
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
/**@name action_resource.cpp - The generic resource action. */
|
||||
//
|
||||
// (c) Copyright 2001-2005 by Crestez Leonard and Jimmy Salmon
|
||||
// (c) Copyright 2001-2007 by Crestez Leonard and Jimmy Salmon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -56,10 +56,6 @@
|
|||
#define SUB_UNREACHABLE_RESOURCE 31
|
||||
#define SUB_START_GATHERING 55
|
||||
#define SUB_GATHER_RESOURCE 60
|
||||
#define SUB_STOP_GATHERING 65
|
||||
#define SUB_MOVE_TO_DEPOT 70
|
||||
#define SUB_UNREACHABLE_DEPOT 100
|
||||
#define SUB_RETURN_RESOURCE 120
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
|
@ -105,13 +101,12 @@ static int StartGathering(CUnit *unit)
|
|||
CUnit *goal;
|
||||
ResourceInfo *resinfo;
|
||||
|
||||
Assert(!unit->IX && !unit->IY);
|
||||
resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
Assert(!unit->IX);
|
||||
Assert(!unit->IY);
|
||||
|
||||
goal = unit->Orders[0]->Goal;
|
||||
|
||||
//
|
||||
// Target is dead, stop getting resources.
|
||||
// Target is gone, stop getting resources.
|
||||
//
|
||||
if (!goal->IsVisibleAsGoal(unit->Player)) {
|
||||
goal->RefsDecrease();
|
||||
|
@ -129,7 +124,7 @@ static int StartGathering(CUnit *unit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// FIXME: 0 can happen, if to near placed by map designer.
|
||||
// FIXME: 0 can happen, if placed too near by map maker.
|
||||
Assert(MapDistanceBetweenUnits(unit, goal) <= 1);
|
||||
|
||||
//
|
||||
|
@ -147,9 +142,7 @@ static int StartGathering(CUnit *unit)
|
|||
if ((goal->Type->MaxOnBoard && goal->Data.Resource.Active >= goal->Type->MaxOnBoard) ||
|
||||
goal->Orders[0]->Action == UnitActionBuilt) {
|
||||
// FIXME: Determine somehow when the resource will be free to use
|
||||
// FIXME: Could we somehow find another resource? Think minerals
|
||||
// FIXME: We should add a flag for that, and a limited range.
|
||||
// FIXME: Think minerals in st*rcr*ft!!
|
||||
// FIXME: Could we somehow find another resource?
|
||||
// However the CPU usage is really low (no pathfinding stuff).
|
||||
unit->Wait = 10;
|
||||
return 0;
|
||||
|
@ -171,13 +164,11 @@ static int StartGathering(CUnit *unit)
|
|||
unit->Data.ResWorker.TimeToHarvest = resinfo->WaitAtResource /
|
||||
SpeedResourcesHarvest[resinfo->ResourceId];
|
||||
|
||||
unit->Data.ResWorker.DoneHarvesting = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
** Animate A unit that is harvesting
|
||||
** Animate a unit that is harvesting
|
||||
**
|
||||
** @param unit Unit to animate
|
||||
*/
|
||||
|
@ -196,10 +187,7 @@ static void AnimateActionHarvest(CUnit *unit)
|
|||
*/
|
||||
static void LoseResource(CUnit *unit, const CUnit *source)
|
||||
{
|
||||
CUnit *depot;
|
||||
ResourceInfo *resinfo;
|
||||
|
||||
resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
ResourceInfo *resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
|
||||
Assert((unit->Container && !resinfo->HarvestFromOutside) ||
|
||||
(!unit->Container && resinfo->HarvestFromOutside));
|
||||
|
@ -210,33 +198,9 @@ static void LoseResource(CUnit *unit, const CUnit *source)
|
|||
}
|
||||
|
||||
//
|
||||
// If we are loaded first search for a depot.
|
||||
//
|
||||
if (unit->ResourcesHeld && (depot = FindDeposit(unit, unit->X, unit->Y,
|
||||
1000, unit->CurrentResource))) {
|
||||
if (unit->Container) {
|
||||
DropOutNearest(unit, depot->X + depot->Type->TileWidth / 2,
|
||||
depot->Y + depot->Type->TileHeight / 2,
|
||||
source->Type->TileWidth, source->Type->TileHeight);
|
||||
}
|
||||
//
|
||||
// Remember were it mined, so it can look around for another resource.
|
||||
//
|
||||
unit->Orders[0]->Arg1.ResourcePos = (unit->X << 16) | unit->Y;
|
||||
unit->Orders[0]->Goal = depot;
|
||||
depot->RefsIncrease();
|
||||
NewResetPath(unit);
|
||||
unit->SubAction = SUB_MOVE_TO_DEPOT;
|
||||
unit->State = 0;
|
||||
DebugPrint("Sent unit %d to depot\n" _C_ unit->Slot);
|
||||
return;
|
||||
}
|
||||
//
|
||||
// No depot found, or harvester empty
|
||||
// Dump the unit outside and look for something to do.
|
||||
//
|
||||
if (unit->Container) {
|
||||
Assert(!resinfo->HarvestFromOutside);
|
||||
DropOutOnSide(unit, LookingW, source->Type->TileWidth,
|
||||
source->Type->TileHeight);
|
||||
}
|
||||
|
@ -248,7 +212,7 @@ static void LoseResource(CUnit *unit, const CUnit *source)
|
|||
unit->State = 0;
|
||||
unit->Orders[0]->Goal->RefsIncrease();
|
||||
} else {
|
||||
DebugPrint("Unit %d just sits around confused.\n" _C_ unit->Slot);
|
||||
DebugPrint("Unit %d did not find another resource.\n" _C_ unit->Slot);
|
||||
unit->Orders[0]->Action = UnitActionStill;
|
||||
unit->SubAction = 0;
|
||||
unit->State = 0;
|
||||
|
@ -259,19 +223,13 @@ static void LoseResource(CUnit *unit, const CUnit *source)
|
|||
** Gather the resource
|
||||
**
|
||||
** @param unit Pointer to unit.
|
||||
**
|
||||
** @return non-zero if ready, otherwise zero.
|
||||
*/
|
||||
static int GatherResource(CUnit *unit)
|
||||
static void GatherResource(CUnit *unit)
|
||||
{
|
||||
CUnit *source;
|
||||
CUnit *uins;
|
||||
ResourceInfo *resinfo;
|
||||
int i;
|
||||
int addload;
|
||||
|
||||
resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
source = 0;
|
||||
CUnit *source = NoUnitP;
|
||||
ResourceInfo *resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
int addload = 1;
|
||||
int visible = 0;
|
||||
|
||||
if (resinfo->HarvestFromOutside) {
|
||||
AnimateActionHarvest(unit);
|
||||
|
@ -281,13 +239,7 @@ static int GatherResource(CUnit *unit)
|
|||
|
||||
unit->Data.ResWorker.TimeToHarvest--;
|
||||
|
||||
if (unit->Data.ResWorker.DoneHarvesting) {
|
||||
Assert(resinfo->HarvestFromOutside);
|
||||
return !unit->Anim.Unbreakable;
|
||||
}
|
||||
|
||||
while (!unit->Data.ResWorker.DoneHarvesting &&
|
||||
unit->Data.ResWorker.TimeToHarvest < 0) {
|
||||
while (unit->Data.ResWorker.TimeToHarvest < 0) {
|
||||
unit->Data.ResWorker.TimeToHarvest += resinfo->WaitAtResource /
|
||||
SpeedResourcesHarvest[resinfo->ResourceId];
|
||||
|
||||
|
@ -297,11 +249,7 @@ static int GatherResource(CUnit *unit)
|
|||
if (resinfo->ResourceStep) {
|
||||
addload = resinfo->ResourceStep;
|
||||
} else {
|
||||
addload = resinfo->ResourceCapacity;
|
||||
}
|
||||
// Make sure we don't bite more than we can chew.
|
||||
if (unit->ResourcesHeld + addload > resinfo->ResourceCapacity) {
|
||||
addload = resinfo->ResourceCapacity - unit->ResourcesHeld;
|
||||
addload = source->ResourcesHeld;
|
||||
}
|
||||
|
||||
if (resinfo->HarvestFromOutside) {
|
||||
|
@ -309,260 +257,50 @@ static int GatherResource(CUnit *unit)
|
|||
} else {
|
||||
source = unit->Container;
|
||||
}
|
||||
|
||||
Assert(source);
|
||||
Assert(source->ResourcesHeld <= 655350);
|
||||
|
||||
//
|
||||
// Target is not dead, getting resources.
|
||||
//
|
||||
if (source->IsVisibleAsGoal(unit->Player)) {
|
||||
// Don't load more that there is.
|
||||
visible = source->IsVisibleAsGoal(unit->Player);
|
||||
if (visible) {
|
||||
// Don't load more than there is.
|
||||
if (addload > source->ResourcesHeld) {
|
||||
addload = source->ResourcesHeld;
|
||||
}
|
||||
|
||||
unit->ResourcesHeld += addload;
|
||||
source->ResourcesHeld -= addload;
|
||||
}
|
||||
|
||||
//
|
||||
// End of resource: destroy the resource.
|
||||
// FIXME: implement depleted resources.
|
||||
//
|
||||
if ((!source->IsVisibleAsGoal(unit->Player)) || (source->ResourcesHeld == 0)) {
|
||||
if (unit->Anim.Unbreakable) {
|
||||
return 0;
|
||||
if (!visible || source->ResourcesHeld == 0) {
|
||||
if (resinfo->HarvestFromOutside && unit->Anim.Unbreakable) {
|
||||
// Continue until the animation is breakable
|
||||
unit->Data.ResWorker.TimeToHarvest = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
DebugPrint("Resource is destroyed for unit %d\n" _C_ unit->Slot);
|
||||
uins = source->UnitInside;
|
||||
|
||||
//
|
||||
// Improved version of DropOutAll that makes workers go to the depot.
|
||||
// Improved version of DropOutAll.
|
||||
//
|
||||
LoseResource(unit,source);
|
||||
for (i = source->InsideCount; i; --i, uins = uins->NextContained) {
|
||||
LoseResource(unit, source);
|
||||
CUnit *uins = source->UnitInside;
|
||||
for (int i = source->InsideCount; i; --i, uins = uins->NextContained) {
|
||||
if (uins->Orders[0]->Action == UnitActionResource) {
|
||||
LoseResource(uins,source);
|
||||
LoseResource(uins, source);
|
||||
}
|
||||
}
|
||||
|
||||
// Don't destroy the resource twice.
|
||||
// This only happens when it's empty.
|
||||
if (source->IsVisibleAsGoal(unit->Player)) {
|
||||
if (visible) {
|
||||
LetUnitDie(source);
|
||||
// FIXME: make the workers inside look for a new resource.
|
||||
}
|
||||
source = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (resinfo->HarvestFromOutside) {
|
||||
if ((unit->ResourcesHeld == resinfo->ResourceCapacity) || (source == NULL)) {
|
||||
// Mark as complete.
|
||||
unit->Data.ResWorker.DoneHarvesting = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!resinfo->HarvestFromOutside) {
|
||||
return unit->ResourcesHeld == resinfo->ResourceCapacity && source;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
** Stop gathering from the resource, go home.
|
||||
**
|
||||
** @param unit Poiner to unit.
|
||||
**
|
||||
** @return TRUE if ready, otherwise FALSE.
|
||||
*/
|
||||
static int StopGathering(CUnit *unit)
|
||||
{
|
||||
CUnit *depot;
|
||||
CUnit *source;
|
||||
ResourceInfo *resinfo;
|
||||
|
||||
resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
|
||||
if (resinfo->HarvestFromOutside) {
|
||||
source = unit->Orders[0]->Goal;
|
||||
source->RefsDecrease();
|
||||
unit->Orders[0]->Goal = NoUnitP;
|
||||
} else {
|
||||
source = unit->Container;
|
||||
}
|
||||
source->Data.Resource.Active--;
|
||||
Assert(source->Data.Resource.Active >= 0);
|
||||
|
||||
|
||||
// Store resource position.
|
||||
// FIXME: is this the best way?
|
||||
unit->Orders[0]->Arg1.ResourcePos = (unit->X << 16) | unit->Y;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (!unit->ResourcesHeld) {
|
||||
DebugPrint("Unit %d is empty???\n" _C_ unit->Slot);
|
||||
}
|
||||
#endif
|
||||
// Find and send to resource deposit.
|
||||
if (!(depot = FindDeposit(unit, unit->X, unit->Y, 1000, unit->CurrentResource)) ||
|
||||
!unit->ResourcesHeld) {
|
||||
if (!resinfo->HarvestFromOutside) {
|
||||
Assert(unit->Container);
|
||||
DropOutOnSide(unit, LookingW, source->Type->TileWidth,
|
||||
source->Type->TileHeight);
|
||||
}
|
||||
DebugPrint("Can't find a resource deposit for unit %d.\n" _C_ unit->Slot);
|
||||
unit->Orders[0]->Action = UnitActionStill;
|
||||
unit->Orders[0]->Goal = NoUnitP;
|
||||
unit->SubAction = 0;
|
||||
// should return 0, done below!
|
||||
} else {
|
||||
if (!resinfo->HarvestFromOutside) {
|
||||
Assert(unit->Container);
|
||||
DropOutNearest(unit, depot->X + depot->Type->TileWidth / 2,
|
||||
depot->Y + depot->Type->TileHeight / 2,
|
||||
source->Type->TileWidth, source->Type->TileHeight);
|
||||
}
|
||||
unit->Orders[0]->Goal = depot;
|
||||
depot->RefsIncrease();
|
||||
unit->Orders[0]->Range = 1;
|
||||
unit->Orders[0]->X = unit->Orders[0]->Y = -1;
|
||||
unit->SubAction = SUB_MOVE_TO_DEPOT;
|
||||
NewResetPath(unit);
|
||||
}
|
||||
|
||||
if (IsOnlySelected(unit)) {
|
||||
SelectedUnitChanged();
|
||||
}
|
||||
|
||||
return unit->Orders[0]->Action != UnitActionStill;
|
||||
}
|
||||
|
||||
/**
|
||||
** Move to resource depot
|
||||
**
|
||||
** @param unit Pointer to unit.
|
||||
**
|
||||
** @return TRUE if reached, otherwise FALSE.
|
||||
*/
|
||||
static int MoveToDepot(CUnit *unit)
|
||||
{
|
||||
CUnit *goal;
|
||||
ResourceInfo *resinfo;
|
||||
|
||||
resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
|
||||
goal = unit->Orders[0]->Goal;
|
||||
Assert(goal);
|
||||
|
||||
switch (DoActionMove(unit)) { // reached end-point?
|
||||
case PF_UNREACHABLE:
|
||||
return -1;
|
||||
case PF_REACHED:
|
||||
break;
|
||||
default:
|
||||
if (unit->Anim.Unbreakable || goal->IsVisibleAsGoal(unit->Player)) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Target is dead, stop getting resources.
|
||||
//
|
||||
if (!goal->IsVisibleAsGoal(unit->Player)) {
|
||||
DebugPrint("Destroyed depot\n");
|
||||
goal->RefsDecrease();
|
||||
unit->Orders[0]->Goal = NoUnitP;
|
||||
// FIXME: perhaps we should choose an alternative
|
||||
unit->Orders[0]->Action = UnitActionStill;
|
||||
unit->SubAction = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// If resource depot is still under construction, wait!
|
||||
//
|
||||
if (goal->Orders[0]->Action == UnitActionBuilt) {
|
||||
unit->Wait = 10;
|
||||
return 0;
|
||||
}
|
||||
|
||||
goal->RefsDecrease();
|
||||
unit->Orders[0]->Goal = NoUnitP;
|
||||
|
||||
//
|
||||
// Place unit inside the depot
|
||||
//
|
||||
unit->Remove(goal);
|
||||
unit->Anim.CurrAnim = NULL;
|
||||
|
||||
//
|
||||
// Update resource.
|
||||
//
|
||||
unit->Player->Resources[resinfo->FinalResource] +=
|
||||
(unit->ResourcesHeld * unit->Player->Incomes[resinfo->FinalResource]) / 100;
|
||||
unit->Player->TotalResources[resinfo->FinalResource] +=
|
||||
(unit->ResourcesHeld * unit->Player->Incomes[resinfo->FinalResource]) / 100;
|
||||
unit->ResourcesHeld = 0;
|
||||
|
||||
unit->Wait = resinfo->WaitAtDepot / SpeedResourcesReturn[resinfo->ResourceId];
|
||||
if (unit->Wait) {
|
||||
unit->Wait--;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
** Wait in depot, for the resources stored.
|
||||
**
|
||||
** @param unit Pointer to unit.
|
||||
**
|
||||
** @return TRUE if ready, otherwise FALSE.
|
||||
*/
|
||||
static int WaitInDepot(CUnit *unit)
|
||||
{
|
||||
const CUnit *depot;
|
||||
CUnit *goal;
|
||||
ResourceInfo *resinfo;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
resinfo = unit->Type->ResInfo[unit->CurrentResource];
|
||||
|
||||
depot = ResourceDepositOnMap(unit->X, unit->Y, resinfo->ResourceId);
|
||||
Assert(depot);
|
||||
// Could be destroyed, but then we couldn't be in?
|
||||
|
||||
if (unit->Orders[0]->Arg1.ResourcePos == -1) {
|
||||
x = unit->X;
|
||||
y = unit->Y;
|
||||
} else {
|
||||
x = unit->Orders[0]->Arg1.ResourcePos >> 16;
|
||||
y = unit->Orders[0]->Arg1.ResourcePos & 0xFFFF;
|
||||
}
|
||||
// Range hardcoded. don't stray too far though
|
||||
if ((goal = UnitFindResource(unit, x, y, 10, unit->CurrentResource))) {
|
||||
DropOutNearest(unit, goal->X + goal->Type->TileWidth / 2,
|
||||
goal->Y + goal->Type->TileHeight / 2,
|
||||
depot->Type->TileWidth, depot->Type->TileHeight);
|
||||
unit->Orders[0]->Goal = goal;
|
||||
goal->RefsIncrease();
|
||||
unit->Orders[0]->Range = 1;
|
||||
unit->Orders[0]->X = unit->Orders[0]->Y = -1;
|
||||
} else {
|
||||
DebugPrint("Unit %d Resource gone. Sit and play dumb.\n" _C_ unit->Slot);
|
||||
DropOutOnSide(unit, LookingW, depot->Type->TileWidth, depot->Type->TileHeight);
|
||||
unit->Orders[0]->Action = UnitActionStill;
|
||||
unit->SubAction = 0;
|
||||
}
|
||||
|
||||
return unit->Orders[0]->Action != UnitActionStill;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -580,25 +318,18 @@ void ResourceGiveUp(CUnit *unit)
|
|||
unit->Orders[0]->Init();
|
||||
unit->Orders[0]->Action = UnitActionStill;
|
||||
unit->SubAction = 0;
|
||||
if (unit->CurrentResource &&
|
||||
unit->Type->ResInfo[unit->CurrentResource]->LoseResources &&
|
||||
unit->ResourcesHeld < unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) {
|
||||
unit->ResourcesHeld = 0;
|
||||
unit->CurrentResource = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Control the unit action: getting a resource.
|
||||
**
|
||||
** This the generic function for oil, gold, ...
|
||||
** This is the generic function for harvesting resources
|
||||
**
|
||||
** @param unit Pointer to unit.
|
||||
*/
|
||||
void HandleActionResource(CUnit *unit)
|
||||
{
|
||||
int ret;
|
||||
int newres;
|
||||
|
||||
if (unit->Wait) {
|
||||
// FIXME: show idle animation while we wait?
|
||||
|
@ -608,20 +339,11 @@ void HandleActionResource(CUnit *unit)
|
|||
|
||||
// Let's start mining.
|
||||
if (unit->SubAction == SUB_START_RESOURCE) {
|
||||
if (unit->Orders[0]->Goal) {
|
||||
newres = unit->Orders[0]->Goal->Type->GivesResource;
|
||||
} else {
|
||||
newres = WoodCost;
|
||||
}
|
||||
if (newres != unit->CurrentResource) {
|
||||
// Drop other resources.
|
||||
unit->ResourcesHeld = 0;
|
||||
}
|
||||
if ((unit->CurrentResource = newres)) {
|
||||
unit->CurrentResource = unit->Orders[0]->Goal->Type->GivesResource;
|
||||
if (unit->CurrentResource) {
|
||||
NewResetPath(unit);
|
||||
unit->SubAction = SUB_MOVE_TO_RESOURCE;
|
||||
} else {
|
||||
unit->ResourcesHeld = 0;
|
||||
ResourceGiveUp(unit);
|
||||
return;
|
||||
}
|
||||
|
@ -664,56 +386,7 @@ void HandleActionResource(CUnit *unit)
|
|||
|
||||
// Gather the resource.
|
||||
if (unit->SubAction == SUB_GATHER_RESOURCE) {
|
||||
if (GatherResource(unit)) {
|
||||
unit->SubAction = SUB_STOP_GATHERING;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Stop gathering the resource.
|
||||
if (unit->SubAction == SUB_STOP_GATHERING) {
|
||||
if (StopGathering(unit)) {
|
||||
unit->SubAction = SUB_MOVE_TO_DEPOT;
|
||||
}
|
||||
}
|
||||
|
||||
// Move back home.
|
||||
if (unit->SubAction >= SUB_MOVE_TO_DEPOT &&
|
||||
unit->SubAction < SUB_UNREACHABLE_DEPOT) {
|
||||
// -1 failure, 0 not yet reached, 1 reached
|
||||
if ((ret = MoveToDepot(unit))) {
|
||||
if (ret == -1) {
|
||||
// Can't Reach
|
||||
unit->SubAction++;
|
||||
unit->Wait = 10;
|
||||
} else {
|
||||
unit->SubAction = SUB_RETURN_RESOURCE;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Depot seems to be unreachable
|
||||
if (unit->SubAction == SUB_UNREACHABLE_DEPOT) {
|
||||
ResourceGiveUp(unit);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unload resources at the depot.
|
||||
if (unit->SubAction == SUB_RETURN_RESOURCE) {
|
||||
if (WaitInDepot(unit)) {
|
||||
unit->SubAction = SUB_START_RESOURCE;
|
||||
//
|
||||
// It's posible, though very rare that the unit's goal blows up
|
||||
// this cycle, but after this unit. Thus, next frame the unit
|
||||
// will start mining a destroyed site. If, on the otherhand we
|
||||
// are already in SUB_MOVE_TO_RESOURCE then we can handle it.
|
||||
// So, we pass through SUB_START_RESOURCE the very instant it
|
||||
// goes out of the depot.
|
||||
//
|
||||
HandleActionResource(unit);
|
||||
}
|
||||
GatherResource(unit);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
// ____ _ __
|
||||
// / __ )____ _____ | | / /___ ___________
|
||||
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
|
||||
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
|
||||
// /_____/\____/____/ |__/|__/\__,_/_/ /____/
|
||||
//
|
||||
// A futuristic real-time strategy game.
|
||||
// This file is part of Bos Wars.
|
||||
//
|
||||
/**@name action_returngoods.cpp - The return goods action. */
|
||||
//
|
||||
// (c) Copyright 1998-2005 by Lutz Sammer and Jimmy Salmon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
//@{
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Include
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stratagus.h"
|
||||
#include "unittype.h"
|
||||
#include "player.h"
|
||||
#include "unit.h"
|
||||
#include "actions.h"
|
||||
#include "pathfinder.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Return goods to gold/wood deposit.
|
||||
**
|
||||
** @param unit pointer to unit.
|
||||
**
|
||||
** @todo FIXME: move this into action_resource?
|
||||
*/
|
||||
void HandleActionReturnGoods(CUnit *unit)
|
||||
{
|
||||
Assert(unit->Type->Harvester);
|
||||
|
||||
// Select target to return goods.
|
||||
if (!unit->CurrentResource || unit->ResourcesHeld == 0 ||
|
||||
(unit->ResourcesHeld != unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity &&
|
||||
unit->Type->ResInfo[unit->CurrentResource]->LoseResources)) {
|
||||
DebugPrint("Unit can't return resources, it doesn't carry any.\n");
|
||||
unit->Player->Notify(NotifyYellow, unit->X, unit->Y, _("No Resources to Return."));
|
||||
|
||||
if (unit->Orders[0]->Goal) { // Depot (if not destroyed)
|
||||
unit->Orders[0]->Goal->RefsDecrease();
|
||||
unit->Orders[0]->Goal = NULL;
|
||||
}
|
||||
unit->Orders[0]->Init();
|
||||
unit->Orders[0]->Action = UnitActionStill;
|
||||
return;
|
||||
}
|
||||
|
||||
// If depot was destroyed search for another one.
|
||||
if (!unit->Orders[0]->Goal) {
|
||||
CUnit *destu;
|
||||
|
||||
if (!(destu = FindDeposit(unit, unit->X, unit->Y, 1000,
|
||||
unit->CurrentResource))) {
|
||||
unit->Orders[0]->Init();
|
||||
unit->Orders[0]->Action = UnitActionStill;
|
||||
return;
|
||||
}
|
||||
unit->Orders[0]->Goal = destu;
|
||||
destu->RefsIncrease();
|
||||
}
|
||||
|
||||
unit->Orders[0]->Action = UnitActionResource;
|
||||
// Somewhere on the way the loaded worker could have change Arg1
|
||||
// Bummer, go get the closest resource to the depot
|
||||
unit->Orders[0]->Arg1.ResourcePos = -1;
|
||||
NewResetPath(unit);
|
||||
unit->SubAction = 70; // FIXME : Define value.
|
||||
}
|
||||
|
||||
//@}
|
|
@ -254,7 +254,7 @@ static void HandleActionNone(CUnit *unit)
|
|||
**
|
||||
** @note can move function into unit structure.
|
||||
*/
|
||||
static void (*HandleActionTable[256])(CUnit *) = {
|
||||
static void (*HandleActionTable[])(CUnit *) = {
|
||||
HandleActionNone,
|
||||
HandleActionStill,
|
||||
HandleActionStandGround,
|
||||
|
@ -272,7 +272,6 @@ static void (*HandleActionTable[256])(CUnit *) = {
|
|||
HandleActionBuild,
|
||||
HandleActionRepair,
|
||||
HandleActionResource,
|
||||
HandleActionReturnGoods,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -397,12 +396,6 @@ static void HandleUnitAction(CUnit *unit)
|
|||
Assert(!(unit->Orders[0]->Action == UnitActionStill && !unit->SubAction));
|
||||
unit->Orders[0]->Goal->RefsDecrease();
|
||||
}
|
||||
if (unit->CurrentResource) {
|
||||
if (unit->Type->ResInfo[unit->CurrentResource]->LoseResources &&
|
||||
unit->ResourcesHeld < unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) {
|
||||
unit->ResourcesHeld = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((unit->Orders[0]->Action == UnitActionBuild && !unit->Type->BuilderOutside && unit->SubAction == 40) ||
|
||||
(unit->Orders[0]->Action == UnitActionRepair && unit->SubAction == 2)) {
|
||||
|
|
|
@ -724,48 +724,6 @@ void CommandResource(CUnit *unit, CUnit *dest, int flush)
|
|||
ClearSavedAction(unit);
|
||||
}
|
||||
|
||||
/**
|
||||
** Let unit returning goods.
|
||||
**
|
||||
** @param unit pointer to unit.
|
||||
** @param goal bring goods to this depot.
|
||||
** @param flush if true, flush command queue.
|
||||
*/
|
||||
void CommandReturnGoods(CUnit *unit, CUnit *goal, int flush)
|
||||
{
|
||||
COrder *order;
|
||||
|
||||
//
|
||||
// Check if unit is still valid and Goal still alive? (NETWORK!)
|
||||
//
|
||||
if (!unit->Removed && unit->Orders[0]->Action != UnitActionDie) {
|
||||
if (!unit->Type->Building && !unit->Type->Harvester && !unit->ResourcesHeld) {
|
||||
ClearSavedAction(unit);
|
||||
return;
|
||||
}
|
||||
|
||||
if (unit->Type->Building) {
|
||||
// FIXME: should find a better way for pending orders.
|
||||
order = &unit->NewOrder;
|
||||
ReleaseOrder(order);
|
||||
} else if (!(order = GetNextOrder(unit, flush))) {
|
||||
return;
|
||||
}
|
||||
order->Init();
|
||||
|
||||
order->Action = UnitActionReturnGoods;
|
||||
//
|
||||
// Destination could be killed. NETWORK!
|
||||
//
|
||||
if (goal && !goal->Destroyed) {
|
||||
order->Goal = goal;
|
||||
goal->RefsIncrease();
|
||||
}
|
||||
order->Range = 1;
|
||||
}
|
||||
ClearSavedAction(unit);
|
||||
}
|
||||
|
||||
/**
|
||||
** Building starts training a unit.
|
||||
**
|
||||
|
@ -878,24 +836,6 @@ void CommandCancelTraining(CUnit *unit, int slot, const CUnitType *type)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Immediate transforming unit into type.
|
||||
**
|
||||
** @param unit pointer to unit.
|
||||
** @param type upgrade to type
|
||||
*/
|
||||
void CommandTransformIntoType(CUnit *unit, CUnitType *type)
|
||||
{
|
||||
COrder *order;
|
||||
|
||||
Assert(unit->CriticalOrder.Action == UnitActionStill);
|
||||
order = &unit->CriticalOrder;
|
||||
order->Init();
|
||||
|
||||
order->Action = UnitActionTransformInto;
|
||||
order->Type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
** Cast a spell at position or unit.
|
||||
**
|
||||
|
|
|
@ -520,7 +520,6 @@ static int AiAssignHarvester(CUnit *unit, int resource)
|
|||
*/
|
||||
static void AiCollectResources(void)
|
||||
{
|
||||
CUnit *units_with_resource[UnitMax][MaxCosts]; // Worker with resource
|
||||
CUnit *units_assigned[UnitMax][MaxCosts]; // Worker assigned to resource
|
||||
CUnit *units_unassigned[UnitMax][MaxCosts]; // Unassigned workers
|
||||
int num_units_with_resource[MaxCosts];
|
||||
|
@ -586,16 +585,6 @@ static void AiCollectResources(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Send workers with resources back home.
|
||||
//
|
||||
if (unit->ResourcesHeld && c) {
|
||||
units_with_resource[num_units_with_resource[c]++][c] = unit;
|
||||
CommandReturnGoods(unit, 0, FlushCommands);
|
||||
total_harvester++;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Look what the unit can do
|
||||
//
|
||||
|
|
|
@ -103,9 +103,6 @@ extern void CommandBuildBuilding(CUnit *, int x, int y,
|
|||
extern void CommandDismiss(CUnit *unit);
|
||||
/// Prepare command resource
|
||||
extern void CommandResource(CUnit *unit, CUnit *dest,
|
||||
int flush);
|
||||
/// Prepare command return
|
||||
extern void CommandReturnGoods(CUnit *unit, CUnit *goal,
|
||||
int flush);
|
||||
/// Prepare command train
|
||||
extern void CommandTrainUnit(CUnit *unit, CUnitType *what,
|
||||
|
@ -113,8 +110,6 @@ extern void CommandTrainUnit(CUnit *unit, CUnitType *what,
|
|||
/// Prepare command cancel training
|
||||
extern void CommandCancelTraining(CUnit *unit, int slot,
|
||||
const CUnitType *type);
|
||||
/// immediate transforming into type.
|
||||
extern void CommandTransformIntoType(CUnit *unit, CUnitType *type);
|
||||
/// Prepare command spellcast
|
||||
extern void CommandSpellCast(CUnit *unit, int x, int y,
|
||||
CUnit *dest, SpellType *spell, int flush);
|
||||
|
@ -159,8 +154,6 @@ extern void HandleActionBoard(CUnit *unit);
|
|||
extern void HandleActionUnload(CUnit *unit);
|
||||
/// Handle command resource
|
||||
extern void HandleActionResource(CUnit *unit);
|
||||
/// Handle command return
|
||||
extern void HandleActionReturnGoods(CUnit *unit);
|
||||
/// Handle command die
|
||||
extern void HandleActionDie(CUnit *unit);
|
||||
/// Handle command build
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
/**@name commands.h - The commands header file. */
|
||||
//
|
||||
// (c) Copyright 1998-2006 by Lutz Sammer and Jimmy Salmon
|
||||
// (c) Copyright 1998-2007 by Lutz Sammer and Jimmy Salmon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -115,9 +115,6 @@ extern void SendCommandBuildBuilding(CUnit *unit, int x, int y,
|
|||
extern void SendCommandDismiss(CUnit *unit);
|
||||
/// Send harvest command
|
||||
extern void SendCommandResource(CUnit *unit, CUnit *dest,
|
||||
int flush);
|
||||
/// Send return goods command
|
||||
extern void SendCommandReturnGoods(CUnit *unit, CUnit *dest,
|
||||
int flush);
|
||||
/// Send train command
|
||||
extern void SendCommandTrainUnit(CUnit *unit,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
/**@name interface.h - The user interface header file. */
|
||||
//
|
||||
// (c) Copyright 1998-2006 by Lutz Sammer and Jimmy Salmon
|
||||
// (c) Copyright 1998-2007 by Lutz Sammer and Jimmy Salmon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -64,7 +64,6 @@ enum ButtonCmd {
|
|||
ButtonButton, /// choose other button set
|
||||
ButtonTrain, /// order train
|
||||
ButtonStandGround, /// order stand ground
|
||||
ButtonReturn, /// order return goods
|
||||
ButtonCancel, /// cancel
|
||||
ButtonCancelTrain, /// cancel training
|
||||
ButtonCancelBuild, /// cancel building
|
||||
|
|
|
@ -406,8 +406,6 @@ typedef enum _unit_action_ {
|
|||
|
||||
UnitActionRepair, /// unit repairing
|
||||
UnitActionResource, /// unit harvesting resources
|
||||
UnitActionReturnGoods, /// unit returning any resource
|
||||
UnitActionTransformInto /// unit transform into type.
|
||||
} UnitAction;
|
||||
|
||||
/**
|
||||
|
@ -449,7 +447,6 @@ public:
|
|||
int X; /// X position for patroling.
|
||||
int Y; /// Y position for patroling.
|
||||
} Patrol; /// position.
|
||||
int ResourcePos; /// ResourcePos == (X<<16 | Y).
|
||||
SpellType *Spell; /// spell when casting.
|
||||
} Arg1; /// Extra command argument.
|
||||
};
|
||||
|
@ -674,7 +671,6 @@ public:
|
|||
} Resource; /// Resource still
|
||||
struct _order_resource_worker_ {
|
||||
int TimeToHarvest; /// how much time until we harvest some more.
|
||||
unsigned DoneHarvesting:1; /// Harvesting done, wait for action to break.
|
||||
} ResWorker; /// Worker harvesting
|
||||
struct _order_repair_ {
|
||||
int Cycles; /// Cycles unit has been repairing for
|
||||
|
@ -875,8 +871,6 @@ extern CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType *type, int x,
|
|||
|
||||
/// Find resource
|
||||
extern CUnit *UnitFindResource(const CUnit *unit, int x, int y, int range, int resource);
|
||||
/// Find nearest deposit
|
||||
extern CUnit *FindDeposit(const CUnit *unit, int x, int y, int range, int resource);
|
||||
/// Find the next idle worker
|
||||
extern CUnit *FindIdleWorker(const CPlayer *player, const CUnit *last);
|
||||
|
||||
|
|
|
@ -442,25 +442,9 @@
|
|||
** it does some sort of animation and gains ResourceStep
|
||||
** resources. You can stop after any number of steps.
|
||||
** when the quantity in the harvester reaches the maximum
|
||||
** (ResourceCapacity) it will return home. I this is 0 then
|
||||
** (ResourceCapacity) it will return home. If this is 0 then
|
||||
** it's considered infinity, and ResourceCapacity will now
|
||||
** be the limit.
|
||||
**
|
||||
** ResourceInfo::ResourceCapacity
|
||||
**
|
||||
** Maximum amount of resources a harvester can carry. The
|
||||
** actual amount can be modified while unloading.
|
||||
**
|
||||
** ResourceInfo::LoseResources
|
||||
**
|
||||
** Special lossy behaviour for loaded harvesters. Harvesters
|
||||
** with loads other than 0 and ResourceCapacity will lose their
|
||||
** cargo on any new order.
|
||||
**
|
||||
** ResourceInfo::WaitAtDepot
|
||||
**
|
||||
** Cycles the unit waits while inside the depot to unload.
|
||||
**
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
@ -504,8 +488,8 @@ public:
|
|||
class ResourceInfo {
|
||||
public:
|
||||
ResourceInfo() : HarvestFromOutside(0), WaitAtResource(0), ResourceStep(0),
|
||||
ResourceCapacity(0), WaitAtDepot(0), ResourceId(0), FinalResource(0),
|
||||
LoseResources(0), SpriteWhenLoaded(NULL), SpriteWhenEmpty(NULL)
|
||||
ResourceId(0), FinalResource(0),
|
||||
SpriteWhenLoaded(NULL), SpriteWhenEmpty(NULL)
|
||||
{}
|
||||
|
||||
std::string FileWhenLoaded; /// Change the graphic when the unit is loaded.
|
||||
|
@ -513,11 +497,8 @@ public:
|
|||
unsigned HarvestFromOutside; /// Unit harvests without entering the building.
|
||||
unsigned WaitAtResource; /// Cycles the unit waits while mining.
|
||||
unsigned ResourceStep; /// Resources the unit gains per mining cycle.
|
||||
int ResourceCapacity; /// Max amount of resources to carry.
|
||||
unsigned WaitAtDepot; /// Cycles the unit waits while returning.
|
||||
unsigned ResourceId; /// Id of the resource harvested. Redundant.
|
||||
unsigned FinalResource; /// Convert resource when delivered.
|
||||
unsigned LoseResources; /// The unit will lose it's resource when distracted.
|
||||
// Runtime info:
|
||||
CPlayerColorGraphic *SpriteWhenLoaded; /// The graphic corresponding to FileWhenLoaded.
|
||||
CPlayerColorGraphic *SpriteWhenEmpty; /// The graphic corresponding to FileWhenEmpty
|
||||
|
|
|
@ -839,8 +839,6 @@ static void DoNextReplay(void)
|
|||
SendCommandDismiss(UnitSlots[unit]);
|
||||
} else if (!strcmp(action, "resource")) {
|
||||
SendCommandResource(UnitSlots[unit], dunit, flags);
|
||||
} else if (!strcmp(action, "return")) {
|
||||
SendCommandReturnGoods(UnitSlots[unit], dunit, flags);
|
||||
} else if (!strcmp(action, "train")) {
|
||||
SendCommandTrainUnit(UnitSlots[unit], UnitTypeByIdent(val), flags);
|
||||
} else if (!strcmp(action, "cancel-train")) {
|
||||
|
@ -1203,23 +1201,6 @@ void SendCommandResource(CUnit *unit, CUnit *dest, int flush)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Send command: Unit return goods.
|
||||
**
|
||||
** @param unit pointer to unit.
|
||||
** @param goal pointer to destination of the goods. (NULL=search best)
|
||||
** @param flush Flag flush all pending commands.
|
||||
*/
|
||||
void SendCommandReturnGoods(CUnit *unit, CUnit *goal, int flush)
|
||||
{
|
||||
if (!IsNetworkGame()) {
|
||||
CommandLog("return", unit, flush, -1, -1, goal, NULL, -1);
|
||||
CommandReturnGoods(unit, goal, flush);
|
||||
} else {
|
||||
NetworkSendCommand(MessageCommandReturn, unit, 0, 0, goal, 0, flush);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Send command: Building/unit train new unit.
|
||||
**
|
||||
|
@ -1502,15 +1483,6 @@ void ParseCommand(unsigned char msgnr, UnitRef unum,
|
|||
CommandLog("resource", unit, status, -1, -1, dest, NULL, -1);
|
||||
CommandResource(unit, dest, status);
|
||||
break;
|
||||
case MessageCommandReturn:
|
||||
dest = NoUnitP;
|
||||
if (dstnr != (unsigned short)0xFFFF) {
|
||||
dest = UnitSlots[dstnr];
|
||||
Assert(dest && dest->Type);
|
||||
}
|
||||
CommandLog("return", unit, status, -1, -1, dest, NULL, -1);
|
||||
CommandReturnGoods(unit, dest, status);
|
||||
break;
|
||||
case MessageCommandTrain:
|
||||
CommandLog("train", unit, status, -1, -1, NoUnitP,
|
||||
UnitTypes[dstnr]->Ident.c_str(), -1);
|
||||
|
|
|
@ -423,28 +423,6 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="action\action_returngoods.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="action\action_spellcast.cpp"
|
||||
>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
/**@name botpanel.cpp - The bottom panel. */
|
||||
//
|
||||
// (c) Copyright 1999-2006 by Lutz Sammer, Vladi Belperchinov-Shabanski,
|
||||
// (c) Copyright 1999-2007 by Lutz Sammer, Vladi Belperchinov-Shabanski,
|
||||
// and Jimmy Salmon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
|
@ -219,7 +219,6 @@ static int GetButtonStatus(const ButtonAction *button)
|
|||
action = UnitActionPatrol;
|
||||
break;
|
||||
case ButtonHarvest:
|
||||
case ButtonReturn:
|
||||
action = UnitActionResource;
|
||||
break;
|
||||
default:
|
||||
|
@ -420,6 +419,7 @@ static bool IsButtonAllowed(const CUnit *unit, const ButtonAction *buttonaction)
|
|||
case ButtonStandGround:
|
||||
case ButtonButton:
|
||||
case ButtonMove:
|
||||
case ButtonHarvest:
|
||||
res = true;
|
||||
break;
|
||||
case ButtonRepair:
|
||||
|
@ -428,22 +428,6 @@ static bool IsButtonAllowed(const CUnit *unit, const ButtonAction *buttonaction)
|
|||
case ButtonPatrol:
|
||||
res = CanMove(unit);
|
||||
break;
|
||||
case ButtonHarvest:
|
||||
if (!unit->CurrentResource ||
|
||||
!(unit->ResourcesHeld > 0 && !unit->Type->ResInfo[unit->CurrentResource]->LoseResources) ||
|
||||
(unit->ResourcesHeld != unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity &&
|
||||
unit->Type->ResInfo[unit->CurrentResource]->LoseResources)) {
|
||||
res = true;
|
||||
}
|
||||
break;
|
||||
case ButtonReturn:
|
||||
if (!(!unit->CurrentResource ||
|
||||
!(unit->ResourcesHeld > 0 && !unit->Type->ResInfo[unit->CurrentResource]->LoseResources) ||
|
||||
(unit->ResourcesHeld != unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity &&
|
||||
unit->Type->ResInfo[unit->CurrentResource]->LoseResources))) {
|
||||
res = true;
|
||||
}
|
||||
break;
|
||||
case ButtonAttack:
|
||||
res = ButtonCheckAttack(unit, buttonaction);
|
||||
break;
|
||||
|
@ -761,12 +745,6 @@ void CButtonPanel::DoClicked(int button)
|
|||
UI.ButtonPanel.Update();
|
||||
UI.StatusLine.Set(_("Select Target"));
|
||||
break;
|
||||
case ButtonReturn:
|
||||
for (i = 0; i < NumSelected; ++i) {
|
||||
SendCommandReturnGoods(Selected[i], NoUnitP,
|
||||
!(KeyModifiers & ModifierShift));
|
||||
}
|
||||
break;
|
||||
case ButtonStop:
|
||||
for (i = 0; i < NumSelected; ++i) {
|
||||
SendCommandStopUnit(Selected[i]);
|
||||
|
|
43
ui/mouse.cpp
43
ui/mouse.cpp
|
@ -143,15 +143,12 @@ void DoRightButton(int sx, int sy)
|
|||
if (!CanSelectMultipleUnits(Selected[0]->Player)) {
|
||||
unit = Selected[0];
|
||||
if (unit->Player->Index != PlayerNumNeutral || dest == NULL ||
|
||||
!(dest->Player == ThisPlayer || dest->IsTeamed(ThisPlayer))) {
|
||||
return ;
|
||||
!(dest->Player == ThisPlayer || dest->IsTeamed(ThisPlayer))) {
|
||||
return;
|
||||
}
|
||||
// tell to go and harvest from a unit
|
||||
if (dest->Type->Harvester &&
|
||||
(res = unit->Type->GivesResource) &&
|
||||
dest->Type->ResInfo[res] &&
|
||||
dest->ResourcesHeld < dest->Type->ResInfo[res]->ResourceCapacity &&
|
||||
unit->Type->CanHarvest) {
|
||||
if (dest->Type->Harvester && (res = unit->Type->GivesResource) &&
|
||||
dest->Type->ResInfo[res] && unit->Type->CanHarvest) {
|
||||
unit->Blink = 4;
|
||||
SendCommandResource(dest, unit, flush);
|
||||
return;
|
||||
|
@ -244,18 +241,8 @@ void DoRightButton(int sx, int sy)
|
|||
if (action == MouseActionHarvest) {
|
||||
if (type->Harvester) {
|
||||
if (dest) {
|
||||
// Return a loaded harvester to deposit
|
||||
if (unit->ResourcesHeld > 0 &&
|
||||
dest->Type->CanStore[unit->CurrentResource] &&
|
||||
dest->Player == unit->Player) {
|
||||
dest->Blink = 4;
|
||||
SendCommandReturnGoods(unit, dest, flush);
|
||||
continue;
|
||||
}
|
||||
// Go and harvest from a unit
|
||||
if ((res = dest->Type->GivesResource) &&
|
||||
type->ResInfo[res] &&
|
||||
unit->ResourcesHeld < type->ResInfo[res]->ResourceCapacity &&
|
||||
if ((res = dest->Type->GivesResource) && type->ResInfo[res] &&
|
||||
dest->Type->CanHarvest &&
|
||||
(dest->Player == unit->Player ||
|
||||
(dest->Player->Index == PlayerNumNeutral))) {
|
||||
|
@ -348,20 +335,9 @@ void DoRightButton(int sx, int sy)
|
|||
|
||||
// Manage harvester from the destination side.
|
||||
if (dest && dest->Type->Harvester) {
|
||||
// tell to return a loaded harvester to deposit
|
||||
if (dest->ResourcesHeld > 0 &&
|
||||
type->CanStore[dest->CurrentResource] &&
|
||||
dest->Player == unit->Player) {
|
||||
dest->Blink = 4;
|
||||
SendCommandReturnGoods(dest, unit, flush);
|
||||
continue;
|
||||
}
|
||||
// tell to go and harvest from a building
|
||||
if ((res = type->GivesResource) &&
|
||||
dest->Type->ResInfo[res] &&
|
||||
dest->ResourcesHeld < dest->Type->ResInfo[res]->ResourceCapacity &&
|
||||
type->CanHarvest &&
|
||||
dest->Player == unit->Player) {
|
||||
if ((res = type->GivesResource) && dest->Type->ResInfo[res] &&
|
||||
type->CanHarvest && dest->Player == unit->Player) {
|
||||
unit->Blink = 4;
|
||||
SendCommandResource(dest, unit, flush);
|
||||
continue;
|
||||
|
@ -1038,10 +1014,7 @@ static int SendResource(int sx, int sy)
|
|||
for (i = 0; i < NumSelected; ++i) {
|
||||
unit = Selected[i];
|
||||
if (unit->Type->Harvester) {
|
||||
if (dest &&
|
||||
(res = dest->Type->GivesResource) &&
|
||||
unit->Type->ResInfo[res] &&
|
||||
unit->ResourcesHeld < unit->Type->ResInfo[res]->ResourceCapacity &&
|
||||
if (dest && (res = dest->Type->GivesResource) && unit->Type->ResInfo[res] &&
|
||||
dest->Type->CanHarvest &&
|
||||
(dest->Player == unit->Player ||
|
||||
(dest->Player->Index == PlayerMax - 1))) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
/**@name script_ui.cpp - The ui ccl functions. */
|
||||
//
|
||||
// (c) Copyright 1999-2006 by Lutz Sammer, Jimmy Salmon, Martin Renold
|
||||
// (c) Copyright 1999-2007 by Lutz Sammer, Jimmy Salmon, Martin Renold
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -1177,8 +1177,6 @@ static int CclDefineButton(lua_State *l)
|
|||
ba.Action = ButtonStandGround;
|
||||
} else if (!strcmp(value, "attack-ground")) {
|
||||
ba.Action = ButtonAttackGround;
|
||||
} else if (!strcmp(value, "return-goods")) {
|
||||
ba.Action = ButtonReturn;
|
||||
} else if (!strcmp(value, "cast-spell")) {
|
||||
ba.Action = ButtonSpellCast;
|
||||
} else if (!strcmp(value, "unload")) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
/**@name script_unit.cpp - The unit ccl functions. */
|
||||
//
|
||||
// (c) Copyright 2001-2005 by Lutz Sammer and Jimmy Salmon
|
||||
// (c) Copyright 2001-2007 by Lutz Sammer and Jimmy Salmon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -183,10 +183,6 @@ void CclParseOrder(lua_State *l, COrder *order)
|
|||
order->Action = UnitActionRepair;
|
||||
} else if (!strcmp(value, "action-resource")) {
|
||||
order->Action = UnitActionResource;
|
||||
} else if (!strcmp(value, "action-return-goods")) {
|
||||
order->Action = UnitActionReturnGoods;
|
||||
} else if (!strcmp(value, "action-transform-into")) {
|
||||
order->Action = UnitActionTransformInto;
|
||||
} else if (!strcmp(value, "range")) {
|
||||
++j;
|
||||
lua_rawgeti(l, -1, j + 1);
|
||||
|
@ -262,12 +258,6 @@ void CclParseOrder(lua_State *l, COrder *order)
|
|||
order->Arg1.Spell = SpellTypeByIdent(LuaToString(l, -1));
|
||||
lua_pop(l, 1);
|
||||
|
||||
} else if (!strcmp(value, "mine")) {
|
||||
++j;
|
||||
lua_rawgeti(l, -1, j + 1);
|
||||
order->Arg1.ResourcePos = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
|
||||
} else {
|
||||
// This leaves a half initialized unit
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
|
@ -347,6 +337,8 @@ static void CclParseBuilt(lua_State *l, CUnit *unit)
|
|||
cframe = cframe->Next;
|
||||
}
|
||||
unit->Data.Built.Frame = cframe;
|
||||
} else {
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -376,9 +368,8 @@ static void CclParseResWorker(lua_State *l, CUnit *unit)
|
|||
lua_rawgeti(l, -1, j + 1);
|
||||
unit->Data.ResWorker.TimeToHarvest = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
} else if (!strcmp(value, "done-harvesting")) {
|
||||
unit->Data.ResWorker.DoneHarvesting = 1;
|
||||
--j;
|
||||
} else {
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -408,6 +399,8 @@ static void CclParseTrain(lua_State *l, CUnit *unit)
|
|||
lua_rawgeti(l, -1, j + 1);
|
||||
unit->Data.Train.Ticks = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
} else {
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -452,6 +445,8 @@ static void CclParseMove(lua_State *l, CUnit *unit)
|
|||
}
|
||||
unit->Data.Move.Length = subargs;
|
||||
lua_pop(l, 1);
|
||||
} else {
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -760,7 +755,7 @@ static int CclUnit(lua_State *l)
|
|||
DefineVariableField(l, unit->Variable + i, j + 1);
|
||||
continue;
|
||||
}
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
LuaError(l, "Unsupported tag: %s" _C_ value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -707,17 +707,6 @@ static int CclDefineUnitType(lua_State *l)
|
|||
lua_rawgeti(l, -1, k + 1);
|
||||
res->WaitAtResource = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
} else if (!strcmp(value, "wait-at-depot")) {
|
||||
lua_rawgeti(l, -1, k + 1);
|
||||
res->WaitAtDepot = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
} else if (!strcmp(value, "resource-capacity")) {
|
||||
lua_rawgeti(l, -1, k + 1);
|
||||
res->ResourceCapacity = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
} else if (!strcmp(value, "lose-resources")) {
|
||||
res->LoseResources = 1;
|
||||
--k;
|
||||
} else if (!strcmp(value, "harvest-from-outside")) {
|
||||
res->HarvestFromOutside = 1;
|
||||
--k;
|
||||
|
@ -1831,10 +1820,6 @@ void UpdateUnitVariables(const CUnit *unit)
|
|||
unit->Variable[GIVERESOURCE_INDEX].Value = unit->ResourcesHeld;
|
||||
unit->Variable[GIVERESOURCE_INDEX].Max = 0x7FFFFFFF;
|
||||
}
|
||||
if (unit->Type->Harvester && unit->CurrentResource) {
|
||||
unit->Variable[CARRYRESOURCE_INDEX].Value = unit->ResourcesHeld;
|
||||
unit->Variable[CARRYRESOURCE_INDEX].Max = unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity;
|
||||
}
|
||||
|
||||
// SightRange
|
||||
unit->Variable[SIGHTRANGE_INDEX].Value = type->Variable[SIGHTRANGE_INDEX].Value;
|
||||
|
|
183
unit/unit.cpp
183
unit/unit.cpp
|
@ -2362,12 +2362,10 @@ CUnit *UnitFindResource(const CUnit *unit, int x, int y, int range, int resource
|
|||
int ep;
|
||||
int i;
|
||||
int w;
|
||||
int n;
|
||||
unsigned char *m;
|
||||
unsigned char *matrix;
|
||||
const CUnit *destu;
|
||||
CUnit *mine;
|
||||
CUnit *bestmine;
|
||||
CUnit *res;
|
||||
CUnit *bestres;
|
||||
int destx;
|
||||
int desty;
|
||||
int bestd;
|
||||
|
@ -2379,19 +2377,15 @@ CUnit *UnitFindResource(const CUnit *unit, int x, int y, int range, int resource
|
|||
Map.Info.MapWidth * Map.Info.MapHeight / 4 : range * range * 5;
|
||||
points = new p[size];
|
||||
|
||||
// Find the nearest gold depot
|
||||
if ((destu = FindDeposit(unit, x, y,range,resource))) {
|
||||
NearestOfUnit(destu, x, y, &destx, &desty);
|
||||
}
|
||||
bestd = 99999;
|
||||
// Make movement matrix. FIXME: can create smaller matrix.
|
||||
matrix = CreateMatrix();
|
||||
w = Map.Info.MapWidth + 2;
|
||||
matrix += w + w + 2;
|
||||
// Unit movement mask
|
||||
// Unit movement mask
|
||||
mask = unit->Type->MovementMask;
|
||||
// Ignore all units along the way. Might seem wierd, but otherwise
|
||||
// peasants would lock at a mine with a lot of workers.
|
||||
// Ignore all units along the way. Might seem weird, but otherwise
|
||||
// peasants would lock at a resource with a lot of workers.
|
||||
mask &= ~(MapFieldLandUnit | MapFieldSeaUnit | MapFieldAirUnit);
|
||||
points[0].X = x;
|
||||
points[0].Y = y;
|
||||
|
@ -2399,7 +2393,7 @@ CUnit *UnitFindResource(const CUnit *unit, int x, int y, int range, int resource
|
|||
matrix[x + y * w] = 1; // mark start point
|
||||
ep = wp = 1; // start with one point
|
||||
cdist = 0; // current distance is 0
|
||||
bestmine = NoUnitP;
|
||||
bestres = NoUnitP;
|
||||
|
||||
//
|
||||
// Pop a point from stack, push all neighbors which could be entered.
|
||||
|
@ -2421,24 +2415,15 @@ CUnit *UnitFindResource(const CUnit *unit, int x, int y, int range, int resource
|
|||
}
|
||||
|
||||
//
|
||||
// Look if there is a mine
|
||||
// Look if there is a resource
|
||||
//
|
||||
if ((mine = ResourceOnMap(x, y, resource)) &&
|
||||
mine->Type->CanHarvest &&
|
||||
(mine->Player->Index == PlayerMax - 1 ||
|
||||
mine->Player == unit->Player ||
|
||||
(unit->IsAllied(mine) && mine->IsAllied(unit)))) {
|
||||
if (destu) {
|
||||
n = (abs(destx - x) > abs(desty - y)) ? abs(destx - x) : abs(desty - y);
|
||||
if (n < bestd) {
|
||||
bestd = n;
|
||||
bestmine = mine;
|
||||
}
|
||||
*m = 99;
|
||||
} else { // no goal take the first
|
||||
delete[] points;
|
||||
return mine;
|
||||
}
|
||||
if ((res = ResourceOnMap(x, y, resource)) &&
|
||||
res->Type->CanHarvest &&
|
||||
(res->Player->Index == PlayerMax - 1 ||
|
||||
res->Player == unit->Player ||
|
||||
(unit->IsAllied(res) && res->IsAllied(unit)))) {
|
||||
delete[] points;
|
||||
return res;
|
||||
}
|
||||
|
||||
if (CanMoveToMask(x, y, mask)) { // reachable
|
||||
|
@ -2463,129 +2448,7 @@ CUnit *UnitFindResource(const CUnit *unit, int x, int y, int range, int resource
|
|||
// Take best of this frame, if any.
|
||||
if (bestd != 99999) {
|
||||
delete[] points;
|
||||
return bestmine;
|
||||
}
|
||||
++cdist;
|
||||
if (rp == wp || cdist >= range) { // unreachable, no more points available
|
||||
break;
|
||||
}
|
||||
// Continue with next set.
|
||||
ep = wp;
|
||||
}
|
||||
delete[] points;
|
||||
return NoUnitP;
|
||||
}
|
||||
|
||||
/**
|
||||
** Find deposit. This will find a deposit for a resource
|
||||
**
|
||||
** @param unit The unit that wants to find a resource.
|
||||
** @param x Closest to x
|
||||
** @param y Closest to y
|
||||
** @param range Maximum distance to the deposit.
|
||||
** @param resource Resource to find deposit from.
|
||||
**
|
||||
** @note This will return a reachable allied depot.
|
||||
**
|
||||
** @return NoUnitP or deposit unit
|
||||
*/
|
||||
CUnit *FindDeposit(const CUnit *unit, int x, int y, int range, int resource)
|
||||
{
|
||||
static const int xoffset[] = { 0,-1,+1, 0, -1,+1,-1,+1 };
|
||||
static const int yoffset[] = { -1, 0, 0,+1, -1,-1,+1,+1 };
|
||||
struct p {
|
||||
unsigned short X;
|
||||
unsigned short Y;
|
||||
} *points;
|
||||
int size;
|
||||
int rx;
|
||||
int ry;
|
||||
int mask;
|
||||
int wp;
|
||||
int rp;
|
||||
int ep;
|
||||
int i;
|
||||
int w;
|
||||
int nodes_searched;
|
||||
unsigned char *m;
|
||||
unsigned char *matrix;
|
||||
CUnit *depot;
|
||||
int destx;
|
||||
int desty;
|
||||
int cdist;
|
||||
|
||||
nodes_searched = 0;
|
||||
|
||||
destx = x;
|
||||
desty = y;
|
||||
size = (Map.Info.MapWidth * Map.Info.MapHeight / 4 < range * range * 5) ?
|
||||
Map.Info.MapWidth * Map.Info.MapHeight / 4 : range * range * 5;
|
||||
points = new p[size];
|
||||
|
||||
// Make movement matrix. FIXME: can create smaller matrix.
|
||||
matrix = CreateMatrix();
|
||||
w = Map.Info.MapWidth + 2;
|
||||
matrix += w + w + 2;
|
||||
// Unit movement mask
|
||||
mask = unit->Type->MovementMask;
|
||||
// Ignore all units along the way. Might seem wierd, but otherwise
|
||||
// peasants would lock at a mine with a lot of workers.
|
||||
mask &= ~(MapFieldLandUnit | MapFieldSeaUnit | MapFieldAirUnit | MapFieldBuilding);
|
||||
points[0].X = x;
|
||||
points[0].Y = y;
|
||||
rp = 0;
|
||||
matrix[x + y * w] = 1; // mark start point
|
||||
ep = wp = 1; // start with one point
|
||||
cdist = 0; // current distance is 0
|
||||
|
||||
//
|
||||
// Pop a point from stack, push all neighbors which could be entered.
|
||||
//
|
||||
for (;;) {
|
||||
while (rp != ep) {
|
||||
rx = points[rp].X;
|
||||
ry = points[rp].Y;
|
||||
for (i = 0; i < 8; ++i) { // mark all neighbors
|
||||
x = rx + xoffset[i];
|
||||
y = ry + yoffset[i];
|
||||
++nodes_searched;
|
||||
// Make sure we don't leave the map.
|
||||
if (x < 0 || y < 0 || x >= Map.Info.MapWidth || y >= Map.Info.MapHeight) {
|
||||
continue;
|
||||
}
|
||||
m = matrix + x + y * w;
|
||||
// Check if visited or unexplored
|
||||
if (*m || !Map.IsFieldExplored(unit->Player, x, y)) {
|
||||
continue;
|
||||
}
|
||||
//
|
||||
// Look if there is a deposit
|
||||
//
|
||||
if ((depot = ResourceDepositOnMap(x, y, resource)) &&
|
||||
((unit->IsAllied(depot) && depot->IsAllied(unit)) ||
|
||||
(unit->Player == depot->Player))) {
|
||||
delete[] points;
|
||||
return depot;
|
||||
}
|
||||
if (CanMoveToMask(x, y, mask)) { // reachable
|
||||
*m = 1;
|
||||
points[wp].X = x; // push the point
|
||||
points[wp].Y = y;
|
||||
if (++wp >= size) { // round about
|
||||
wp = 0;
|
||||
}
|
||||
if (wp == ep) {
|
||||
// We are out of points, give up!
|
||||
DebugPrint("Ran out of points the hard way, beware.\n");
|
||||
break;
|
||||
}
|
||||
} else { // unreachable
|
||||
*m = 99;
|
||||
}
|
||||
}
|
||||
if (++rp >= size) { // round about
|
||||
rp = 0;
|
||||
}
|
||||
return bestres;
|
||||
}
|
||||
++cdist;
|
||||
if (rp == wp || cdist >= range) { // unreachable, no more points available
|
||||
|
@ -3506,12 +3369,6 @@ void SaveOrder(const COrder *order, CFile *file)
|
|||
case UnitActionResource:
|
||||
file->printf("\"action-resource\",");
|
||||
break;
|
||||
case UnitActionReturnGoods:
|
||||
file->printf("\"action-return-goods\",");
|
||||
break;
|
||||
case UnitActionTransformInto:
|
||||
file->printf("\"action-transform-into\",");
|
||||
break;
|
||||
default:
|
||||
DebugPrint("Unknown action in order\n");
|
||||
}
|
||||
|
@ -3542,10 +3399,6 @@ void SaveOrder(const COrder *order, CFile *file)
|
|||
file->printf(" \"spell\", \"%s\",", order->Arg1.Spell->Ident.c_str());
|
||||
}
|
||||
break;
|
||||
case UnitActionResource :
|
||||
case UnitActionReturnGoods :
|
||||
file->printf(" \"mine\", %d,", order->Arg1.ResourcePos);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -3736,11 +3589,7 @@ void SaveUnit(const CUnit *unit, CFile *file)
|
|||
}
|
||||
break;
|
||||
case UnitActionResource:
|
||||
file->printf(", \"data-res-worker\", {\"time-to-harvest\", %d,", unit->Data.ResWorker.TimeToHarvest);
|
||||
if (unit->Data.ResWorker.DoneHarvesting) {
|
||||
file->printf(" \"done-harvesting\",");
|
||||
}
|
||||
file->printf("}");
|
||||
file->printf(", \"data-res-worker\", {\"time-to-harvest\", %d,}", unit->Data.ResWorker.TimeToHarvest);
|
||||
break;
|
||||
case UnitActionBuilt:
|
||||
{
|
||||
|
|
|
@ -744,11 +744,6 @@ static void ShowSingleOrder(const CUnit *unit, int x1, int y1, const COrder *ord
|
|||
dest = 1;
|
||||
break;
|
||||
|
||||
case UnitActionReturnGoods:
|
||||
e_color = color = ColorYellow;
|
||||
dest = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
e_color = color = ColorGray;
|
||||
DebugPrint("Unknown action %d\n" _C_ order->Action);
|
||||
|
|
Loading…
Add table
Reference in a new issue