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 ( )
default

Member Function Documentation

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

Definition at line 133 of file C4TransferZone.cpp.

References Hgt, Wdt, X, and Y.

Referenced by C4PathFinderRay::Execute().

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

Here is the caller graph for this function:

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

Definition at line 124 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.

125 {
126  if (Used) fHighlight=true;
128  int(cgo.X+X-cgo.TargetX),int(cgo.Y+Y-cgo.TargetY),
129  int(cgo.X+X-cgo.TargetX+Wdt-1),int(cgo.Y+Y-cgo.TargetY+Hgt-1),
130  fHighlight ? C4RGB(0, 0xca, 0) : C4RGB(0xca, 0, 0));
131 }
float Y
Definition: C4Facet.h:118
void DrawFrameDw(C4Surface *sfcDest, int x1, int y1, int x2, int y2, DWORD dwClr, float width=1.0f)
Definition: C4Draw.cpp:641
C4Draw * pDraw
Definition: C4Draw.cpp:42
#define C4RGB(r, g, b)
Definition: StdColors.h:26
float TargetX
Definition: C4Facet.h:165
C4Surface * Surface
Definition: C4Facet.h:117
float TargetY
Definition: C4Facet.h:165
float X
Definition: C4Facet.h:118

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 160 of file C4TransferZone.cpp.

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

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

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

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: