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 /* Basic classes for rectangles and vertex outlines */
19 
20 #ifndef INC_C4Shape
21 #define INC_C4Shape
22 
23 #include "config/C4Constants.h"
24 #include "lib/C4Rect.h"
25 
26 #define C4D_VertexCpyPos (C4D_MaxVertex/2)
27 
28 // a functional class to provide density for coordinates
29 class C4DensityProvider
30 {
31 public:
32 	virtual int32_t GetDensity(int32_t x, int32_t y) const;
33 	virtual ~C4DensityProvider() = default;
34 };
35 
36 extern C4DensityProvider DefaultDensityProvider;
37 
38 class C4Shape : public C4Rect
39 {
40 public:
41 	// remember to adjust C4Shape::CopyFrom and CreateOwnOriginalCopy when adding members here!
42 	int32_t VtxNum = 0;
43 	int32_t VtxX[C4D_MaxVertex] = { 0 };
44 	int32_t VtxY[C4D_MaxVertex] = { 0 };
45 	int32_t VtxCNAT[C4D_MaxVertex] = { 0 };
46 	int32_t VtxFriction[C4D_MaxVertex] = { 0 };
47 	int32_t ContactDensity = C4M_Solid;
48 	int32_t ContactCNAT = 0;
49 	int32_t ContactCount = 0;
50 	int32_t AttachMat = MNone;
51 	int32_t VtxContactCNAT[C4D_MaxVertex] = { 0 };
52 	int32_t VtxContactMat[C4D_MaxVertex] = { 0 };
53 	int32_t iAttachX = 0, iAttachY = 0, iAttachVtx = 0;
54 public:
55 	void Default();
56 	void Rotate(C4Real Angle, bool bUpdateVertices);
57 	void Stretch(int32_t iCon, bool bUpdateVertices);
58 	void Jolt(int32_t iCon, bool bUpdateVertices);
59 	void GetVertexOutline(C4Rect &rRect);
60 	int32_t GetVertexY(int32_t iVertex);
61 	int32_t GetVertexX(int32_t iVertex);
GetX()62 	int32_t GetX() const { return x; }
GetY()63 	int32_t GetY() const { return y; }
64 	bool AddVertex(int32_t iX, int32_t iY);
65 	bool CheckContact(int32_t cx, int32_t cy);
66 	bool ContactCheck(int32_t cx, int32_t cy, uint32_t *border_hack_contacts=nullptr, bool collide_halfvehic=false);
67 	bool Attach(int32_t &cx, int32_t &cy, BYTE cnat_pos);
68 	bool LineConnect(int32_t tx, int32_t ty, int32_t cvtx, int32_t ld, int32_t oldx, int32_t oldy);
69 	bool InsertVertex(int32_t iPos, int32_t tx, int32_t ty);
70 	bool RemoveVertex(int32_t iPos);
71 	void CopyFrom(C4Shape rFrom, bool bCpyVertices, bool fCopyVerticesFromSelf);
72 	int32_t GetBottomVertex();
73 	int GetBottom(); // return lowest vertex Y
74 	int32_t GetVertexContact(int32_t iVtx, DWORD dwCheckMask, int32_t tx, int32_t ty, const C4DensityProvider &rDensityProvider = DefaultDensityProvider); // get CNAT-mask for given vertex - does not check range for iVtx!
75 	bool CheckScaleToWalk(int x, int y);
76 	void CreateOwnOriginalCopy(C4Shape &rFrom); // create copy of all vertex members in back area of own buffers
77 	void CompileFunc(StdCompiler *pComp, const C4Shape *default_shape);
78 private:
79 	bool CheckTouchableMaterial(int32_t x, int32_t y, int32_t vtx_i, int32_t y_dir = 0, const C4DensityProvider &rDensityProvider = DefaultDensityProvider);
80 };
81 
82 #endif // INC_C4Shape
83