File: MoveMath.h

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (80 lines) | stat: -rwxr-xr-x 3,117 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef MOVEMATH_H
#define MOVEMATH_H

#include "Sim/MoveTypes/MoveInfo.h"
#include "Sim/Objects/SolidObject.h"
#include "System/float3.h"
#include "System/Misc/BitwiseEnum.h"


class CMoveMath {
	CR_DECLARE(CMoveMath);
	
protected:
	virtual float SpeedMod(const MoveData& moveData, float height, float slope) const = 0;
	virtual float SpeedMod(const MoveData& moveData, float height, float slope, float moveSlope) const = 0;

public:
	// gives the y-coordinate the unit will "stand on"
	virtual float yLevel(const float3& pos) const;
	virtual float yLevel(int xSquare, int Square) const = 0;

public:
	enum BlockTypes {
		BLOCK_NONE        = 0,
		BLOCK_MOVING      = 1,
		BLOCK_MOBILE      = 2,
		BLOCK_MOBILE_BUSY = 4,
		BLOCK_STRUCTURE   = 8,
		BLOCK_IMPASSABLE  = 24 // := 16 | BLOCK_STRUCTURE;
	};
	typedef BitwiseEnum<BlockTypes> BlockType;
	

	// returns a speed-multiplier for given position or data
	float GetPosSpeedMod(const MoveData& moveData, int xSquare, int zSquare) const;
	float GetPosSpeedMod(const MoveData& moveData, int xSquare, int zSquare, const float3& moveDir) const;
	float GetPosSpeedMod(const MoveData& moveData, const float3& pos) const
	{
		return GetPosSpeedMod(moveData, pos.x / SQUARE_SIZE, pos.z / SQUARE_SIZE);
	}
	float GetPosSpeedMod(const MoveData& moveData, const float3& pos, const float3& moveDir) const
	{
		return GetPosSpeedMod(moveData, pos.x / SQUARE_SIZE, pos.z / SQUARE_SIZE, moveDir);
	}

	// tells whether a position is blocked (inaccessable for a given object's movedata)
	inline BlockType IsBlocked(const MoveData& moveData, const float3& pos) const;
	inline BlockType IsBlocked(const MoveData& moveData, int xSquare, int zSquare) const;
	BlockType IsBlockedNoSpeedModCheck(const MoveData& moveData, int xSquare, int zSquare) const;
	bool IsBlockedStructure(const MoveData& moveData, int xSquare, int zSquare) const;
	bool IsBlockedStructureXmax(const MoveData& moveData, int xSquare, int zSquare) const;
	bool IsBlockedStructureZmax(const MoveData& moveData, int xSquare, int zSquare) const;
	
	// tells whether a given object is blocking the given movedata
	static bool CrushResistant(const MoveData& colliderMD, const CSolidObject* collidee);
	static bool IsNonBlocking(const MoveData& colliderMD, const CSolidObject* collidee);

	// returns the block-status of a single quare
	static BlockType SquareIsBlocked(const MoveData& moveData, int xSquare, int zSquare);

	virtual ~CMoveMath() {}
};

/* Check if a given square-position is accessable by the movedata footprint. */
inline CMoveMath::BlockType CMoveMath::IsBlocked(const MoveData& moveData, int xSquare, int zSquare) const
{
	if (GetPosSpeedMod(moveData, xSquare, zSquare) == 0.0f)
		return BLOCK_IMPASSABLE;
	return IsBlockedNoSpeedModCheck(moveData, xSquare, zSquare);
}

/* Converts a point-request into a square-positional request. */
inline CMoveMath::BlockType CMoveMath::IsBlocked(const MoveData& moveData, const float3& pos) const
{
	return IsBlocked(moveData, pos.x / SQUARE_SIZE, pos.z / SQUARE_SIZE);
}

#endif