|
1 | 1 | using Microsoft.Xna.Framework; |
2 | 2 | using Microsoft.Xna.Framework.Graphics; |
3 | 3 | using Rampastring.Tools; |
| 4 | +using Rampastring.XNAUI.XNAControls; |
4 | 5 | using System; |
5 | 6 | using System.Collections.Generic; |
6 | 7 | using System.Globalization; |
@@ -2124,6 +2125,134 @@ private void CheckForAITriggerTeamWithMaxZeroIssue(AITriggerType aiTrigger, Team |
2124 | 2125 | } |
2125 | 2126 | } |
2126 | 2127 |
|
| 2128 | + public bool IsLikelyMultiplayer() |
| 2129 | + { |
| 2130 | + if (Basic.MultiplayerOnly) |
| 2131 | + return true; |
| 2132 | + |
| 2133 | + const int MaxUniqueHouses = 32; |
| 2134 | + const int FirstSpawnHouseIndex = 50; |
| 2135 | + |
| 2136 | + if (Houses.Count > 0 && Houses.Count < MaxUniqueHouses) |
| 2137 | + { |
| 2138 | + // Most likely singleplayer - SP maps always have houses, |
| 2139 | + // while regular MP maps don't have houses |
| 2140 | + // and scripted TS MP maps need more than 50 houses |
| 2141 | + return false; |
| 2142 | + } |
| 2143 | + |
| 2144 | + if (Houses.Count > FirstSpawnHouseIndex) |
| 2145 | + { |
| 2146 | + // Most likely a scripted multiplayer scenario |
| 2147 | + return true; |
| 2148 | + } |
| 2149 | + |
| 2150 | + return false; |
| 2151 | + } |
| 2152 | + |
| 2153 | + public bool IsWaypointInUse(Waypoint waypoint) |
| 2154 | + { |
| 2155 | + foreach (Trigger trigger in Triggers) |
| 2156 | + { |
| 2157 | + foreach (var action in trigger.Actions) |
| 2158 | + { |
| 2159 | + var triggerActionType = EditorConfig.TriggerActionTypes.GetValueOrDefault(action.ActionIndex); |
| 2160 | + |
| 2161 | + if (triggerActionType == null) |
| 2162 | + continue; |
| 2163 | + |
| 2164 | + for (int i = 0; i < triggerActionType.Parameters.Length; i++) |
| 2165 | + { |
| 2166 | + if (triggerActionType.Parameters[i] == null) |
| 2167 | + continue; |
| 2168 | + |
| 2169 | + var param = triggerActionType.Parameters[i]; |
| 2170 | + |
| 2171 | + if (param.TriggerParamType == TriggerParamType.Waypoint && action.Parameters[i] == waypoint.Identifier.ToString()) |
| 2172 | + { |
| 2173 | + return true; |
| 2174 | + } |
| 2175 | + |
| 2176 | + if (param.TriggerParamType == TriggerParamType.WaypointZZ && action.Parameters[i] == Helpers.WaypointNumberToAlphabeticalString(waypoint.Identifier)) |
| 2177 | + { |
| 2178 | + return true; |
| 2179 | + } |
| 2180 | + } |
| 2181 | + } |
| 2182 | + |
| 2183 | + foreach (var condition in trigger.Conditions) |
| 2184 | + { |
| 2185 | + var triggerEventType = EditorConfig.TriggerEventTypes.GetValueOrDefault(condition.ConditionIndex); |
| 2186 | + |
| 2187 | + if (triggerEventType == null) |
| 2188 | + continue; |
| 2189 | + |
| 2190 | + for (int i = 0; i < triggerEventType.Parameters.Length; i++) |
| 2191 | + { |
| 2192 | + if (triggerEventType.Parameters[i] == null) |
| 2193 | + continue; |
| 2194 | + |
| 2195 | + var param = triggerEventType.Parameters[i]; |
| 2196 | + |
| 2197 | + if (param.TriggerParamType == TriggerParamType.Waypoint && condition.Parameters[i] == waypoint.Identifier.ToString()) |
| 2198 | + { |
| 2199 | + return true; |
| 2200 | + } |
| 2201 | + |
| 2202 | + if (param.TriggerParamType == TriggerParamType.WaypointZZ && condition.Parameters[i] == Helpers.WaypointNumberToAlphabeticalString(waypoint.Identifier)) |
| 2203 | + { |
| 2204 | + return true; |
| 2205 | + } |
| 2206 | + } |
| 2207 | + } |
| 2208 | + } |
| 2209 | + |
| 2210 | + foreach (Script script in Scripts) |
| 2211 | + { |
| 2212 | + foreach (var actionEntry in script.Actions) |
| 2213 | + { |
| 2214 | + var scriptAction = EditorConfig.ScriptActions.GetValueOrDefault(actionEntry.Action); |
| 2215 | + |
| 2216 | + if (scriptAction == null) |
| 2217 | + { |
| 2218 | + continue; |
| 2219 | + } |
| 2220 | + |
| 2221 | + if (scriptAction.ParamType == TriggerParamType.Waypoint && actionEntry.Argument == waypoint.Identifier) |
| 2222 | + { |
| 2223 | + return true; |
| 2224 | + } |
| 2225 | + } |
| 2226 | + } |
| 2227 | + |
| 2228 | + foreach (TeamType team in TeamTypes) |
| 2229 | + { |
| 2230 | + if (team.Waypoint == Helpers.WaypointNumberToAlphabeticalString(waypoint.Identifier)) |
| 2231 | + { |
| 2232 | + return true; |
| 2233 | + } |
| 2234 | + } |
| 2235 | + |
| 2236 | + return false; |
| 2237 | + } |
| 2238 | + |
| 2239 | + public Waypoint GetFirstUnusedWaypoint() |
| 2240 | + { |
| 2241 | + int firstValidIdentifier = IsLikelyMultiplayer() ? 8 : 0; |
| 2242 | + |
| 2243 | + for (int i = 0; i < Waypoints.Count; i++) |
| 2244 | + { |
| 2245 | + Waypoint wp = Waypoints[i]; |
| 2246 | + if (wp.Identifier < firstValidIdentifier) |
| 2247 | + continue; |
| 2248 | + |
| 2249 | + if (!IsWaypointInUse(wp)) |
| 2250 | + return wp; |
| 2251 | + } |
| 2252 | + |
| 2253 | + return null; |
| 2254 | + } |
| 2255 | + |
2127 | 2256 | public void Clear() |
2128 | 2257 | { |
2129 | 2258 | LoadedINI = null; |
|
0 commit comments