src/ai/default/default.cpp
changeset 6248 e4a2ed7e5613
parent 6247 7d81e3a5d803
child 6259 471b91a4b1d8
equal deleted inserted replaced
6247:7d81e3a5d803 6248:e4a2ed7e5613
   444 	// vehicle is not owned by the player anymore, something went very wrong.
   444 	// vehicle is not owned by the player anymore, something went very wrong.
   445 	if (!IsValidVehicle(v) || v->owner != _current_player) return;
   445 	if (!IsValidVehicle(v) || v->owner != _current_player) return;
   446 	_veh_do_replace_proc[v->type - VEH_Train](p);
   446 	_veh_do_replace_proc[v->type - VEH_Train](p);
   447 }
   447 }
   448 
   448 
   449 typedef struct FoundRoute {
   449 struct FoundRoute {
   450 	int distance;
   450 	int distance;
   451 	CargoID cargo;
   451 	CargoID cargo;
   452 	void *from;
   452 	void *from;
   453 	void *to;
   453 	void *to;
   454 } FoundRoute;
   454 };
   455 
   455 
   456 static Town *AiFindRandomTown()
   456 static Town *AiFindRandomTown()
   457 {
   457 {
   458 	return GetRandomTown();
   458 	return GetRandomTown();
   459 }
   459 }
  1822 	while (p->mode != 3 || !((--cmd) & 0x80)) p++;
  1822 	while (p->mode != 3 || !((--cmd) & 0x80)) p++;
  1823 
  1823 
  1824 	return tile + ToTileIndexDiff(p->tileoffs) - TileOffsByDiagDir(*dir = p->attr);
  1824 	return tile + ToTileIndexDiff(p->tileoffs) - TileOffsByDiagDir(*dir = p->attr);
  1825 }
  1825 }
  1826 
  1826 
  1827 typedef struct AiRailPathFindData {
  1827 struct AiRailPathFindData {
  1828 	TileIndex tile;
  1828 	TileIndex tile;
  1829 	TileIndex tile2;
  1829 	TileIndex tile2;
  1830 	int count;
  1830 	int count;
  1831 	bool flag;
  1831 	bool flag;
  1832 } AiRailPathFindData;
  1832 };
  1833 
  1833 
  1834 static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, uint length, byte *state)
  1834 static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, uint length, byte *state)
  1835 {
  1835 {
  1836 	if (a->flag) return true;
  1836 	if (a->flag) return true;
  1837 
  1837 
  1856 	FollowTrack(p->ai.cur_tile_a + TileOffsByDiagDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, (DiagDirection)(p->ai.cur_dir_a^2),
  1856 	FollowTrack(p->ai.cur_tile_a + TileOffsByDiagDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, (DiagDirection)(p->ai.cur_dir_a^2),
  1857 		(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
  1857 		(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
  1858 	return arpfd.count > 8;
  1858 	return arpfd.count > 8;
  1859 }
  1859 }
  1860 
  1860 
  1861 typedef struct AiRailFinder {
  1861 struct AiRailFinder {
  1862 	TileIndex final_tile;
  1862 	TileIndex final_tile;
  1863 	byte final_dir;
  1863 	byte final_dir;
  1864 	byte depth;
  1864 	byte depth;
  1865 	byte recursive_mode;
  1865 	byte recursive_mode;
  1866 	byte cur_best_dir;
  1866 	byte cur_best_dir;
  1871 	const byte *best_ptr;
  1871 	const byte *best_ptr;
  1872 	uint best_dist;
  1872 	uint best_dist;
  1873 	TileIndex cur_best_tile, best_tile;
  1873 	TileIndex cur_best_tile, best_tile;
  1874 	TileIndex bridge_end_tile;
  1874 	TileIndex bridge_end_tile;
  1875 	Player *player;
  1875 	Player *player;
  1876 } AiRailFinder;
  1876 };
  1877 
  1877 
  1878 static const byte _ai_table_15[4][8] = {
  1878 static const byte _ai_table_15[4][8] = {
  1879 	{0, 0, 4, 3, 3, 1, 128 + 0, 64},
  1879 	{0, 0, 4, 3, 3, 1, 128 + 0, 64},
  1880 	{1, 1, 2, 0, 4, 2, 128 + 1, 65},
  1880 	{1, 1, 2, 0, 4, 2, 128 + 1, 65},
  1881 	{0, 2, 2, 3, 5, 1, 128 + 2, 66},
  1881 	{0, 2, 2, 3, 5, 1, 128 + 2, 66},
  2711 	// yep, all are done. switch state to the rail building state.
  2711 	// yep, all are done. switch state to the rail building state.
  2712 	p->ai.state = AIS_BUILD_ROAD;
  2712 	p->ai.state = AIS_BUILD_ROAD;
  2713 	p->ai.state_mode = 255;
  2713 	p->ai.state_mode = 255;
  2714 }
  2714 }
  2715 
  2715 
  2716 typedef struct {
  2716 struct AiRoadFinder {
  2717 	TileIndex final_tile;
  2717 	TileIndex final_tile;
  2718 	byte final_dir;
  2718 	byte final_dir;
  2719 	byte depth;
  2719 	byte depth;
  2720 	byte recursive_mode;
  2720 	byte recursive_mode;
  2721 	byte cur_best_dir;
  2721 	byte cur_best_dir;
  2726 	const byte *best_ptr;
  2726 	const byte *best_ptr;
  2727 	uint best_dist;
  2727 	uint best_dist;
  2728 	TileIndex cur_best_tile, best_tile;
  2728 	TileIndex cur_best_tile, best_tile;
  2729 	TileIndex bridge_end_tile;
  2729 	TileIndex bridge_end_tile;
  2730 	Player *player;
  2730 	Player *player;
  2731 } AiRoadFinder;
  2731 };
  2732 
  2732 
  2733 typedef struct AiRoadEnum {
  2733 struct AiRoadEnum {
  2734 	TileIndex dest;
  2734 	TileIndex dest;
  2735 	TileIndex best_tile;
  2735 	TileIndex best_tile;
  2736 	int best_track;
  2736 	int best_track;
  2737 	uint best_dist;
  2737 	uint best_dist;
  2738 } AiRoadEnum;
  2738 };
  2739 
  2739 
  2740 static const byte _dir_by_track[] = {
  2740 static const byte _dir_by_track[] = {
  2741 	0, 1, 0, 1, 2, 1,
  2741 	0, 1, 0, 1, 2, 1,
  2742 	0, 0,
  2742 	0, 0,
  2743 	2, 3, 3, 2, 3, 0,
  2743 	2, 3, 3, 2, 3, 0,