void MagnetAttachObject(Body mapObjectBody) { if (mapObjectBody.IsDisposed) { return; } if (IsMagnetBodyAttached(mapObjectBody)) { Log.Fatal("Crane: MagnetAttachObject: IsMagnetBodyAttached( mapObjectBody )."); } MapObject mapObject = MapSystemWorld.GetMapObjectByBody(mapObjectBody); if (mapObject != null && mapObject.PhysicsModel != null) { MagnetObjectItem item = new MagnetObjectItem(); item.mapObject = mapObject; item.body = mapObjectBody; item.bodyIndex = Array.IndexOf <Body>(mapObject.PhysicsModel.Bodies, mapObjectBody); SubscribeToDeletionEvent(mapObject); CreateFixedJointForAttachedObject(item); magnetAttachedObjects.Add(item); } }
void MagnetAttachObject(Body mapObjectBody) { if (mapObjectBody.IsDisposed) { return; } Trace.Assert(!IsMagnetBodyAttached(mapObjectBody)); MapObject mapObject = MapSystemWorld.GetMapObjectByBody(mapObjectBody); if (mapObject == null) { return; } MagnetObjectItem item = new MagnetObjectItem(); item.mapObject = mapObject; item.body = mapObjectBody; item.bodyIndex = Array.IndexOf <Body>(mapObject.PhysicsModel.Bodies, mapObjectBody); AddRelationship(mapObject); CreateFixedJointForAttachedObject(item); magnetAttachedObjects.Add(item); }
void MapDestroy(bool newMapWillBeLoaded) { bool mapWasDestroyed = Map.Instance != null; MapSystemWorld.MapDestroy(); if (EntitySystemWorld.Instance != null) { EntitySystemWorld.Instance.WorldDestroy(); } if (mapWasDestroyed) { GameNetworkServer.Instance.EntitySystemService.WorldWasDestroyed(newMapWillBeLoaded); } if (mapWasDestroyed) { Log("Map destroyed"); } buttonMapLoad.Enabled = true; buttonMapUnload.Enabled = false; buttonMapChange.Enabled = false; }
void magnetBody_Collision(ref CollisionEvent collisionEvent) { Body mapObjectBody = collisionEvent.OtherShape.Body; MapObject mapObject = MapSystemWorld.GetMapObjectByBody(mapObjectBody); if (mapObject == null) { return; } if (mapObject == this) { return; } if (IsMagnetBodyAttached(mapObjectBody)) { return; } int count; if (lastMagnetContactsCount.TryGetValue(mapObjectBody, out count)) { lastMagnetContactsCount.Remove(mapObjectBody); } else { count = 0; } lastMagnetContactsCount.Add(mapObjectBody, count + 1); }
private Set <MapObject> GetObjectsInActiveArea() { Set <MapObject> result = new Set <MapObject>(); float height = Type.ActiveAreaHeight; float radius = Type.ActiveAreaRadius; Bounds bounds = new Bounds( Position - new Vec3(radius, radius, 0), Position + new Vec3(radius, radius, height)); Body[] bodies = PhysicsWorld.Instance.VolumeCast(bounds, (int)ContactGroup.CastOnlyDynamic); foreach (Body body in bodies) { if (!body.Static) { MapObject obj = MapSystemWorld.GetMapObjectByBody(body); if (obj != null && obj != this && IsAllowToTeleport(obj) && CheckPositionInActiveArea(obj.Position)) { result.AddWithCheckAlreadyContained(obj); } } } return(result); }
protected void UpdateTargetObject() { //redraw targetedEntity = null; if (EngineApp.Instance.MouseRelativeMode) { return; } Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(EngineApp.Instance.MousePosition); RayCastResult[] results = PhysicsWorld.Instance.RayCastPiercing(ray, (int)ContactGroup.CastOnlyCollision); foreach (RayCastResult result in results) { //terrain HeightmapTerrain terrain = HeightmapTerrain.GetTerrainByBody(result.Shape.Body); if (terrain != null) { targetedEntity = terrain; return; } //other targetedEntity = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); return; } }
void Client_EntitySystemService_WorldCreateBegin(EntitySystemClientNetworkService sender, WorldType worldType, string mapVirtualFileName) { //show map loading window EControl mapLoadingWindow = ControlDeclarationManager.Instance.CreateControl( "Gui\\MapLoadingWindow.gui"); if (mapLoadingWindow != null) { mapLoadingWindow.Text = mapVirtualFileName; controlManager.Controls.Add(mapLoadingWindow); } RenderScene(); DeleteAllGameWindows(); MapSystemWorld.MapDestroy(); if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.ClientOnly, worldType, sender.NetworkingInterface)) { Log.Fatal("GameEngineApp: Client_EntitySystemService_WorldCreateBegin: " + "EntitySystemWorld.WorldCreate failed."); } }
private bool CheckDirectVisibilityByRayCast(Vec3 from, Vec3 targetPosition, MapObject targetObject) { MechUnitAI controlledObj = Owner.ControlledObject; Ray ray = new Ray(from, targetPosition - from); RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); foreach (RayCastResult result in piercingResult) { MapObject obj = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (obj != null) { //skip target object if (targetObject != null && obj == targetObject) { continue; } //skip controlled object if (obj == controlledObj) { continue; } } //found body which breaks visibility return(false); } return(true); }
bool MapLoad(string fileName) { MapDestroy(); WorldType worldType = EntitySystemWorld.Instance.DefaultWorldType; GameNetworkServer server = GameNetworkServer.Instance; if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.DedicatedServer, worldType, server.EntitySystemService.NetworkingInterface)) { Log("Error: EntitySystemWorld.Instance.WorldCreate failed."); return(false); } if (!MapSystemWorld.MapLoad(fileName)) { MapDestroy(); return(false); } //run simulation EntitySystemWorld.Instance.Simulation = true; Log("Map loaded"); return(true); }
void Log_Handlers_ErrorHandler(string text, ref bool handled) { if (controlManager != null) { handled = true; //find already created MessageBoxWindow foreach (EControl control in controlManager.Controls) { if (control is MessageBoxWindow && !control.IsShouldDetach()) { return; } } if (Map.Instance != null) { if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle()) { EntitySystemWorld.Instance.Simulation = false; } } EngineApp.Instance.MouseRelativeMode = false; DeleteAllGameWindows(); MapSystemWorld.MapDestroy(); if (EntitySystemWorld.Instance != null) { EntitySystemWorld.Instance.WorldDestroy(); } GameEngineApp.Instance.Server_DestroyServer("Error on the server"); GameEngineApp.Instance.Client_DisconnectFromServer(); //show message box MessageBoxWindow messageBoxWindow = new MessageBoxWindow(text, "Error", delegate(EButton sender) { //close all windows foreach (EControl control in controlManager.Controls) { control.SetShouldDetach(); } if (EntitySystemWorld.Instance == null) { EngineApp.Instance.SetNeedExit(); return; } //create main menu controlManager.Controls.Add(new MainMenuWindow()); }); controlManager.Controls.Add(messageBoxWindow); } }
public bool Load(string p) { bool result; using (new CursorKeeper(Cursors.WaitCursor)) { if (!ResetWorld()) { return(false); } string p1 = VirtualFileSystem.GetVirtualPathByReal(p); if (!MapSystemWorld.MapLoad(p1)) { result = false; } else { RecordRecentlyLoadedMap(p); UpdateRecentlyLoadedMapIntoMenu(); result = true; } MainForm.Instance.NotifyUpdate(); // Load Modified = false; } return(result); }
void ToggleEntity() { if (EngineApp.Instance.MouseRelativeMode) { return; } MapEditorInterface.Instance.SetMapModified(); Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(EngineApp.Instance.MousePosition); RayCastResult[] results = PhysicsWorld.Instance.RayCastPiercing(ray, (int)ContactGroup.CastOnlyCollision); foreach (RayCastResult result in results) { //heightmapterrain HeightmapTerrain terrain = HeightmapTerrain.GetTerrainByBody(result.Shape.Body); if (terrain != null) { //deselect if (RecastNavigationSystem.Instance.Geometries.Contains(terrain)) { //Log.Info("Removed terrain " + terrain.Name + " from geometries."); RecastNavigationSystem.Instance.Geometries.Remove(terrain); return; } //select if (RecastNavigationSystem.Instance.GeometryVerifier(terrain, true)) { //Log.Info("Added terrain " + terrain.Name + " to geometries."); RecastNavigationSystem.Instance.Geometries.Add(terrain); return; } } MapObject mapObject = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (mapObject != null) { //deselect if (RecastNavigationSystem.Instance.Geometries.Contains(mapObject)) { RecastNavigationSystem.Instance.Geometries.Remove(mapObject); return; } //select if (RecastNavigationSystem.Instance.GeometryVerifier(mapObject, true)) { RecastNavigationSystem.Instance.Geometries.Add(mapObject); return; } } Log.Error("Unknown entity with collisions, what shenanigans!"); } return; }
/// <summary> /// Destroys the background world. /// </summary> void DestroyMap() { if (mapInstance == Map.Instance) { MapSystemWorld.MapDestroy(); EntitySystemWorld.Instance.WorldDestroy(); } }
public static void WorldDestroy() { MapSystemWorld.MapDestroy(); if (EntitySystemWorld.Instance != null) { EntitySystemWorld.Instance.WorldDestroy(); } }
/// <summary> /// 加载地图 /// </summary> /// <param name="p">虚拟路径</param> /// <returns></returns> public bool MapLoad(string p) { if (!ResetWorld()) { return(false); } bool result = MapSystemWorld.MapLoad(p); return(result); }
public bool MapDestroy() { if (Map.Instance == null) { return(false); } MapSystemWorld.MapDestroy(); DestroyWorld(); return(true); }
public void DestroyWorld() { EntityWorld.Instance.ClearEntitySelection(true, true); UndoSystem.Instance.Clear(); CloseLogicEditor(); MapSystemWorld.MapDestroy(); EntitySystemWorld.Instance.WorldDestroy(); MainForm.Instance.NotifyUpdate(); // DestroyWorld }
void MapDestroy() { if (Map.Instance != null) { MapSystemWorld.MapDestroy(); Log("Map destroyed"); } if (EntitySystemWorld.Instance != null) { EntitySystemWorld.Instance.WorldDestroy(); } }
void Client_EntitySystemService_WorldCreateBegin(EntitySystemClientNetworkService sender, WorldType worldType, string mapVirtualFileName) { MapSystemWorld.MapDestroy(); if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.ClientOnly, worldType, sender.NetworkingInterface)) { Log.Fatal("GameEngineApp: Client_EntitySystemService_WorldCreateBegin: " + "EntitySystemWorld.WorldCreate failed."); } }
private bool IsWeaponDirectedToTarget(AttackTask attackTask) { Vec3 targetPos = CalculateTargetPosition(attackTask); Weapon weapon = attackTask.Weapon; //to check up a weapon angle { Vec3 needDirection = (targetPos - weapon.Position).GetNormalize(); Vec3 weaponDirection = weapon.Rotation.GetForward(); Radian angle = Math.Abs(MathFunctions.ACos(Vec3.Dot(needDirection, weaponDirection))); Radian minimalDifferenceAngle = new Degree(2).InRadians(); if (angle > minimalDifferenceAngle) { return(false); } } //to check up a line of fire { Ray ray = new Ray(weapon.Position, targetPos - weapon.Position); RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); foreach (RayCastResult result in piercingResult) { Dynamic dynamic = MapSystemWorld.GetMapObjectByBody(result.Shape.Body) as Dynamic; if (dynamic != null) { Unit parentUnit = dynamic.GetParentUnit(); if (parentUnit != null) { if (parentUnit == attackTask.TargetEntity) { continue; } if (parentUnit == ControlledObject) { continue; } } } return(false); } } return(true); }
private Unit AquireNewTarget() { Unit TempTarget = null; Bounds volume = new Bounds(this.Position); volume.Expand(new Vec3(Type.RadarRange, Type.RadarRange, Type.RadarRange)); Body[] result = PhysicsWorld.Instance.VolumeCast(volume, (int)ContactGroup.CastOnlyDynamic); foreach (Body body in result) { MapObject obj = MapSystemWorld.GetMapObjectByBody(body); if (obj != null) { Unit unit = obj as Unit; if (unit != null) { float Angletounit = CalculateAngleTo(unit); //0.8f in radian is 45 Degrees and the absoulote value whould give the missile a window of 90' if (Angletounit > 0.8f) { continue; } if (TempTarget == null) { TempTarget = unit; } else { float PreTargetDistance = (TempTarget.Position - Position).LengthFast(); float newTargetDistance = (unit.Position - Position).LengthFast(); float DifDis = PreTargetDistance - newTargetDistance; float DiftAngle = CalculateAngleTo(TempTarget) - Angletounit; if (DifDis > 0 && DiftAngle > 0) { TempTarget = unit; } } } } } return(TempTarget); }
//save current map public void SaveMap(string filePath, bool currentMap) { if (MapSaveAble()) { if (currentMap) { MapSystemWorld.WorldSave(filePath + " //cursave.world", true); } else { string saveName = string.Format("{0}Maps//{1}.world", filePath, Path.GetFileNameWithoutExtension(Map.Instance.SourceMapVirtualFileName)); MapSystemWorld.MapSave(saveName, true); } } }
public bool Save(string virtualPathByReal) { bool result; using (new CursorKeeper(Cursors.WaitCursor)) { if (string.IsNullOrEmpty(virtualPathByReal)) { string p = ChooseSavePath(); if (p == null) { return(false); } virtualPathByReal = VirtualFileSystem.GetVirtualPathByReal(p); if (string.IsNullOrEmpty(virtualPathByReal)) { Log.Warning(ToolsLocalization.Translate("Various", "Unable to save file. You cannot save map outside \"Data\" directory.")); result = false; return(result); } } EntityWorld.Instance.ResetBeforeMapSave(); UndoSystem.Instance.Clear(); Map.Instance.GetDataForEditor().ClearDeletedEntities(); bool flag; try { MainForm.Instance.WatchFileSystem = false; flag = MapSystemWorld.MapSave(virtualPathByReal, true); } finally { MainForm.Instance.WatchFileSystem = true; } if (!flag) { result = false; } else { Modified = false; result = true; } MainForm.Instance.NotifyUpdate(false); // Save } return(result); }
void exitToMainMenuButton_Click(object sender) { MapSystemWorld.MapDestroy(); EntitySystemWorld.Instance.WorldDestroy(); GameEngineApp.Instance.Server_DestroyServer("The server has been destroyed"); GameEngineApp.Instance.Client_DisconnectFromServer(); //close all windows foreach (Control control in GameEngineApp.Instance.ControlManager.Controls) { control.SetShouldDetach(); } //create main menu GameEngineApp.Instance.ControlManager.Controls.Add(new MainMenuWindow()); }
private void attachedParentBody_Collision(ref CollisionEvent collisionEvent) { if (lastJumpTime == 0) { return; } lastJumpTime = 0; Dynamic objDynamic = MapSystemWorld.GetMapObjectByBody( collisionEvent.OtherShape.Body) as Dynamic; if (objDynamic == null) { return; } Character unit = (Character)AttachedMapObjectParent; if (unit == null || unit.Intellect == null) { return; } //Not kick allies Unit objUnit = objDynamic.GetParentUnitHavingIntellect(); if (objUnit == null) { return; } if (objUnit.Intellect.Faction == unit.Intellect.Faction) { return; } objUnit.DoDamage(unit, unit.Position, collisionEvent.OtherShape, Type.NormalMode.Damage, true); SoundPlay3D(Type.SoundBlowKick, .5f, false); if (EntitySystemWorld.Instance.IsServer() && Type.NetworkType == EntityNetworkTypes.Synchronized) { Server_SendSoundPlayBlowKick(); } }
Dynamic GetObject() { Vec3 mouseMapPos = Vec3.Zero; //get pick information Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(EngineApp.Instance.MousePosition); if (!float.IsNaN(ray.Direction.X)) { RayCastResult result = PhysicsWorld.Instance.RayCast(ray, (int)ContactGroup.CastOnlyContact); if (result.Shape != null) { return(MapSystemWorld.GetMapObjectByBody(result.Shape.Body) as Dynamic); } } return(null); }
private bool MapLoad(string fileName) { MapDestroy(false); Log("Loading map \"{0}\"...", fileName); WorldType worldType = EntitySystemWorld.Instance.DefaultWorldType; GameNetworkServer server = GameNetworkServer.Instance; if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.DedicatedServer, worldType, server.EntitySystemService.NetworkingInterface)) { Log("Error: EntitySystemWorld.Instance.WorldCreate failed."); return(false); } if (!MapSystemWorld.MapLoad(fileName)) { MapDestroy(false); onMapEnd(); return(false); } else { onMapStart(); } //run simulation EntitySystemWorld.Instance.Simulation = true; GameNetworkServer.Instance.EntitySystemService.WorldWasCreated(); Log("Map loaded"); buttonMapLoad.Enabled = false; buttonMapUnload.Enabled = true; buttonMapChange.Enabled = true; checkPrivateServer.Enabled = false; ntbMapTime.Enabled = false; return(true); }
public bool WorldSave(string fileName) { EControl worldSavingWindow = null; //world saving window { worldSavingWindow = ControlDeclarationManager.Instance.CreateControl( "Gui\\WorldSavingWindow.gui"); if (worldSavingWindow != null) { worldSavingWindow.Text = fileName; controlManager.Controls.Add(worldSavingWindow); } RenderScene(); } GameWindow gameWindow = null; foreach (EControl control in controlManager.Controls) { gameWindow = control as GameWindow; if (gameWindow != null) { break; } } if (gameWindow != null) { gameWindow.OnBeforeWorldSave(); } bool result = MapSystemWorld.WorldSave(fileName); if (worldSavingWindow != null) { worldSavingWindow.SetShouldDetach(); } return(result); }
private Set <MapObject> GetObjectsInActiveArea() { Set <MapObject> result = new Set <MapObject>(); Bounds areabounds = new Bounds(Position - box.Extents, Position + box.Extents); Body[] bodies = PhysicsWorld.Instance.VolumeCast(areabounds, (int)ContactGroup.CastOnlyDynamic); foreach (Body body in bodies) { if (!body.Static) { MapObject obj = MapSystemWorld.GetMapObjectByBody(body); if (obj != null && obj != this && IsAllowToTeleport(obj) && CheckPositionInActiveArea(areabounds, obj.Position)) { result.AddWithCheckAlreadyContained(obj); } } } return(result); }
public static bool MapLoad(string virtualFileName, bool runSimulation) { //Destroy old WorldDestroy(); //New if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.Single, EntitySystemWorld.Instance.DefaultWorldType)) { Log.Error("EntitySystemWorld: WorldCreate failed."); return(false); } if (!MapSystemWorld.MapLoad(virtualFileName)) { return(false); } //run simulation EntitySystemWorld.Instance.Simulation = runSimulation; return(true); }