src/ai/trolly/trolly.cpp
branchcustombridgeheads
changeset 5650 aefc131bf5ce
parent 5649 55c8267c933f
equal deleted inserted replaced
5649:55c8267c933f 5650:aefc131bf5ce
   792 
   792 
   793 	p->ainew.depot_tile = 0;
   793 	p->ainew.depot_tile = 0;
   794 
   794 
   795 	for (i=2;i<p->ainew.path_info.route_length-2;i++) {
   795 	for (i=2;i<p->ainew.path_info.route_length-2;i++) {
   796 		tile = p->ainew.path_info.route[i];
   796 		tile = p->ainew.path_info.route[i];
   797 		for (j = 0; j < 4; j++) {
   797 		for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) {
   798 			TileIndex t = tile + TileOffsByDiagDir(j);
   798 			TileIndex t = tile + TileOffsByDiagDir(j);
   799 
   799 
   800 			if (IsTileType(t, MP_STREET) &&
   800 			if (IsTileType(t, MP_STREET) &&
   801 					GetRoadTileType(t) == ROAD_TILE_DEPOT &&
   801 					GetRoadTileType(t) == ROAD_TILE_DEPOT &&
   802 					IsTileOwner(t, _current_player) &&
   802 					IsTileOwner(t, _current_player) &&
   823 			continue;
   823 			continue;
   824 		}
   824 		}
   825 
   825 
   826 		tile = p->ainew.path_info.route[i];
   826 		tile = p->ainew.path_info.route[i];
   827 
   827 
   828 		for (j = 0; j < 4; j++) {
   828 		for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) {
   829 			TileIndex t = tile + TileOffsByDiagDir(j);
   829 			TileIndex t = tile + TileOffsByDiagDir(j);
   830 
   830 
   831 			// It may not be placed on the road/rail itself
   831 			// It may not be placed on the road/rail itself
   832 			// And because it is not build yet, we can't see it on the tile..
   832 			// And because it is not build yet, we can't see it on the tile..
   833 			// So check the surrounding tiles :)
   833 			// So check the surrounding tiles :)
   901 		} else {
   901 		} else {
   902 			max_cargo = GetIndustry(p->ainew.to_ic)->total_production[0];
   902 			max_cargo = GetIndustry(p->ainew.to_ic)->total_production[0];
   903 		}
   903 		}
   904 
   904 
   905 		// This is because moving 60% is more than we can dream of!
   905 		// This is because moving 60% is more than we can dream of!
   906 		max_cargo *= 0.6;
   906 		max_cargo *= 6;
       
   907 		max_cargo /= 10;
   907 		// We want all the cargo to be gone in a month.. so, we know the cargo it delivers
   908 		// We want all the cargo to be gone in a month.. so, we know the cargo it delivers
   908 		//  we know what the vehicle takes with him, and we know the time it takes him
   909 		//  we know what the vehicle takes with him, and we know the time it takes him
   909 		//  to get back here.. now let's do some math!
   910 		//  to get back here.. now let's do some math!
   910 		amount = 2 * length * max_cargo / tiles_a_day / 30 / RoadVehInfo(i)->capacity;
   911 		amount = 2 * length * max_cargo / tiles_a_day / 30 / RoadVehInfo(i)->capacity;
   911 		amount += 1;
   912 		amount += 1;
  1051 					dir2 = p->ainew.to_direction + 1;
  1052 					dir2 = p->ainew.to_direction + 1;
  1052 					if (dir2 > 3) dir2 = 0;
  1053 					if (dir2 > 3) dir2 = 0;
  1053 					dir3 = p->ainew.to_direction;
  1054 					dir3 = p->ainew.to_direction;
  1054 				}
  1055 				}
  1055 
  1056 
  1056 				ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1057 				ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1057 				if (!CmdFailed(ret)) {
  1058 				if (!CmdFailed(ret)) {
  1058 					dir1 = TileOffsByDiagDir(dir1);
  1059 					dir1 = TileOffsByDiagDir(dir1);
  1059 					if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) {
  1060 					if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) {
  1060 						ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1061 						ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1061 						if (!CmdFailed(ret)) {
  1062 						if (!CmdFailed(ret)) {
  1063 								AI_DoCommand(tile+dir1+dir1, AiNew_GetRoadDirection(tile+dir1, tile+dir1+dir1, tile+dir1+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1064 								AI_DoCommand(tile+dir1+dir1, AiNew_GetRoadDirection(tile+dir1, tile+dir1+dir1, tile+dir1+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1064 						}
  1065 						}
  1065 					}
  1066 					}
  1066 				}
  1067 				}
  1067 
  1068 
  1068 				ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1069 				ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1069 				if (!CmdFailed(ret)) {
  1070 				if (!CmdFailed(ret)) {
  1070 					dir2 = TileOffsByDiagDir(dir2);
  1071 					dir2 = TileOffsByDiagDir(dir2);
  1071 					if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) {
  1072 					if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) {
  1072 						ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1073 						ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1073 						if (!CmdFailed(ret)) {
  1074 						if (!CmdFailed(ret)) {
  1075 								AI_DoCommand(tile+dir2+dir2, AiNew_GetRoadDirection(tile+dir2, tile+dir2+dir2, tile+dir2+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1076 								AI_DoCommand(tile+dir2+dir2, AiNew_GetRoadDirection(tile+dir2, tile+dir2+dir2, tile+dir2+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1076 						}
  1077 						}
  1077 					}
  1078 					}
  1078 				}
  1079 				}
  1079 
  1080 
  1080 				ret = AI_DoCommand(tile, DiagDirToRoadBits(dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1081 				ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1081 				if (!CmdFailed(ret)) {
  1082 				if (!CmdFailed(ret)) {
  1082 					dir3 = TileOffsByDiagDir(dir3);
  1083 					dir3 = TileOffsByDiagDir(dir3);
  1083 					if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) {
  1084 					if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) {
  1084 						ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1085 						ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
  1085 						if (!CmdFailed(ret)) {
  1086 						if (!CmdFailed(ret)) {