796 SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode?0:32)); |
796 SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode?0:32)); |
797 |
797 |
798 if (s->age < 12) { |
798 if (s->age < 12) { |
799 if (!(s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL)) { |
799 if (!(s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL)) { |
800 SetDParam(1, STR_2029); |
800 SetDParam(1, STR_2029); |
801 i = DEREF_INDUSTRY(s->from); |
801 i = GetIndustry(s->from); |
802 tile = i->xy; |
802 tile = i->xy; |
803 SetDParam(2, i->town->townnametype); |
803 SetDParam(2, i->town->townnametype); |
804 SetDParam(3, i->town->townnameparts); |
804 SetDParam(3, i->town->townnameparts); |
805 |
805 |
806 SetDParam(4, i->type + STR_4802_COAL_MINE); |
806 SetDParam(4, i->type + STR_4802_COAL_MINE); |
807 |
807 |
808 if (s->cargo_type != CT_GOODS && s->cargo_type != CT_FOOD) { |
808 if (s->cargo_type != CT_GOODS && s->cargo_type != CT_FOOD) { |
809 SetDParam(5, STR_2029); |
809 SetDParam(5, STR_2029); |
810 i = DEREF_INDUSTRY(s->to); |
810 i = GetIndustry(s->to); |
811 tile2 = i->xy; |
811 tile2 = i->xy; |
812 SetDParam(8, i->type + STR_4802_COAL_MINE); |
812 SetDParam(8, i->type + STR_4802_COAL_MINE); |
813 SetDParam(6, i->town->townnametype); |
813 SetDParam(6, i->town->townnametype); |
814 SetDParam(7, i->town->townnameparts); |
814 SetDParam(7, i->town->townnameparts); |
815 } else { |
815 } else { |
816 t = DEREF_TOWN(s->to); |
816 t = GetTown(s->to); |
817 tile2 = t->xy; |
817 tile2 = t->xy; |
818 SetDParam(5, t->townnametype); |
818 SetDParam(5, t->townnametype); |
819 SetDParam(6, t->townnameparts); |
819 SetDParam(6, t->townnameparts); |
820 } |
820 } |
821 } else { |
821 } else { |
822 t = DEREF_TOWN(s->from); |
822 t = GetTown(s->from); |
823 tile = t->xy; |
823 tile = t->xy; |
824 SetDParam(1, t->townnametype); |
824 SetDParam(1, t->townnametype); |
825 SetDParam(2, t->townnameparts); |
825 SetDParam(2, t->townnameparts); |
826 |
826 |
827 t = DEREF_TOWN(s->to); |
827 t = GetTown(s->to); |
828 tile2 = t->xy; |
828 tile2 = t->xy; |
829 SetDParam(3, t->townnametype); |
829 SetDParam(3, t->townnametype); |
830 SetDParam(4, t->townnameparts); |
830 SetDParam(4, t->townnameparts); |
831 } |
831 } |
832 } else { |
832 } else { |
833 st = DEREF_STATION(s->from); |
833 st = GetStation(s->from); |
834 tile = st->xy; |
834 tile = st->xy; |
835 SetDParam(1, st->index); |
835 SetDParam(1, st->index); |
836 |
836 |
837 st = DEREF_STATION(s->to); |
837 st = GetStation(s->to); |
838 tile2 = st->xy; |
838 tile2 = st->xy; |
839 SetDParam(2, st->index); |
839 SetDParam(2, st->index); |
840 } |
840 } |
841 |
841 |
842 tp.a = tile; |
842 tp.a = tile; |
886 { |
886 { |
887 Town *from,*to; |
887 Town *from,*to; |
888 |
888 |
889 fr->distance = (uint)-1; |
889 fr->distance = (uint)-1; |
890 |
890 |
891 fr->from = from = DEREF_TOWN(RandomRange(_total_towns)); |
891 fr->from = from = GetTown(RandomRange(_total_towns)); |
892 if (from->xy == 0 || from->population < 400) |
892 if (from->xy == 0 || from->population < 400) |
893 return; |
893 return; |
894 |
894 |
895 fr->to = to = DEREF_TOWN(RandomRange(_total_towns)); |
895 fr->to = to = GetTown(RandomRange(_total_towns)); |
896 if (from==to || to->xy == 0 || to->population < 400 || to->pct_pass_transported > 42) |
896 if (from==to || to->xy == 0 || to->population < 400 || to->pct_pass_transported > 42) |
897 return; |
897 return; |
898 |
898 |
899 fr->distance = GetTileDist(from->xy, to->xy); |
899 fr->distance = GetTileDist(from->xy, to->xy); |
900 } |
900 } |
930 |
930 |
931 fr->cargo = cargo; |
931 fr->cargo = cargo; |
932 |
932 |
933 if (cargo == CT_GOODS || cargo == CT_FOOD) { |
933 if (cargo == CT_GOODS || cargo == CT_FOOD) { |
934 // The destination is a town |
934 // The destination is a town |
935 Town *t = DEREF_TOWN(RandomRange(_total_towns)); |
935 Town *t = GetTown(RandomRange(_total_towns)); |
936 |
936 |
937 // Only want big towns |
937 // Only want big towns |
938 if (t->xy == 0 || t->population < 900) |
938 if (t->xy == 0 || t->population < 900) |
939 return; |
939 return; |
940 fr->distance = GetTileDist(i->xy, t->xy); |
940 fr->distance = GetTileDist(i->xy, t->xy); |
941 fr->to = t; |
941 fr->to = t; |
942 } else { |
942 } else { |
943 // The destination is an industry |
943 // The destination is an industry |
944 Industry *i2 = DEREF_INDUSTRY(RandomRange(_total_industries)); |
944 Industry *i2 = GetIndustry(RandomRange(_total_industries)); |
945 |
945 |
946 // The industry must accept the cargo |
946 // The industry must accept the cargo |
947 if (i == i2 || i2->xy == 0 || |
947 if (i == i2 || i2->xy == 0 || |
948 (cargo != i2->accepts_cargo[0] && |
948 (cargo != i2->accepts_cargo[0] && |
949 cargo != i2->accepts_cargo[1] && |
949 cargo != i2->accepts_cargo[1] && |
1006 pair = SetupSubsidyDecodeParam(s, 1); |
1006 pair = SetupSubsidyDecodeParam(s, 1); |
1007 AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
1007 AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
1008 s->cargo_type = 0xFF; |
1008 s->cargo_type = 0xFF; |
1009 modified = true; |
1009 modified = true; |
1010 } else if (s->age == 2*12-1) { |
1010 } else if (s->age == 2*12-1) { |
1011 st = DEREF_STATION(s->to); |
1011 st = GetStation(s->to); |
1012 if (st->owner == _local_player) { |
1012 if (st->owner == _local_player) { |
1013 pair = SetupSubsidyDecodeParam(s, 1); |
1013 pair = SetupSubsidyDecodeParam(s, 1); |
1014 AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
1014 AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
1015 } |
1015 } |
1016 s->cargo_type = 0xFF; |
1016 s->cargo_type = 0xFF; |
1039 goto add_subsidy; |
1039 goto add_subsidy; |
1040 } |
1040 } |
1041 FindSubsidyCargoRoute(&fr); |
1041 FindSubsidyCargoRoute(&fr); |
1042 if (fr.distance <= 70) { |
1042 if (fr.distance <= 70) { |
1043 s->cargo_type = fr.cargo; |
1043 s->cargo_type = fr.cargo; |
1044 s->from = (Industry*)fr.from - _industries; |
1044 s->from = ((Industry*)fr.from)->index; |
1045 s->to = (fr.cargo == CT_GOODS || fr.cargo == CT_FOOD) ? ((Town*)fr.to)->index : (Industry*)fr.to - _industries; |
1045 s->to = (fr.cargo == CT_GOODS || fr.cargo == CT_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index; |
1046 add_subsidy: |
1046 add_subsidy: |
1047 if (!CheckSubsidyDuplicate(s)) { |
1047 if (!CheckSubsidyDuplicate(s)) { |
1048 s->age = 0; |
1048 s->age = 0; |
1049 pair = SetupSubsidyDecodeParam(s, 0); |
1049 pair = SetupSubsidyDecodeParam(s, 0); |
1050 AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
1050 AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b); |
1165 for(s=_subsidies; s != endof(_subsidies); s++) { |
1165 for(s=_subsidies; s != endof(_subsidies); s++) { |
1166 if (s->cargo_type == cargo_type && s->age < 12) { |
1166 if (s->cargo_type == cargo_type && s->age < 12) { |
1167 |
1167 |
1168 /* Check distance from source */ |
1168 /* Check distance from source */ |
1169 if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) { |
1169 if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) { |
1170 xy = DEREF_TOWN(s->from)->xy; |
1170 xy = GetTown(s->from)->xy; |
1171 } else { |
1171 } else { |
1172 xy = (DEREF_INDUSTRY(s->from))->xy; |
1172 xy = (GetIndustry(s->from))->xy; |
1173 } |
1173 } |
1174 if (GetTileDist1D(xy, from->xy) > 9) |
1174 if (GetTileDist1D(xy, from->xy) > 9) |
1175 continue; |
1175 continue; |
1176 |
1176 |
1177 /* Check distance from dest */ |
1177 /* Check distance from dest */ |
1178 if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) { |
1178 if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) { |
1179 xy = DEREF_TOWN(s->to)->xy; |
1179 xy = GetTown(s->to)->xy; |
1180 } else { |
1180 } else { |
1181 xy = (DEREF_INDUSTRY(s->to))->xy; |
1181 xy = (GetIndustry(s->to))->xy; |
1182 } |
1182 } |
1183 |
1183 |
1184 if (GetTileDist1D(xy, to->xy) > 9) |
1184 if (GetTileDist1D(xy, to->xy) > 9) |
1185 continue; |
1185 continue; |
1186 |
1186 |
1222 p->cur_economy.delivered_cargo += num_pieces; |
1222 p->cur_economy.delivered_cargo += num_pieces; |
1223 SETBIT(p->cargo_types, cargo_type); |
1223 SETBIT(p->cargo_types, cargo_type); |
1224 } |
1224 } |
1225 |
1225 |
1226 // Get station pointers. |
1226 // Get station pointers. |
1227 s_from = DEREF_STATION(source); |
1227 s_from = GetStation(source); |
1228 s_to = DEREF_STATION(dest); |
1228 s_to = GetStation(dest); |
1229 |
1229 |
1230 // Check if a subsidy applies. |
1230 // Check if a subsidy applies. |
1231 subsidised = CheckSubsidised(s_from, s_to, cargo_type); |
1231 subsidised = CheckSubsidised(s_from, s_to, cargo_type); |
1232 |
1232 |
1233 // Increase town's counter for some special goods types |
1233 // Increase town's counter for some special goods types |