annotate src/newgrf_spritegroup.cpp @ 9088:5b5958727985 draft

(svn r12947) -Fix: keep only first 15 bits for non failed callback results
author glx <glx@openttd.org>
date Sun, 04 May 2008 22:32:25 +0000
parents 94bb527c979f
children d48433370037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
3 /** @file newgrf_spritegroup.cpp */
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6343
diff changeset
4
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
6 #include "openttd.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
7 #include "variables.h"
6343
f75b72d9fc98 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros <maedhros@openttd.org>
parents: 6332
diff changeset
8 #include "landscape.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
9 #include "oldpool.h"
8546
1b7b256d26af (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch <frosch@openttd.org>
parents: 8474
diff changeset
10 #include "newgrf.h"
5617
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
11 #include "newgrf_callbacks.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #include "newgrf_spritegroup.h"
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6247
diff changeset
13 #include "sprite.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8113
diff changeset
14 #include "date_func.h"
8270
5613b863190d (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium <rubidium@openttd.org>
parents: 8140
diff changeset
15 #include "settings_type.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
16
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
17 static void SpriteGroupPoolCleanBlock(uint start_item, uint end_item);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
18
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
19 static uint _spritegroup_count = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
20 STATIC_OLD_POOL(SpriteGroup, SpriteGroup, 9, 250, NULL, SpriteGroupPoolCleanBlock)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
21
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
22 static void DestroySpriteGroup(SpriteGroup *group)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
23 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
24 /* Free dynamically allocated memory */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
25 /* XXX Cast away the consts due to MSVC being buggy... */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
26 switch (group->type) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
27 case SGT_REAL:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
28 free((SpriteGroup**)group->g.real.loaded);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
29 free((SpriteGroup**)group->g.real.loading);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
30 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
31
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
32 case SGT_DETERMINISTIC:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
33 free(group->g.determ.adjusts);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34 free(group->g.determ.ranges);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
35 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
36
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
37 case SGT_RANDOMIZED:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
38 free((SpriteGroup**)group->g.random.groups);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
39 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
40
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6247
diff changeset
41 case SGT_TILELAYOUT:
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6247
diff changeset
42 free((void*)group->g.layout.dts->seq);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6247
diff changeset
43 free(group->g.layout.dts);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6247
diff changeset
44 break;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6247
diff changeset
45
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
46 default:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
47 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
48 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
49 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
50
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
51 static void SpriteGroupPoolCleanBlock(uint start_item, uint end_item)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
52 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
53 uint i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
54
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
55 for (i = start_item; i <= end_item; i++) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
56 DestroySpriteGroup(GetSpriteGroup(i));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
57 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
58 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
59
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
60
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
61 /* Allocate a new SpriteGroup */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 5622
diff changeset
62 SpriteGroup *AllocateSpriteGroup()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
63 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
64 /* This is totally different to the other pool allocators, as we never remove an item from the pool. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
65 if (_spritegroup_count == GetSpriteGroupPoolSize()) {
7401
1e97c047c9f6 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium <rubidium@openttd.org>
parents: 7168
diff changeset
66 if (!_SpriteGroup_pool.AddBlockToPool()) return NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
67 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
68
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
69 return GetSpriteGroup(_spritegroup_count++);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
70 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
71
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
72
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 5622
diff changeset
73 void InitializeSpriteGroupPool()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
74 {
7401
1e97c047c9f6 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium <rubidium@openttd.org>
parents: 7168
diff changeset
75 _SpriteGroup_pool.CleanPool();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
76
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
77 _spritegroup_count = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
78 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
79
7616
b1b321279552 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium <rubidium@openttd.org>
parents: 7612
diff changeset
80 TemporaryStorageArray<uint32, 0x110> _temp_store;
6521
9aecb1a6dea5 (svn r9707) -Codechange: Add some support for NewGRF var 7D, temporary storage array.
peter1138 <peter1138@openttd.org>
parents: 6357
diff changeset
81
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
82
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
83 static inline uint32 GetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
84 {
8546
1b7b256d26af (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch <frosch@openttd.org>
parents: 8474
diff changeset
85 /* First handle variables common with Action7/9/D */
1b7b256d26af (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch <frosch@openttd.org>
parents: 8474
diff changeset
86 uint32 value;
8561
75331afa9549 (svn r12139) -Fix (r12124): The global variable value should be returned, not the variable.
peter1138 <peter1138@openttd.org>
parents: 8546
diff changeset
87 if (GetGlobalVariable(variable, &value)) return value;
8546
1b7b256d26af (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch <frosch@openttd.org>
parents: 8474
diff changeset
88
1b7b256d26af (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch <frosch@openttd.org>
parents: 8474
diff changeset
89 /* Non-common variable */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
90 switch (variable) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
91 case 0x0C: return object->callback;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
92 case 0x10: return object->callback_param1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
93 case 0x18: return object->callback_param2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
94 case 0x1C: return object->last_value;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
95
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
96 case 0x7D: return _temp_store.Get(parameter);
6521
9aecb1a6dea5 (svn r9707) -Codechange: Add some support for NewGRF var 7D, temporary storage array.
peter1138 <peter1138@openttd.org>
parents: 6357
diff changeset
97
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
98 /* Not a common variable, so evalute the feature specific variables */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
99 default: return object->GetVariable(object, variable, parameter, available);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
100 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
101 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
102
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
103
7612
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
104 /**
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
105 * Rotate val rot times to the right
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
106 * @param val the value to rotate
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
107 * @param rot the amount of times to rotate
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
108 * @return the rotated value
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
109 */
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
110 static uint32 RotateRight(uint32 val, uint32 rot)
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
111 {
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
112 /* Do not rotate more than necessary */
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
113 rot %= 32;
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
114
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
115 return (val >> rot) | (val << (32 - rot));
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
116 }
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
117
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
118
5600
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
119 /* Evaluate an adjustment for a variable of the given size.
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
120 * U is the unsigned type and S is the signed type to use. */
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
121 template <typename U, typename S>
7610
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7609
diff changeset
122 static U EvalAdjustT(const DeterministicSpriteGroupAdjust *adjust, ResolverObject *object, U last_value, uint32 value)
5600
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
123 {
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
124 value >>= adjust->shift_num;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
125 value &= adjust->and_mask;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
126
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
127 if (adjust->type != DSGA_TYPE_NONE) value += (S)adjust->add_val;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
128
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
129 switch (adjust->type) {
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
130 case DSGA_TYPE_DIV: value /= (S)adjust->divmod_val; break;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
131 case DSGA_TYPE_MOD: value %= (U)adjust->divmod_val; break;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
132 case DSGA_TYPE_NONE: break;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
133 }
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
134
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
135 switch (adjust->operation) {
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
136 case DSGA_OP_ADD: return last_value + value;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
137 case DSGA_OP_SUB: return last_value - value;
5601
ca6b459bf488 (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar <celestar@openttd.org>
parents: 5600
diff changeset
138 case DSGA_OP_SMIN: return min((S)last_value, (S)value);
ca6b459bf488 (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar <celestar@openttd.org>
parents: 5600
diff changeset
139 case DSGA_OP_SMAX: return max((S)last_value, (S)value);
5600
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
140 case DSGA_OP_UMIN: return min((U)last_value, (U)value);
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
141 case DSGA_OP_UMAX: return max((U)last_value, (U)value);
6617
bfd51a1acb47 (svn r9837) -Fix: [NewGRF] Catch occurance of division-by-zero in varaction handling.
peter1138 <peter1138@openttd.org>
parents: 6521
diff changeset
142 case DSGA_OP_SDIV: return value == 0 ? (S)last_value : (S)last_value / (S)value;
bfd51a1acb47 (svn r9837) -Fix: [NewGRF] Catch occurance of division-by-zero in varaction handling.
peter1138 <peter1138@openttd.org>
parents: 6521
diff changeset
143 case DSGA_OP_SMOD: return value == 0 ? (S)last_value : (S)last_value % (S)value;
bfd51a1acb47 (svn r9837) -Fix: [NewGRF] Catch occurance of division-by-zero in varaction handling.
peter1138 <peter1138@openttd.org>
parents: 6521
diff changeset
144 case DSGA_OP_UDIV: return value == 0 ? (U)last_value : (U)last_value / (U)value;
bfd51a1acb47 (svn r9837) -Fix: [NewGRF] Catch occurance of division-by-zero in varaction handling.
peter1138 <peter1138@openttd.org>
parents: 6521
diff changeset
145 case DSGA_OP_UMOD: return value == 0 ? (U)last_value : (U)last_value % (U)value;
5600
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
146 case DSGA_OP_MUL: return last_value * value;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
147 case DSGA_OP_AND: return last_value & value;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
148 case DSGA_OP_OR: return last_value | value;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
149 case DSGA_OP_XOR: return last_value ^ value;
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
150 case DSGA_OP_STO: _temp_store.Store(value, last_value); return last_value;
6521
9aecb1a6dea5 (svn r9707) -Codechange: Add some support for NewGRF var 7D, temporary storage array.
peter1138 <peter1138@openttd.org>
parents: 6357
diff changeset
151 case DSGA_OP_RST: return value;
7610
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7609
diff changeset
152 case DSGA_OP_STOP: if (object->psa != NULL) object->psa->Store(value, last_value); return last_value;
7612
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
153 case DSGA_OP_ROR: return RotateRight(last_value, value);
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
154 case DSGA_OP_SCMP: return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
967884079cd0 (svn r11141) -Codechange: add support for NewGRF's varaction2 operators 11, 12 and 13.
rubidium <rubidium@openttd.org>
parents: 7610
diff changeset
155 case DSGA_OP_UCMP: return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
5600
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
156 default: return value;
37c5d98c3fa6 (svn r8054) -Codechange: Use a template function instead of a macro for evaluating NewGRF var adjusts
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
157 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
158 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
159
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
160
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
161 static inline const SpriteGroup *ResolveVariable(const SpriteGroup *group, ResolverObject *object)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
162 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
163 static SpriteGroup nvarzero;
5607
f746786ae8b3 (svn r8063) -Codechange: When evaluating newgrf varaction2s the 'last value' should start off at 0, and the result of the operation is remembered.
peter1138 <peter1138@openttd.org>
parents: 5606
diff changeset
164 uint32 last_value = 0;
5606
1176330381e4 (svn r8062) -Codechange: change newgrf varaction2 value from signed to unsigned
peter1138 <peter1138@openttd.org>
parents: 5604
diff changeset
165 uint32 value = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
166 uint i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
167
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
168 object->scope = group->g.determ.var_scope;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
169
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
170 for (i = 0; i < group->g.determ.num_adjusts; i++) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
171 DeterministicSpriteGroupAdjust *adjust = &group->g.determ.adjusts[i];
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
172
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
173 /* Try to get the variable. We shall assume it is available, unless told otherwise. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
174 bool available = true;
5617
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
175 if (adjust->variable == 0x7E) {
5622
b6656f3088b3 (svn r8081) -Fix (r8075): Use a copy of the resolver object instead of the using the existing one. This fixes problems with the object scope setting.
peter1138 <peter1138@openttd.org>
parents: 5617
diff changeset
176 ResolverObject subobject = *object;
8685
a148a6ee005d (svn r12352) -Fix: Some callback-results were treated as 8 bit, when they were 15 bit, and vice versa.
frosch <frosch@openttd.org>
parents: 8561
diff changeset
177 subobject.procedure_call = true;
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
178 const SpriteGroup *subgroup = Resolve(adjust->subroutine, &subobject);
5617
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
179 if (subgroup == NULL || subgroup->type != SGT_CALLBACK) {
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
180 value = CALLBACK_FAILED;
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
181 } else {
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
182 value = subgroup->g.callback.result;
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
183 }
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
184 } else {
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
185 value = GetVariable(object, adjust->variable, adjust->parameter, &available);
ef79a2605252 (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros <maedhros@openttd.org>
parents: 5607
diff changeset
186 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
187
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
188 if (!available) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
189 /* Unsupported property: skip further processing and return either
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
190 * the group from the first range or the default group. */
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
191 return Resolve(group->g.determ.num_ranges > 0 ? group->g.determ.ranges[0].group : group->g.determ.default_group, object);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
192 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
193
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
194 switch (group->g.determ.size) {
7610
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7609
diff changeset
195 case DSG_SIZE_BYTE: value = EvalAdjustT<uint8, int8> (adjust, object, last_value, value); break;
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7609
diff changeset
196 case DSG_SIZE_WORD: value = EvalAdjustT<uint16, int16>(adjust, object, last_value, value); break;
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7609
diff changeset
197 case DSG_SIZE_DWORD: value = EvalAdjustT<uint32, int32>(adjust, object, last_value, value); break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
198 default: NOT_REACHED(); break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
199 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
200 last_value = value;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
201 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
202
5607
f746786ae8b3 (svn r8063) -Codechange: When evaluating newgrf varaction2s the 'last value' should start off at 0, and the result of the operation is remembered.
peter1138 <peter1138@openttd.org>
parents: 5606
diff changeset
203 object->last_value = last_value;
f746786ae8b3 (svn r8063) -Codechange: When evaluating newgrf varaction2s the 'last value' should start off at 0, and the result of the operation is remembered.
peter1138 <peter1138@openttd.org>
parents: 5606
diff changeset
204
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
205 if (group->g.determ.num_ranges == 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
206 /* nvar == 0 is a special case -- we turn our value into a callback result */
9088
5b5958727985 (svn r12947) -Fix: keep only first 15 bits for non failed callback results
glx <glx@openttd.org>
parents: 9020
diff changeset
207 if (value != CALLBACK_FAILED) value = GB(value, 0, 15);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
208 nvarzero.type = SGT_CALLBACK;
9020
94bb527c979f (svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium <rubidium@openttd.org>
parents: 8968
diff changeset
209 nvarzero.g.callback.result = value;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
210 return &nvarzero;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
211 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
212
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
213 for (i = 0; i < group->g.determ.num_ranges; i++) {
5606
1176330381e4 (svn r8062) -Codechange: change newgrf varaction2 value from signed to unsigned
peter1138 <peter1138@openttd.org>
parents: 5604
diff changeset
214 if (group->g.determ.ranges[i].low <= value && value <= group->g.determ.ranges[i].high) {
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
215 return Resolve(group->g.determ.ranges[i].group, object);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
216 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
217 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
218
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
219 return Resolve(group->g.determ.default_group, object);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
220 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
221
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
222
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
223 static inline const SpriteGroup *ResolveRandom(const SpriteGroup *group, ResolverObject *object)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
224 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
225 uint32 mask;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
226 byte index;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
227
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
228 object->scope = group->g.random.var_scope;
8756
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8714
diff changeset
229 object->count = group->g.random.count;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
230
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
231 if (object->trigger != 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
232 /* Handle triggers */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
233 /* Magic code that may or may not do the right things... */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
234 byte waiting_triggers = object->GetTriggers(object);
7862
f5474c8b9b6f (svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium <rubidium@openttd.org>
parents: 7860
diff changeset
235 byte match = group->g.random.triggers & (waiting_triggers | object->trigger);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
236 bool res;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
237
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
238 res = (group->g.random.cmp_mode == RSG_CMP_ANY) ?
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
239 (match != 0) : (match == group->g.random.triggers);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
240
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
241 if (res) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
242 waiting_triggers &= ~match;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
243 object->reseed |= (group->g.random.num_groups - 1) << group->g.random.lowest_randbit;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
244 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
245 waiting_triggers |= object->trigger;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
246 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
247
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
248 object->SetTriggers(object, waiting_triggers);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
249 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
250
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
251 mask = (group->g.random.num_groups - 1) << group->g.random.lowest_randbit;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
252 index = (object->GetRandomBits(object) & mask) >> group->g.random.lowest_randbit;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
253
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
254 return Resolve(group->g.random.groups[index], object);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
255 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
256
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
257
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
258 /* ResolverObject (re)entry point */
7609
9e4c3b886ccb (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7600
diff changeset
259 const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
260 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
261 /* We're called even if there is no group, so quietly return nothing */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
262 if (group == NULL) return NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
264 switch (group->type) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265 case SGT_REAL: return object->ResolveReal(object, group);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
266 case SGT_DETERMINISTIC: return ResolveVariable(group, object);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
267 case SGT_RANDOMIZED: return ResolveRandom(group, object);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
268 default: return group;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
269 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
270 }