blob: 5ec7b96e090c771ce21bedbce7703ed9b1680c52 (
plain)
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
|
/* $Id$ */
/** @file macros.h */
#ifndef MACROS_H
#define MACROS_H
#include "core/bitmath_func.hpp"
#include "core/math_func.hpp"
#define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START)
#define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner]))
/**
* Whether a sprite comes from the original graphics files or a new grf file
* (either supplied by OpenTTD or supplied by the user).
*
* @param sprite The sprite to check
* @return True if it is a new sprite, or false if it is original.
*/
#define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE)
/**
* Do an operation for each set set bit in a value.
*
* This macros is used to do an operation for each set
* bit in a variable. The first variable can be reused
* in the operation due to it's the bit position counter.
* The second variable will be cleared during the usage
*
* @param i The position counter
* @param b The value which we check for set bits
*/
#define FOR_EACH_SET_BIT(i, b) \
for (i = 0; b != 0; i++, b >>= 1) \
if (b & 1)
static inline uint16 ReadLE16Aligned(const void* x)
{
return FROM_LE16(*(const uint16*)x);
}
static inline uint16 ReadLE16Unaligned(const void* x)
{
#ifdef OTTD_ALIGNMENT
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
#else
return FROM_LE16(*(const uint16*)x);
#endif
}
/** return the largest value that can be entered in a variable.
*/
#define MAX_UVALUE(type) ((type)~(type)0)
#endif /* MACROS_H */
|