OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4TransferZone Class Reference

#include <C4TransferZone.h>

Collaboration diagram for C4TransferZone:
[legend]

Public Member Functions

 C4TransferZone ()
 
 ~C4TransferZone ()
 
bool GetEntryPoint (int32_t &rX, int32_t &rY, int32_t iToX, int32_t iToY)
 
void Draw (C4TargetFacet &cgo, bool fHighlight=false)
 
bool At (int32_t iX, int32_t iY)
 

Public Attributes

C4ObjectObject
 
int32_t X
 
int32_t Y
 
int32_t Wdt
 
int32_t Hgt
 
bool Used
 

Protected Attributes

C4TransferZoneNext
 

Friends

class C4TransferZones
 

Detailed Description

Definition at line 23 of file C4TransferZone.h.

Constructor & Destructor Documentation

C4TransferZone::C4TransferZone ( )

Definition at line 29 of file C4TransferZone.cpp.

References Hgt, Next, Object, Used, Wdt, X, and Y.

30 {
31  Object = nullptr;
32  X = Y = Wdt = Hgt = 0;
33  Next = nullptr;
34  Used = false;
35 }
C4TransferZone * Next
C4Object * Object
C4TransferZone::~C4TransferZone ( )

Definition at line 37 of file C4TransferZone.cpp.

38 {
39 }

Member Function Documentation

bool C4TransferZone::At ( int32_t  iX,
int32_t  iY 
)

Definition at line 135 of file C4TransferZone.cpp.

References Hgt, Wdt, X, and Y.

Referenced by C4PathFinderRay::Execute().

136 {
137  return (Inside<int32_t>(iX-X,0,Wdt-1) && Inside<int32_t>(iY-Y,0,Hgt-1));
138 }

Here is the caller graph for this function:

void C4TransferZone::Draw ( C4TargetFacet cgo,
bool  fHighlight = false 
)

Definition at line 126 of file C4TransferZone.cpp.

References C4RGB, C4Draw::DrawFrameDw(), Hgt, pDraw, C4Facet::Surface, C4TargetFacet::TargetX, C4TargetFacet::TargetY, Used, Wdt, X, C4Facet::X, Y, and C4Facet::Y.

127 {
128  if (Used) fHighlight=true;
130  int(cgo.X+X-cgo.TargetX),int(cgo.Y+Y-cgo.TargetY),
131  int(cgo.X+X-cgo.TargetX+Wdt-1),int(cgo.Y+Y-cgo.TargetY+Hgt-1),
132  fHighlight ? C4RGB(0, 0xca, 0) : C4RGB(0xca, 0, 0));
133 }
float Y
Definition: C4Facet.h:120
void DrawFrameDw(C4Surface *sfcDest, int x1, int y1, int x2, int y2, DWORD dwClr, float width=1.0f)
Definition: C4Draw.cpp:644
C4Draw * pDraw
Definition: C4Draw.cpp:45
#define C4RGB(r, g, b)
Definition: StdColors.h:28
float TargetX
Definition: C4Facet.h:167
C4Surface * Surface
Definition: C4Facet.h:119
float TargetY
Definition: C4Facet.h:167
float X
Definition: C4Facet.h:120

Here is the call graph for this function:

bool C4TransferZone::GetEntryPoint ( int32_t &  rX,
int32_t &  rY,
int32_t  iToX,
int32_t  iToY 
)

Definition at line 162 of file C4TransferZone.cpp.

References AdjustMoveToTarget(), GBackSolid(), Hgt, Wdt, X, and Y.

Referenced by C4PathFinderRay::Execute(), and C4Command::Transfer().

163 {
164  // Target inside zone: move outside horizontally
165  if (Inside<int32_t>(iToX-X,0,Wdt-1) && Inside<int32_t>(iToY-Y,0,Hgt-1))
166  {
167  if (iToX<X+Wdt/2) iToX=X-1;
168  else iToX=X+Wdt;
169  }
170  // Get closest adjacent point
171  rX=Clamp<int32_t>(iToX,X-1,X+Wdt);
172  rY=Clamp<int32_t>(iToY,Y-1,Y+Hgt);
173  // Search around zone for free
174  int32_t iX1=rX,iY1=rY,iX2=rX,iY2=rY;
175  int32_t iXIncr1=0,iYIncr1=-1,iXIncr2=0,iYIncr2=+1;
176  int32_t cnt;
177  for (cnt=0; cnt<2*Wdt+2*Hgt; cnt++)
178  {
179  // Found free
180  if (!GBackSolid(iX1,iY1)) { rX=iX1; rY=iY1; break; }
181  if (!GBackSolid(iX2,iY2)) { rX=iX2; rY=iY2; break; }
182  // Advance
183  iX1+=iXIncr1; iY1+=iYIncr1;
184  iX2+=iXIncr2; iY2+=iYIncr2;
185  // Corners
186  if (iY1<Y-1) { iY1=Y-1; iXIncr1=+1; iYIncr1=0; }
187  if (iX1>X+Wdt) { iX1=X+Wdt; iXIncr1=0; iYIncr1=+1; }
188  if (iY1>Y+Hgt) { iY1=Y+Hgt; iXIncr1=-1; iYIncr1=0; }
189  if (iX1<X-1) { iX1=X-1; iXIncr1=0; iYIncr1=-1; }
190  if (iY2<Y-1) { iY2=Y-1; iXIncr2=-1; iYIncr2=0; }
191  if (iX2>X+Wdt) { iX2=X+Wdt; iXIncr2=0; iYIncr2=-1; }
192  if (iY2>Y+Hgt) { iY2=Y+Hgt; iXIncr2=+1; iYIncr2=0; }
193  if (iX2<X-1) { iX2=X-1; iXIncr2=0; iYIncr2=+1; }
194  }
195  // No free found
196  if (cnt>=2*Wdt+2*Hgt) return false;
197  // Vertical walk-to adjust (only if at the side of zone)
198  if (!Inside<int32_t>(rX-X,0,Wdt-1))
199  AdjustMoveToTarget(rX,rY,false,20);
200  // Success
201  return true;
202 }
void AdjustMoveToTarget(int32_t &rX, int32_t &rY, bool fFreeMove, int32_t iShapeHgt)
Definition: C4Command.cpp:144
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:232

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4TransferZones
friend

Definition at line 25 of file C4TransferZone.h.

Member Data Documentation

int32_t C4TransferZone::Hgt
bool C4TransferZone::Used

Definition at line 32 of file C4TransferZone.h.

Referenced by C4TransferZone(), Draw(), and C4PathFinderRay::Execute().

int32_t C4TransferZone::Wdt
int32_t C4TransferZone::X
int32_t C4TransferZone::Y

The documentation for this class was generated from the following files: