Update: Translations from eints
[openttd-github.git] / src / town_map.h
blob39131c5ec1b2d3d7161ea83ede5583dfb9010f66
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file town_map.h Accessors for towns */
10 #ifndef TOWN_MAP_H
11 #define TOWN_MAP_H
13 #include "road_map.h"
14 #include "house.h"
15 #include "timer/timer_game_calendar.h"
17 /**
18 * Get the index of which town this house/street is attached to.
19 * @param t the tile
20 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_ROAD) but not a road depot
21 * @return TownID
23 inline TownID GetTownIndex(Tile t)
25 assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
26 return t.m2();
29 /**
30 * Set the town index for a road or house tile.
31 * @param t the tile
32 * @param index the index of the town
33 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_ROAD) but not a road depot
35 inline void SetTownIndex(Tile t, TownID index)
37 assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
38 t.m2() = index;
41 /**
42 * Get the type of this house, which is an index into the house spec array
43 * without doing any NewGRF related translations.
44 * @param t the tile
45 * @pre IsTileType(t, MP_HOUSE)
46 * @return house type
48 inline HouseID GetCleanHouseType(Tile t)
50 assert(IsTileType(t, MP_HOUSE));
51 return t.m4() | (GB(t.m3(), 6, 1) << 8);
54 /**
55 * Get the type of this house, which is an index into the house spec array
56 * @param t the tile
57 * @pre IsTileType(t, MP_HOUSE)
58 * @return house type
60 inline HouseID GetHouseType(Tile t)
62 return GetTranslatedHouseID(GetCleanHouseType(t));
65 /**
66 * Set the house type.
67 * @param t the tile
68 * @param house_id the new house type
69 * @pre IsTileType(t, MP_HOUSE)
71 inline void SetHouseType(Tile t, HouseID house_id)
73 assert(IsTileType(t, MP_HOUSE));
74 t.m4() = GB(house_id, 0, 8);
75 SB(t.m3(), 6, 1, GB(house_id, 8, 1));
78 /**
79 * Check if the lift of this animated house has a destination
80 * @param t the tile
81 * @return has destination
83 inline bool LiftHasDestination(Tile t)
85 return HasBit(t.m7(), 0);
88 /**
89 * Set the new destination of the lift for this animated house, and activate
90 * the LiftHasDestination bit.
91 * @param t the tile
92 * @param dest new destination
94 inline void SetLiftDestination(Tile t, uint8_t dest)
96 SetBit(t.m7(), 0);
97 SB(t.m7(), 1, 3, dest);
101 * Get the current destination for this lift
102 * @param t the tile
103 * @return destination
105 inline uint8_t GetLiftDestination(Tile t)
107 return GB(t.m7(), 1, 3);
111 * Stop the lift of this animated house from moving.
112 * Clears the first 4 bits of m7 at once, clearing the LiftHasDestination bit
113 * and the destination.
114 * @param t the tile
116 inline void HaltLift(Tile t)
118 SB(t.m7(), 0, 4, 0);
122 * Get the position of the lift on this animated house
123 * @param t the tile
124 * @return position, from 0 to 36
126 inline uint8_t GetLiftPosition(Tile t)
128 return GB(t.m6(), 2, 6);
132 * Set the position of the lift on this animated house
133 * @param t the tile
134 * @param pos position, from 0 to 36
136 inline void SetLiftPosition(Tile t, uint8_t pos)
138 SB(t.m6(), 2, 6, pos);
142 * Get the completion of this house
143 * @param t the tile
144 * @return true if it is, false if it is not
146 inline bool IsHouseCompleted(Tile t)
148 assert(IsTileType(t, MP_HOUSE));
149 return HasBit(t.m3(), 7);
153 * Mark this house as been completed
154 * @param t the tile
155 * @param status
157 inline void SetHouseCompleted(Tile t, bool status)
159 assert(IsTileType(t, MP_HOUSE));
160 SB(t.m3(), 7, 1, !!status);
164 * House Construction Scheme.
165 * Construction counter, for buildings under construction. Incremented on every
166 * periodic tile processing.
167 * On wraparound, the stage of building in is increased.
168 * GetHouseBuildingStage is taking care of the real stages,
169 * (as the sprite for the next phase of house building)
170 * (Get|Inc)HouseConstructionTick is simply a tick counter between the
171 * different stages
175 * Gets the building stage of a house
176 * Since the stage is used for determining what sprite to use,
177 * if the house is complete (and that stage no longer is available),
178 * fool the system by returning the TOWN_HOUSE_COMPLETE (3),
179 * thus showing a beautiful complete house.
180 * @param t the tile of the house to get the building stage of
181 * @pre IsTileType(t, MP_HOUSE)
182 * @return the building stage of the house
184 inline uint8_t GetHouseBuildingStage(Tile t)
186 assert(IsTileType(t, MP_HOUSE));
187 return IsHouseCompleted(t) ? (uint8_t)TOWN_HOUSE_COMPLETED : GB(t.m5(), 3, 2);
191 * Gets the construction stage of a house
192 * @param t the tile of the house to get the construction stage of
193 * @pre IsTileType(t, MP_HOUSE)
194 * @return the construction stage of the house
196 inline uint8_t GetHouseConstructionTick(Tile t)
198 assert(IsTileType(t, MP_HOUSE));
199 return IsHouseCompleted(t) ? 0 : GB(t.m5(), 0, 3);
203 * Sets the increment stage of a house
204 * It is working with the whole counter + stage 5 bits, making it
205 * easier to work: the wraparound is automatic.
206 * @param t the tile of the house to increment the construction stage of
207 * @pre IsTileType(t, MP_HOUSE)
209 inline void IncHouseConstructionTick(Tile t)
211 assert(IsTileType(t, MP_HOUSE));
212 AB(t.m5(), 0, 5, 1);
214 if (GB(t.m5(), 3, 2) == TOWN_HOUSE_COMPLETED) {
215 /* House is now completed.
216 * Store the year of construction as well, for newgrf house purpose */
217 SetHouseCompleted(t, true);
222 * Sets the age of the house to zero.
223 * Needs to be called after the house is completed. During construction stages the map space is used otherwise.
224 * @param t the tile of this house
225 * @pre IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)
227 inline void ResetHouseAge(Tile t)
229 assert(IsTileType(t, MP_HOUSE) && IsHouseCompleted(t));
230 t.m5() = 0;
234 * Increments the age of the house.
235 * @param t the tile of this house
236 * @pre IsTileType(t, MP_HOUSE)
238 inline void IncrementHouseAge(Tile t)
240 assert(IsTileType(t, MP_HOUSE));
241 if (IsHouseCompleted(t) && t.m5() < 0xFF) t.m5()++;
245 * Get the age of the house
246 * @param t the tile of this house
247 * @pre IsTileType(t, MP_HOUSE)
248 * @return year
250 inline TimerGameCalendar::Year GetHouseAge(Tile t)
252 assert(IsTileType(t, MP_HOUSE));
253 return IsHouseCompleted(t) ? t.m5() : 0;
257 * Set the random bits for this house.
258 * This is required for newgrf house
259 * @param t the tile of this house
260 * @param random the new random bits
261 * @pre IsTileType(t, MP_HOUSE)
263 inline void SetHouseRandomBits(Tile t, uint8_t random)
265 assert(IsTileType(t, MP_HOUSE));
266 t.m1() = random;
270 * Get the random bits for this house.
271 * This is required for newgrf house
272 * @param t the tile of this house
273 * @pre IsTileType(t, MP_HOUSE)
274 * @return random bits
276 inline uint8_t GetHouseRandomBits(Tile t)
278 assert(IsTileType(t, MP_HOUSE));
279 return t.m1();
283 * Set the activated triggers bits for this house.
284 * This is required for newgrf house
285 * @param t the tile of this house
286 * @param triggers the activated triggers
287 * @pre IsTileType(t, MP_HOUSE)
289 inline void SetHouseTriggers(Tile t, uint8_t triggers)
291 assert(IsTileType(t, MP_HOUSE));
292 SB(t.m3(), 0, 5, triggers);
296 * Get the already activated triggers bits for this house.
297 * This is required for newgrf house
298 * @param t the tile of this house
299 * @pre IsTileType(t, MP_HOUSE)
300 * @return triggers
302 inline uint8_t GetHouseTriggers(Tile t)
304 assert(IsTileType(t, MP_HOUSE));
305 return GB(t.m3(), 0, 5);
309 * Get the amount of time remaining before the tile loop processes this tile.
310 * @param t the house tile
311 * @pre IsTileType(t, MP_HOUSE)
312 * @return time remaining
314 inline uint8_t GetHouseProcessingTime(Tile t)
316 assert(IsTileType(t, MP_HOUSE));
317 return GB(t.m6(), 2, 6);
321 * Set the amount of time remaining before the tile loop processes this tile.
322 * @param t the house tile
323 * @param time the time to be set
324 * @pre IsTileType(t, MP_HOUSE)
326 inline void SetHouseProcessingTime(Tile t, uint8_t time)
328 assert(IsTileType(t, MP_HOUSE));
329 SB(t.m6(), 2, 6, time);
333 * Decrease the amount of time remaining before the tile loop processes this tile.
334 * @param t the house tile
335 * @pre IsTileType(t, MP_HOUSE)
337 inline void DecHouseProcessingTime(Tile t)
339 assert(IsTileType(t, MP_HOUSE));
340 t.m6() -= 1 << 2;
344 * Make the tile a house.
345 * @param t tile index
346 * @param tid Town index
347 * @param counter of construction step
348 * @param stage of construction (used for drawing)
349 * @param type of house. Index into house specs array
350 * @param random_bits required for newgrf houses
351 * @pre IsTileType(t, MP_CLEAR)
353 inline void MakeHouseTile(Tile t, TownID tid, uint8_t counter, uint8_t stage, HouseID type, uint8_t random_bits)
355 assert(IsTileType(t, MP_CLEAR));
357 SetTileType(t, MP_HOUSE);
358 t.m1() = random_bits;
359 t.m2() = tid;
360 t.m3() = 0;
361 SetHouseType(t, type);
362 SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
363 t.m5() = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
364 SetAnimationFrame(t, 0);
365 SetHouseProcessingTime(t, HouseSpec::Get(type)->processing_time);
368 #endif /* TOWN_MAP_H */