summaryrefslogtreecommitdiff
path: root/src/autoreplace_cmd.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-09-01 18:27:18 +0200
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-10-22 11:55:40 +0200
commit12e43c697d2ea4a0a9736ab2517a1921e6e690b8 (patch)
tree12cb2c77a7db7d0aa198ec7a522fafab9b30a2be /src/autoreplace_cmd.cpp
parentcbefc1d99491def454fe25d1700c6d41925c81d6 (diff)
downloadopenttd-12e43c697d2ea4a0a9736ab2517a1921e6e690b8.tar.xz
Add: [Script] ScriptEventVehicleAutoReplaced.
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r--src/autoreplace_cmd.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 7c43f9e7a..27149010b 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -21,6 +21,7 @@
#include "core/random_func.hpp"
#include "vehiclelist.h"
#include "road.h"
+#include "ai/ai.hpp"
#include "table/strings.h"
@@ -419,6 +420,8 @@ static CommandCost ReplaceFreeUnit(Vehicle **single_unit, DoCommandFlag flags, b
TransferCargo(old_v, new_v, false);
*single_unit = new_v;
+
+ AI::NewEvent(old_v->owner, new ScriptEventVehicleAutoReplaced(old_v->index, new_v->index));
}
/* Sell the old vehicle */
@@ -587,7 +590,10 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
cost.AddCost(DoCommand(0, w->index, 0, flags | DC_AUTOREPLACE, GetCmdSellVeh(w)));
if ((flags & DC_EXEC) != 0) {
old_vehs[i] = nullptr;
- if (i == 0) old_head = nullptr;
+ if (i == 0) {
+ AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index));
+ old_head = nullptr;
+ }
}
}
@@ -641,6 +647,8 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
if ((flags & DC_EXEC) != 0) {
TransferCargo(old_head, new_head, true);
*chain = new_head;
+
+ AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index));
}
/* Sell the old vehicle */