OpenClonk
C4ObjectOCF.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Object Character Flag logic */
19 
20 #include "C4Include.h"
22 #include "object/C4Object.h"
23 
24 #include "control/C4Record.h"
25 #include "game/C4Physics.h"
26 #include "landscape/C4Landscape.h"
27 #include "object/C4Def.h"
28 
29 
31 {
32  C4PropList* pActionDef = GetAction();
33  uint32_t dwOCFOld = OCF;
34  // Update the object character flag according to the object's current situation
35  C4Real cspeed=GetSpeed();
36 #ifdef _DEBUG
38  { LogF("Warning: contained in wild object %p!", static_cast<void*>(Contained)); }
39  else if (Contained && !Contained->Status)
40  { LogF("Warning: contained in deleted object (#%d) (%s)!", Contained->Number, Contained->GetName()); }
41 #endif
42  // OCF_Normal: The OCF is never zero
44  // OCF_Construct: Can be built outside
45  if (Def->Constructable && (Con<FullCon)
46  && (fix_r==Fix0) && !OnFire)
48  // OCF_Grab: Can be pushed
50  OCF|=OCF_Grab;
51  // OCF_Carryable: Can be picked up
54  // OCF_OnFire: Is burning
55  if (OnFire)
56  OCF|=OCF_OnFire;
57  // OCF_Inflammable: Is not burning and is inflammable
60  // OCF_FullCon: Is fully completed/grown
61  if (Con>=FullCon)
63  // OCF_Rotate: Can be rotated
64  if (Def->Rotateable)
65  // Don't rotate minimum (invisible) construction sites
66  if (Con>100)
67  OCF|=OCF_Rotate;
68  // OCF_Exclusive: No action through this, no construction in front of this
69  if (Def->Exclusive)
71  // OCF_Entrance: Can currently be entered/activated
72  if ((Def->Entrance.Wdt>0) && (Def->Entrance.Hgt>0))
73  if ((OCF & OCF_FullCon) && ((Def->RotatedEntrance == 1) || (GetR() <= Def->RotatedEntrance)))
75  // HitSpeeds
76  if (cspeed>=HitSpeed1) OCF|=OCF_HitSpeed1;
77  if (cspeed>=HitSpeed2) OCF|=OCF_HitSpeed2;
78  if (cspeed>=HitSpeed3) OCF|=OCF_HitSpeed3;
79  if (cspeed>=HitSpeed4) OCF|=OCF_HitSpeed4;
80  // OCF_Collection
82  if ((Def->Collection.Wdt>0) && (Def->Collection.Hgt>0))
83  if (!pActionDef || (!pActionDef->GetPropertyInt(P_ObjectDisabled)))
85  // OCF_Alive
86  if (Alive) OCF|=OCF_Alive;
87  // OCF_CrewMember
88  if (Def->CrewMember)
89  if (Alive)
91  // OCF_NotContained
92  if (!Contained)
94  // OCF_InLiquid
95  if (InLiquid)
96  if (!Contained)
98  // OCF_InSolid
99  if (!Contained)
100  if (GBackSolid(GetX(), GetY()))
101  OCF|=OCF_InSolid;
102  // OCF_InFree
103  if (!Contained)
104  if (!GBackSemiSolid(GetX(), GetY()-1))
105  OCF|=OCF_InFree;
106  // OCF_Available
108  if (!GBackSemiSolid(GetX(), GetY()-1) || (!GBackSolid(GetX(), GetY()-1) && !GBackSemiSolid(GetX(), GetY()-8)))
110  // OCF_Container
114  {
115  C4RCOCF rc = { dwOCFOld, OCF, false };
116  AddDbgRec(RCT_OCF, &rc, sizeof(rc));
117  }
118 }
119 
120 
122 {
123  C4PropList* pActionDef = GetAction();
124  uint32_t dwOCFOld = OCF;
125  // Update the object character flag according to the object's current situation
126  C4Real cspeed=GetSpeed();
127 #ifdef _DEBUG
129  { LogF("Warning: contained in wild object %p!", static_cast<void*>(Contained)); }
130  else if (Contained && !Contained->Status)
131  { LogF("Warning: contained in deleted object %p (%s)!", static_cast<void*>(Contained), Contained->GetName()); }
132 #endif
133  // Keep the bits that only have to be updated with SetOCF (def, category, con, alive, onfire)
136  // OCF_inflammable: can catch fire and is not currently burning.
138  OCF |= OCF_Inflammable;
139  // OCF_Carryable: Can be picked up
142  // OCF_Grab: Can be grabbed.
144  OCF |= OCF_Grab;
145  // OCF_Construct: Can be built outside
146  if (Def->Constructable && (Con<FullCon)
147  && (fix_r == Fix0) && !OnFire)
149  // OCF_Entrance: Can currently be entered/activated
150  if ((Def->Entrance.Wdt>0) && (Def->Entrance.Hgt>0))
151  if ((OCF & OCF_FullCon) && ((Def->RotatedEntrance == 1) || (GetR() <= Def->RotatedEntrance)))
152  OCF|=OCF_Entrance;
153  // HitSpeeds
154  if (cspeed>=HitSpeed1) OCF|=OCF_HitSpeed1;
155  if (cspeed>=HitSpeed2) OCF|=OCF_HitSpeed2;
156  if (cspeed>=HitSpeed3) OCF|=OCF_HitSpeed3;
157  if (cspeed>=HitSpeed4) OCF|=OCF_HitSpeed4;
158  // OCF_Collection
160  if ((Def->Collection.Wdt>0) && (Def->Collection.Hgt>0))
161  if (!pActionDef || (!pActionDef->GetPropertyInt(P_ObjectDisabled)))
163  // OCF_NotContained
164  if (!Contained)
166  // OCF_InLiquid
167  if (InLiquid)
168  if (!Contained)
169  OCF|=OCF_InLiquid;
170  // OCF_InSolid
171  if (!Contained)
172  if (GBackSolid(GetX(), GetY()))
173  OCF|=OCF_InSolid;
174  // OCF_InFree
175  if (!Contained)
176  if (!GBackSemiSolid(GetX(), GetY()-1))
177  OCF|=OCF_InFree;
178  // OCF_Available
180  if (!GBackSemiSolid(GetX(), GetY()-1) || (!GBackSolid(GetX(), GetY()-1) && !GBackSemiSolid(GetX(), GetY()-8)))
182  // OCF_Container
186  {
187  C4RCOCF rc = { dwOCFOld, OCF, true };
188  AddDbgRec(RCT_OCF, &rc, sizeof(rc));
189  }
190 #ifdef _DEBUG
192  uint32_t updateOCF = OCF;
193  SetOCF();
194  assert (updateOCF == OCF);
196 #endif
197 }
198 
199 void C4Object::GetOCFForPos(int32_t ctx, int32_t cty, DWORD &ocf) const
200 {
201  DWORD rocf=OCF;
202  // Verify entrance area OCF return
203  if (rocf & OCF_Entrance)
204  if (!Inside<int32_t>(cty - (GetY() + Def->Entrance.y), 0, Def->Entrance.Hgt - 1)
205  || !Inside<int32_t>(ctx - (GetX() + Def->Entrance.x), 0, Def->Entrance.Wdt - 1))
206  rocf &= (~OCF_Entrance);
207  // Verify collection area OCF return
208  if (rocf & OCF_Collection)
209  if (!Inside<int32_t>(cty - (GetY() + Def->Collection.y), 0, Def->Collection.Hgt - 1)
210  || !Inside<int32_t>(ctx - (GetX() + Def->Collection.x), 0, Def->Collection.Wdt - 1))
211  rocf &= (~OCF_Collection);
212  ocf=rocf;
213 }
C4Config Config
Definition: C4Config.cpp:930
const uint32_t OCF_Carryable
Definition: C4Constants.h:82
const int32_t FullCon
Definition: C4Constants.h:181
const uint32_t OCF_Inflammable
Definition: C4Constants.h:86
const uint32_t OCF_Grab
Definition: C4Constants.h:81
const uint32_t OCF_Construct
Definition: C4Constants.h:80
const uint32_t OCF_InFree
Definition: C4Constants.h:100
const uint32_t OCF_HitSpeed1
Definition: C4Constants.h:84
const uint32_t OCF_Collection
Definition: C4Constants.h:93
const uint32_t OCF_HitSpeed4
Definition: C4Constants.h:95
const uint32_t OCF_Normal
Definition: C4Constants.h:79
const uint32_t OCF_OnFire
Definition: C4Constants.h:83
const uint32_t OCF_Entrance
Definition: C4Constants.h:90
const uint32_t OCF_Alive
Definition: C4Constants.h:103
const uint32_t OCF_Container
Definition: C4Constants.h:102
const uint32_t OCF_Available
Definition: C4Constants.h:101
const uint32_t OCF_Exclusive
Definition: C4Constants.h:89
const uint32_t OCF_Rotate
Definition: C4Constants.h:88
const uint32_t OCF_HitSpeed3
Definition: C4Constants.h:92
const uint32_t OCF_InSolid
Definition: C4Constants.h:99
const uint32_t OCF_FullCon
Definition: C4Constants.h:85
const uint32_t OCF_NotContained
Definition: C4Constants.h:96
const uint32_t OCF_HitSpeed2
Definition: C4Constants.h:91
const uint32_t OCF_CrewMember
Definition: C4Constants.h:97
const uint32_t OCF_InLiquid
Definition: C4Constants.h:98
const int32_t C4D_Grab_Put
Definition: C4Def.h:62
const int32_t C4D_Grab_Get
Definition: C4Def.h:63
constexpr bool DEBUGREC_OCF
Definition: C4Include.h:35
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:234
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:229
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
const C4Real HitSpeed3
Definition: C4Physics.h:29
const C4Real HitSpeed1
Definition: C4Movement.cpp:37
const C4Real HitSpeed2
Definition: C4Physics.h:29
const C4Real HitSpeed4
Definition: C4Physics.h:29
const C4Real Fix0
Definition: C4Real.h:312
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
#define DEBUGREC_ON
Definition: C4Record.h:29
@ RCT_OCF
Definition: C4Record.h:83
#define DEBUGREC_OFF
Definition: C4Record.h:28
@ P_ContactIncinerate
@ P_Collectible
@ P_Touchable
@ P_ObjectDisabled
uint32_t DWORD
int32_t DebugRec
Definition: C4Config.h:63
C4ConfigGeneral General
Definition: C4Config.h:255
int32_t CrewMember
Definition: C4Def.h:112
int32_t IncompleteActivity
Definition: C4Def.h:128
int32_t RotatedEntrance
Definition: C4Def.h:145
int32_t Rotateable
Definition: C4Def.h:119
C4Rect Collection
Definition: C4Def.h:106
int32_t Constructable
Definition: C4Def.h:118
int32_t GrabPutGet
Definition: C4Def.h:124
C4Rect Entrance
Definition: C4Def.h:105
int32_t Exclusive
Definition: C4Def.h:116
Definition: C4Real.h:59
bool OnFire
Definition: C4Object.h:171
void GetOCFForPos(int32_t ctx, int32_t cty, DWORD &ocf) const
C4PropList * GetAction() const
C4Real GetSpeed() const
int32_t GetX() const
Definition: C4Object.h:285
uint32_t OCF
Definition: C4Object.h:132
C4Real fix_r
Definition: C4Object.h:123
int32_t Con
Definition: C4Object.h:172
void UpdateOCF()
int32_t GetY() const
Definition: C4Object.h:286
bool Alive
Definition: C4Object.h:174
int32_t GetR() const
Definition: C4Object.h:287
C4ObjectPtr Contained
Definition: C4Object.h:142
void SetOCF()
Definition: C4ObjectOCF.cpp:30
bool InLiquid
Definition: C4Object.h:129
C4Def * Def
Definition: C4Object.h:141
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:855
virtual const char * GetName() const
Definition: C4PropList.cpp:618
int32_t Status
Definition: C4PropList.h:173
static bool CheckPropList(C4PropList *)
Definition: C4PropList.cpp:56
int32_t y
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30