equal
deleted
inserted
replaced
1078 * Search for a matching rear-engine of a dual-headed train. |
1078 * Search for a matching rear-engine of a dual-headed train. |
1079 * Do this as if you would find matching parentheses. If a new |
1079 * Do this as if you would find matching parentheses. If a new |
1080 * engine is 'started', first 'close' that before 'closing' our |
1080 * engine is 'started', first 'close' that before 'closing' our |
1081 * searched engine |
1081 * searched engine |
1082 */ |
1082 */ |
1083 Vehicle *GetRearEngine(const Vehicle *v, EngineID engine) |
1083 Vehicle* GetRearEngine(const Vehicle* v) |
1084 { |
1084 { |
1085 Vehicle *u; |
1085 Vehicle *u; |
1086 int en_count = 1; |
1086 int en_count = 1; |
1087 |
1087 |
1088 for (u = v->next; u != NULL; u = u->next) { |
1088 for (u = v->next; u != NULL; u = u->next) { |
1089 if (u->engine_type == engine) { // find matching engine |
1089 if (u->engine_type == v->engine_type) { // find matching engine |
1090 en_count += (IS_FIRSTHEAD_SPRITE(u->spritenum)) ? +1 : -1; |
1090 en_count += (IS_FIRSTHEAD_SPRITE(u->spritenum)) ? +1 : -1; |
1091 |
1091 |
1092 if (en_count == 0) return (Vehicle *)u; |
1092 if (en_count == 0) return (Vehicle *)u; |
1093 } |
1093 } |
1094 } |
1094 } |
1140 bool switch_engine = false; // update second wagon to engine? |
1140 bool switch_engine = false; // update second wagon to engine? |
1141 byte ori_subtype = v->subtype; // backup subtype of deleted wagon in case DeleteVehicle() changes |
1141 byte ori_subtype = v->subtype; // backup subtype of deleted wagon in case DeleteVehicle() changes |
1142 |
1142 |
1143 /* 1. Delete the engine, if it is dualheaded also delete the matching |
1143 /* 1. Delete the engine, if it is dualheaded also delete the matching |
1144 * rear engine of the loco (from the point of deletion onwards) */ |
1144 * rear engine of the loco (from the point of deletion onwards) */ |
1145 Vehicle *rear = (RailVehInfo(v->engine_type)->flags & RVI_MULTIHEAD) ? GetRearEngine(v, v->engine_type) : NULL; |
1145 Vehicle* rear = (RailVehInfo(v->engine_type)->flags & RVI_MULTIHEAD) ? GetRearEngine(v) : NULL; |
1146 if (rear != NULL) { |
1146 if (rear != NULL) { |
1147 cost -= v->value; |
1147 cost -= v->value; |
1148 if (flags & DC_EXEC) { |
1148 if (flags & DC_EXEC) { |
1149 v = UnlinkWagon(rear, v); |
1149 v = UnlinkWagon(rear, v); |
1150 DeleteVehicle(rear); |
1150 DeleteVehicle(rear); |