158 |
159 |
159 return false; |
160 return false; |
160 } |
161 } |
161 #endif |
162 #endif |
162 |
163 |
163 int Aircraft::GetImage(Direction direction) const |
164 SpriteID Aircraft::GetImage(Direction direction) const |
164 { |
165 { |
165 int spritenum = this->spritenum; |
166 uint8 spritenum = this->spritenum; |
166 |
167 |
167 if (is_custom_sprite(spritenum)) { |
168 if (is_custom_sprite(spritenum)) { |
168 int sprite = GetCustomVehicleSprite(this, direction); |
169 SpriteID sprite = GetCustomVehicleSprite(this, direction); |
169 |
|
170 if (sprite != 0) return sprite; |
170 if (sprite != 0) return sprite; |
|
171 |
171 spritenum = _orig_aircraft_vehicle_info[this->engine_type - AIRCRAFT_ENGINES_INDEX].image_index; |
172 spritenum = _orig_aircraft_vehicle_info[this->engine_type - AIRCRAFT_ENGINES_INDEX].image_index; |
172 } |
173 } |
|
174 |
173 return direction + _aircraft_sprite[spritenum]; |
175 return direction + _aircraft_sprite[spritenum]; |
174 } |
176 } |
175 |
177 |
176 SpriteID GetRotorImage(const Vehicle *v) |
178 SpriteID GetRotorImage(const Vehicle *v) |
177 { |
179 { |
178 assert(v->subtype == AIR_HELICOPTER); |
180 assert(v->subtype == AIR_HELICOPTER); |
179 |
181 |
180 const Vehicle *w = v->Next()->Next(); |
182 const Vehicle *w = v->Next()->Next(); |
181 if (is_custom_sprite(v->spritenum)) { |
183 if (is_custom_sprite(v->spritenum)) { |
182 SpriteID spritenum = GetCustomRotorSprite(v, false); |
184 SpriteID sprite = GetCustomRotorSprite(v, false); |
183 if (spritenum != 0) return spritenum; |
185 if (sprite != 0) return sprite; |
184 } |
186 } |
185 |
187 |
186 /* Return standard rotor sprites if there are no custom sprites for this helicopter */ |
188 /* Return standard rotor sprites if there are no custom sprites for this helicopter */ |
187 return SPR_ROTOR_STOPPED + w->u.air.state; |
189 return SPR_ROTOR_STOPPED + w->u.air.state; |
188 } |
190 } |
189 |
191 |
|
192 static SpriteID GetAircraftIcon(EngineID engine) |
|
193 { |
|
194 uint8 spritenum = AircraftVehInfo(engine)->image_index; |
|
195 |
|
196 if (is_custom_sprite(spritenum)) { |
|
197 SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W); |
|
198 if (sprite != 0) return sprite; |
|
199 |
|
200 spritenum = _orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].image_index; |
|
201 } |
|
202 |
|
203 return 6 + _aircraft_sprite[spritenum]; |
|
204 } |
|
205 |
190 void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal) |
206 void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal) |
191 { |
207 { |
192 const AircraftVehicleInfo* avi = AircraftVehInfo(engine); |
208 DrawSprite(GetAircraftIcon(engine), pal, x, y); |
193 int spritenum = avi->image_index; |
209 |
194 SpriteID sprite = (6 + _aircraft_sprite[spritenum]); |
210 if (!(AircraftVehInfo(engine)->subtype & AIR_CTOL)) { |
195 |
|
196 if (is_custom_sprite(spritenum)) { |
|
197 sprite = GetCustomVehicleIcon(engine, DIR_W); |
|
198 if (sprite == 0) { |
|
199 spritenum = _orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].image_index; |
|
200 sprite = (6 + _aircraft_sprite[spritenum]); |
|
201 } |
|
202 } |
|
203 |
|
204 DrawSprite(sprite, pal, x, y); |
|
205 |
|
206 if (!(avi->subtype & AIR_CTOL)) { |
|
207 SpriteID rotor_sprite = GetCustomRotorIcon(engine); |
211 SpriteID rotor_sprite = GetCustomRotorIcon(engine); |
208 if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED; |
212 if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED; |
209 DrawSprite(rotor_sprite, PAL_NONE, x, y - 5); |
213 DrawSprite(rotor_sprite, PAL_NONE, x, y - 5); |
210 } |
214 } |
211 } |
215 } |
215 * @param width The width of the sprite |
219 * @param width The width of the sprite |
216 * @param height The height of the sprite |
220 * @param height The height of the sprite |
217 */ |
221 */ |
218 void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height) |
222 void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height) |
219 { |
223 { |
220 const AircraftVehicleInfo* avi = AircraftVehInfo(engine); |
224 const Sprite *spr = GetSprite(GetAircraftIcon(engine)); |
221 int spritenum = avi->image_index; |
225 |
222 SpriteID sprite = (6 + _aircraft_sprite[spritenum]); |
226 width = spr->width; |
223 |
|
224 if (is_custom_sprite(spritenum)) { |
|
225 sprite = GetCustomVehicleIcon(engine, DIR_W); |
|
226 if (sprite == 0) { |
|
227 spritenum = _orig_aircraft_vehicle_info[engine - AIRCRAFT_ENGINES_INDEX].image_index; |
|
228 sprite = (6 + _aircraft_sprite[spritenum]); |
|
229 } |
|
230 } |
|
231 |
|
232 const Sprite *spr = GetSprite(sprite); |
|
233 |
|
234 width = spr->width ; |
|
235 height = spr->height; |
227 height = spr->height; |
236 } |
228 } |
237 |
229 |
238 static CommandCost EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi) |
230 static CommandCost EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi) |
239 { |
231 { |
526 return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT); |
518 return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT); |
527 |
519 |
528 /* Check if this aircraft can be started/stopped. The callback will fail or |
520 /* Check if this aircraft can be started/stopped. The callback will fail or |
529 * return 0xFF if it can. */ |
521 * return 0xFF if it can. */ |
530 uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
522 uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
531 if (callback != CALLBACK_FAILED && callback != 0xFF) { |
523 if (callback != CALLBACK_FAILED && GB(callback, 0, 8) != 0xFF) { |
532 StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
524 StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
533 return_cmd_error(error); |
525 return_cmd_error(error); |
534 } |
526 } |
535 |
527 |
536 if (flags & DC_EXEC) { |
528 if (flags & DC_EXEC) { |