changeset 193 | 0a7025304867 |
parent 164 | 0cbdf3c9bde1 |
child 337 | cbe0c766c947 |
192:614bba52258d | 193:0a7025304867 |
---|---|
273 // the AI doesn't click on a tile to build airplanes, so the below code will |
273 // the AI doesn't click on a tile to build airplanes, so the below code will |
274 // never work. Therefore just assume the AI's planes always come from Hangar0 |
274 // never work. Therefore just assume the AI's planes always come from Hangar0 |
275 // On hold for NewAI |
275 // On hold for NewAI |
276 v->u.air.pos = (!_patches.ainew_active && _is_ai_player) ? 0:MAX_ELEMENTS; |
276 v->u.air.pos = (!_patches.ainew_active && _is_ai_player) ? 0:MAX_ELEMENTS; |
277 |
277 |
278 /* When we click on hangar we know the tile (it is in var 'tile')it is on. By that we know |
278 /* When we click on hangar we know the tile (it is in var 'tile')it is on. By that we know |
279 its position in the array of depots the airport has.....we can search |
279 its position in the array of depots the airport has.....we can search |
280 ->layout for #th position of depot. Since layout must start with depots, it is simple |
280 ->layout for #th position of depot. Since layout must start with depots, it is simple |
281 */ |
281 */ |
282 { |
282 { |
283 Station *st; |
283 Station *st; |
284 const AirportFTAClass *Airport; |
284 const AirportFTAClass *Airport; |
540 if ((v->next_order & (OT_MASK | OF_FULL_LOAD)) == (OT_GOTO_DEPOT | OF_FULL_LOAD)) |
540 if ((v->next_order & (OT_MASK | OF_FULL_LOAD)) == (OT_GOTO_DEPOT | OF_FULL_LOAD)) |
541 return; |
541 return; |
542 |
542 |
543 if (_patches.gotodepot && ScheduleHasDepotOrders(v->schedule_ptr)) |
543 if (_patches.gotodepot && ScheduleHasDepotOrders(v->schedule_ptr)) |
544 return; |
544 return; |
545 |
545 |
546 st = DEREF_STATION(v->next_order_param); |
546 st = DEREF_STATION(v->next_order_param); |
547 // only goto depot if the target airport has terminals (eg. it is airport) |
547 // only goto depot if the target airport has terminals (eg. it is airport) |
548 if (st->xy != 0 && st->airport_tile != 0 && GetAirport(st->airport_type)->nofterminals != 0) { |
548 if (st->xy != 0 && st->airport_tile != 0 && GetAirport(st->airport_type)->nofterminals != 0) { |
549 // printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index); |
549 // printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index); |
550 // v->u.air.targetairport = st->index; |
550 // v->u.air.targetairport = st->index; |
619 u = v->next->next; |
619 u = v->next->next; |
620 |
620 |
621 if (u->vehstatus & VS_HIDDEN) |
621 if (u->vehstatus & VS_HIDDEN) |
622 return; |
622 return; |
623 |
623 |
624 // if true, helicopter rotors do not rotate. This should only be the case if a helicopter is |
624 // if true, helicopter rotors do not rotate. This should only be the case if a helicopter is |
625 // loading/unloading at a terminal or stopped |
625 // loading/unloading at a terminal or stopped |
626 if ((v->next_order&OT_MASK) == OT_LOADING || (v->vehstatus&VS_STOPPED)) { |
626 if ((v->next_order&OT_MASK) == OT_LOADING || (v->vehstatus&VS_STOPPED)) { |
627 if (u->cur_speed != 0) { |
627 if (u->cur_speed != 0) { |
628 u->cur_speed++; |
628 u->cur_speed++; |
629 if (u->cur_speed >= 0x80 && u->cur_image == 0xF40) { |
629 if (u->cur_speed >= 0x80 && u->cur_image == 0xF40) { |
733 uint spd = v->acceleration * 2; |
733 uint spd = v->acceleration * 2; |
734 byte t; |
734 byte t; |
735 |
735 |
736 v->subspeed = (t=v->subspeed) + (byte)spd; |
736 v->subspeed = (t=v->subspeed) + (byte)spd; |
737 spd = min( v->cur_speed + (spd >> 8) + (v->subspeed < t), v->max_speed); |
737 spd = min( v->cur_speed + (spd >> 8) + (v->subspeed < t), v->max_speed); |
738 |
738 |
739 // adjust speed for broken vehicles |
739 // adjust speed for broken vehicles |
740 if(v->vehstatus&VS_AIRCRAFT_BROKEN) spd = min(spd, 27); |
740 if(v->vehstatus&VS_AIRCRAFT_BROKEN) spd = min(spd, 27); |
741 |
741 |
742 //updates statusbar only if speed have changed to save CPU time |
742 //updates statusbar only if speed have changed to save CPU time |
743 if (spd != v->cur_speed) { |
743 if (spd != v->cur_speed) { |
873 if (v->cur_speed > 12) |
873 if (v->cur_speed > 12) |
874 v->cur_speed = 12; |
874 v->cur_speed = 12; |
875 |
875 |
876 // Change direction smoothly to final direction. |
876 // Change direction smoothly to final direction. |
877 dirdiff = amd->direction - v->direction; |
877 dirdiff = amd->direction - v->direction; |
878 // if distance is 0, and plane points in right direction, no point in calling |
878 // if distance is 0, and plane points in right direction, no point in calling |
879 // UpdateAircraftSpeed(). So do it only afterwards |
879 // UpdateAircraftSpeed(). So do it only afterwards |
880 if (dirdiff == 0) { |
880 if (dirdiff == 0) { |
881 v->cur_speed = 0; |
881 v->cur_speed = 0; |
882 return true; |
882 return true; |
883 } |
883 } |
1059 // OT_GOTO_DEPOT, OT_LOADING |
1059 // OT_GOTO_DEPOT, OT_LOADING |
1060 if ((v->next_order & OT_MASK) >= OT_GOTO_DEPOT && (v->next_order & OT_MASK) <= OT_LOADING) { |
1060 if ((v->next_order & OT_MASK) >= OT_GOTO_DEPOT && (v->next_order & OT_MASK) <= OT_LOADING) { |
1061 if ((v->next_order & (OT_MASK|OF_UNLOAD)) != (OT_GOTO_DEPOT|OF_UNLOAD)) |
1061 if ((v->next_order & (OT_MASK|OF_UNLOAD)) != (OT_GOTO_DEPOT|OF_UNLOAD)) |
1062 return; |
1062 return; |
1063 } |
1063 } |
1064 |
1064 |
1065 if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) && |
1065 if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) && |
1066 SERVICE_INTERVAL) { |
1066 SERVICE_INTERVAL) { |
1067 v->cur_order_index++; |
1067 v->cur_order_index++; |
1068 } |
1068 } |
1069 |
1069 |
1215 static void AircraftEnterHangar(Vehicle *v) |
1215 static void AircraftEnterHangar(Vehicle *v) |
1216 { |
1216 { |
1217 byte old_order; |
1217 byte old_order; |
1218 |
1218 |
1219 ServiceAircraft(v); |
1219 ServiceAircraft(v); |
1220 |
1220 |
1221 MaybeRenewVehicle(v, EstimateAircraftCost(v->engine_type)); |
1221 MaybeRenewVehicle(v, EstimateAircraftCost(v->engine_type)); |
1222 |
1222 |
1223 if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT) { |
1223 if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT) { |
1224 InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
1224 InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
1225 |
1225 |
1226 old_order = v->next_order; |
1226 old_order = v->next_order; |
1227 v->next_order = OT_NOTHING; |
1227 v->next_order = OT_NOTHING; |
1228 |
1228 |
1229 if (old_order & OF_UNLOAD) { v->cur_order_index++; } |
1229 if (old_order & OF_UNLOAD) { v->cur_order_index++; } |
1230 |
1230 |
1231 else if (old_order & OF_FULL_LOAD) { // force depot visit |
1231 else if (old_order & OF_FULL_LOAD) { // force depot visit |
1232 v->vehstatus |= VS_STOPPED; |
1232 v->vehstatus |= VS_STOPPED; |
1233 |
1233 |
1234 if (v->owner == _local_player) { |
1234 if (v->owner == _local_player) { |
1235 SET_DPARAM16(0, v->unitnumber); |
1235 SET_DPARAM16(0, v->unitnumber); |
1690 } |
1690 } |
1691 } |
1691 } |
1692 return false; |
1692 return false; |
1693 } |
1693 } |
1694 |
1694 |
1695 static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport) |
1695 static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport) |
1696 { |
1696 { |
1697 byte nofterminalspergroup, i; |
1697 byte nofterminalspergroup, i; |
1698 AirportFTA *temp; |
1698 AirportFTA *temp; |
1699 Station *st; |
1699 Station *st; |
1700 |
1700 |
1701 /* example of more terminalgroups |
1701 /* example of more terminalgroups |
1702 {0,HANGAR,NOTHING_block,1}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER_block,1}, {0,0,N,1}, |
1702 {0,HANGAR,NOTHING_block,1}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER_block,1}, {0,0,N,1}, |
1703 Heading 255 denotes a group. We see 2 groups here: |
1703 Heading 255 denotes a group. We see 2 groups here: |
1704 1. group 0 -- TERM_GROUP1_block (check block) |
1704 1. group 0 -- TERM_GROUP1_block (check block) |
1705 2. group 1 -- TERM_GROUP2_ENTER_block (check block) |
1705 2. group 1 -- TERM_GROUP2_ENTER_block (check block) |
1706 First in line is checked first, group 0. If the block (TERM_GROUP1_block) is free, it |
1706 First in line is checked first, group 0. If the block (TERM_GROUP1_block) is free, it |
1707 looks at the corresponding terminals of that group. If no free ones are found, other |
1707 looks at the corresponding terminals of that group. If no free ones are found, other |
1708 possible groups are checked (in this case group 1, since that is after group 0). If that |
1708 possible groups are checked (in this case group 1, since that is after group 0). If that |
1709 fails, then attempt fails and plane waits |
1709 fails, then attempt fails and plane waits |
1710 */ |
1710 */ |
1711 if (Airport->nofterminalgroups > 1) { |
1711 if (Airport->nofterminalgroups > 1) { |
1712 st = DEREF_STATION(v->u.air.targetairport); |
1712 st = DEREF_STATION(v->u.air.targetairport); |
1713 nofterminalspergroup = Airport->nofterminals / Airport->nofterminalgroups; |
1713 nofterminalspergroup = Airport->nofterminals / Airport->nofterminalgroups; |
1729 |
1729 |
1730 // if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max) |
1730 // if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max) |
1731 return FreeTerminal(v, 0, Airport->nofterminals); |
1731 return FreeTerminal(v, 0, Airport->nofterminals); |
1732 } |
1732 } |
1733 |
1733 |
1734 static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport) |
1734 static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport) |
1735 { |
1735 { |
1736 Station *st; |
1736 Station *st; |
1737 byte nofhelipadspergroup, i; |
1737 byte nofhelipadspergroup, i; |
1738 AirportFTA *temp; |
1738 AirportFTA *temp; |
1739 |
1739 |
1845 v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving |
1845 v_oldstyle->vehstatus &= ~VS_STOPPED; // make airplane moving |
1846 v_oldstyle->u.air.state = FLYING; |
1846 v_oldstyle->u.air.state = FLYING; |
1847 AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport |
1847 AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport |
1848 GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting) |
1848 GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting) |
1849 v_oldstyle->tile = 0; // aircraft in air is tile=0 |
1849 v_oldstyle->tile = 0; // aircraft in air is tile=0 |
1850 |
1850 |
1851 // correct speed of helicopter-rotors |
1851 // correct speed of helicopter-rotors |
1852 if (v_oldstyle->subtype == 0) {v_oldstyle->next->next->cur_speed = 32;} |
1852 if (v_oldstyle->subtype == 0) {v_oldstyle->next->next->cur_speed = 32;} |
1853 |
1853 |
1854 // set new position x,y,z |
1854 // set new position x,y,z |
1855 SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); |
1855 SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); |
1856 } |
1856 } |
1857 } |
1857 } |
1858 } |
1858 } |
1859 |
1859 |
1860 void UpdateAirplanesOnNewStation(Station *st) |
1860 void UpdateAirplanesOnNewStation(Station *st) |
1861 { |
1861 { |
1862 GetNewVehiclePosResult gp; |
1862 GetNewVehiclePosResult gp; |
1863 Vehicle *v; |
1863 Vehicle *v; |
1864 byte takeofftype; |
1864 byte takeofftype; |
1865 uint16 cnt; |
1865 uint16 cnt; |