diff options
author | smatz <smatz@openttd.org> | 2011-02-02 23:06:38 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2011-02-02 23:06:38 +0000 |
commit | f3e550e9bd8cdaa31e18e05208cdecc642cea55f (patch) | |
tree | e875013b8577d8cb293d3dd1d4539ec0781f5f35 | |
parent | a4bf3be864dcff13dd1550c6badaa47184e53bfb (diff) | |
download | openttd-f3e550e9bd8cdaa31e18e05208cdecc642cea55f.tar.xz |
(svn r21949) -Change: randomize the vehicle a small UFO targets, do not use the one with lowest index
-rw-r--r-- | src/disaster_cmd.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index 38c366ed5..a0998a55d 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -307,17 +307,28 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) } v->current_order.SetDestination(1); + uint n = 0; // Total number of targetable road vehicles. RoadVehicle *u; FOR_ALL_ROADVEHICLES(u) { - if (u->IsFrontEngine()) { - v->dest_tile = u->index; - v->age = 0; - return true; - } + if (u->IsFrontEngine()) n++; } - delete v; - return false; + if (n == 0) { + /* If there are no targetable road vehicles, destroy the UFO. */ + delete v; + return false; + } + + n = RandomRange(n); // Choose one of them. + FOR_ALL_ROADVEHICLES(u) { + /* Find (n+1)-th road vehicle. */ + if (u->IsFrontEngine() && (n-- == 0)) break; + } + + /* Target it. */ + v->dest_tile = u->index; + v->age = 0; + return true; } else { /* Target a vehicle */ RoadVehicle *u = RoadVehicle::Get(v->dest_tile); |