File: Maths.h

package info (click to toggle)
spring 106.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 55,260 kB
  • sloc: cpp: 543,946; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (86 lines) | stat: -rw-r--r-- 3,072 bytes parent folder | download | duplicates (7)
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
81
82
83
84
85
86
#ifndef KAIK_MATHS_HDR
#define KAIK_MATHS_HDR

#if defined WIN32
  #ifndef NOMINMAX
    #define NOMINMAX
  #endif
  #define WIN32_LEAN_AND_MEAN
  #include <windows.h>
#else
  #include <sys/time.h>
  #define LARGE_INTEGER struct timeval
#endif

#include "System/float3.h"
#include "Defines.h"
#include "MTRand.h"

struct AIClasses;
struct BuildTask;

namespace springLegacyAI {
	struct UnitDef;
} // namespace springLegacyAI

class CMaths {
	public:
		CMaths(AIClasses* ai);
		~CMaths();

		// sets the float3 so it is inside the game area
		void F3MapBound(float3& pos);
		// Returns a random point inside a circle centered on pos
		float3 F3Randomize(const float3& pos, float radius);//Returns a random point inside a circle centered on pos

		// Converts a float3 into X Y coordinates for use in arrays, divided by this resolution
		void F32XY(const float3& pos, int* x, int* y, int resolution = 1);
		// Converts X Y coordinates into a float3 for use in commands etc, divided by this resolution
		float3 XY2F3(int x, int y, int resolution = 1);

		// Returns the metal per second needed to build this unit with this builder
		float BuildMetalPerSecond(const UnitDef* builder, const UnitDef* built);
		// Returns the energy per second needed to build this unit with this builder
		float BuildEnergyPerSecond(const UnitDef* builder, const UnitDef* built);
		// Returns the time taken for the builder to build the unit unassisted and with available resources
		float BuildTime(const UnitDef* builder, const UnitDef* built);

		// Returns whether building this unit will put resource reserves below the specified amounts with the current income and expenditure
		bool FeasibleConstruction(const UnitDef* builder, const UnitDef* built, float MinMpc = FEASIBLEMSTORRATIO, float MinEpc = FEASIBLEESTORRATIO);
		// Returns whether building this unit will put metal reserves below the specified amount with the current income and expenditure
		bool MFeasibleConstruction(const UnitDef* builder, const UnitDef* built, float MinMpc = FEASIBLEMSTORRATIO);
		// Returns whether building this unit will put energy reserves below the specified amount with the current income and expenditure
		bool EFeasibleConstruction(const UnitDef* builder, const UnitDef* built, float MinEpc = FEASIBLEESTORRATIO);

		float GetUnitCost(const UnitDef* unit);
		float GetUnitCost(int unit);

		// Estimated time for the unit to arrive at location in a flat straight line, in seconds
		float ETA(int unit, const float3& destination);
		// Estimated time for this buildtask to complete with the current builders with full resources
		float ETT(BuildTask& bt);

		// RNGs
		float RandNormal(float m, float s, bool positiveonly = false);
		float RandFloat();
		unsigned int RandInt();

		// Timer Stuff
		void TimerStart();
		int TimerTicks();
		float TimerSecs();

	private:
		// Timer Stuff
		LARGE_INTEGER tick_start, tick_laststop, tick_end, ticksPerSecond;

		// Mersenne Twisters
		MTRand_int32 MTRandInt;
		MTRand MTRandFloat;

		AIClasses* ai;
		int mapfloat3height, mapfloat3width;
};


#endif