SetIntellect() public method

public SetIntellect ( Intellect value, bool shouldDeleteAfterDetach ) : void
value Intellect
shouldDeleteAfterDetach bool
return void
Exemplo n.º 1
0
        Unit ServerOrSingle_CreatePlayerUnit(PlayerManager.ServerOrSingle_Player player,
                                             SpawnPoint spawnPoint)
        {
            string unitTypeName;

            if (!player.Bot)
            {
                unitTypeName = "Forklift";
            }
            else
            {
                unitTypeName = player.Name;
            }

            Unit unit = (Unit)Entities.Instance.Create(unitTypeName, Map.Instance);

            Vec3 posOffset = new Vec3(0, 0, 1.5f);              //!!!!temp

            unit.Position = spawnPoint.Position + posOffset;
            unit.Rotation = spawnPoint.Rotation;
            unit.PostCreate();

            if (player.Intellect != null)
            {
                player.Intellect.ControlledObject = unit;
                unit.SetIntellect(player.Intellect, false);
            }

            return(unit);
        }
Exemplo n.º 2
0
        void ServerOrSingle_ChangeMainControlledUnit(Unit unit)
        {
            //Change player controlled unit
            mainNotActiveUnit = ControlledObject;

            //send mainNotActiveUnit to clients
            if (EntitySystemWorld.Instance.IsServer())
            {
                Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);
            }

            if (mainNotActiveUnit != null)
            {
                AddRelationship(mainNotActiveUnit);

                mainNotActiveUnit.SetIntellect(null, false);
                mainNotActiveUnitRestorePosition = mainNotActiveUnit.Position;

                //disable collision for shapes and save contact groups
                mainNotActiveUnitShapeContactGroups = new Dictionary <Shape, int>();
                foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies)
                {
                    foreach (Shape shape in body.Shapes)
                    {
                        mainNotActiveUnitShapeContactGroups.Add(shape, shape.ContactGroup);
                        shape.ContactGroup = (int)ContactGroup.NoContact;
                    }
                }

                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = false;

                ControlledObject = unit;
                unit.SetIntellect(this, false);
                unit.Destroying += AlternativeUnitAllowPlayerControl_Destroying;
            }
        }
Exemplo n.º 3
0
        void ServerOrSingle_RestoreMainControlledUnit()
        {
            if (mainNotActiveUnit == null)
            {
                return;
            }

            if (ControlledObject != null)
            {
                ControlledObject.SetIntellect(null, false);
                ControlledObject.Destroying -= AlternativeUnitAllowPlayerControl_Destroying;
            }

            if (!mainNotActiveUnit.IsSetDeleted)
            {
                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = true;

                mainNotActiveUnit.Position = mainNotActiveUnitRestorePosition;
                //find free position for movable player controlled units
                if (ControlledObject != null)
                {
                    //Tank specific
                    if (ControlledObject is Tank)
                    {
                        mainNotActiveUnit.Position = FindFreePositionForUnit(
                            mainNotActiveUnit, ControlledObject.Position);
                    }
                }

                mainNotActiveUnit.OldPosition = mainNotActiveUnit.Position;

                mainNotActiveUnit.Visible = true;

                RemoveRelationship(mainNotActiveUnit);

                //restore contact groups for shapes
                if (mainNotActiveUnitShapeContactGroups != null)
                {
                    foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies)
                    {
                        foreach (Shape shape in body.Shapes)
                        {
                            int group;
                            if (mainNotActiveUnitShapeContactGroups.TryGetValue(shape, out group))
                            {
                                shape.ContactGroup = group;
                            }
                        }
                    }
                    mainNotActiveUnitShapeContactGroups.Clear();
                    mainNotActiveUnitShapeContactGroups = null;
                }

                mainNotActiveUnit.SetIntellect(this, false);

                ControlledObject = mainNotActiveUnit;
            }
            else
            {
                ControlledObject = null;
            }

            mainNotActiveUnit = null;

            //send mainNotActiveUnit to clients
            if (EntitySystemWorld.Instance.IsServer())
            {
                Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);
            }
        }
        void ServerOrSingle_ChangeMainControlledUnit( Unit unit )
        {
            //Change player controlled unit
            mainNotActiveUnit = ControlledObject;

            //send mainNotActiveUnit to clients
            if( EntitySystemWorld.Instance.IsServer() )
                Server_SendMainNotActiveUnitToClients( EntitySystemWorld.Instance.RemoteEntityWorlds );

            if( mainNotActiveUnit != null )
            {
                AddRelationship( mainNotActiveUnit );

                mainNotActiveUnit.SetIntellect( null, false );
                mainNotActiveUnitRestorePosition = mainNotActiveUnit.Position;

                //disable collision for shapes and save contact groups
                mainNotActiveUnitShapeContactGroups = new Dictionary<Shape, int>();
                foreach( Body body in mainNotActiveUnit.PhysicsModel.Bodies )
                {
                    foreach( Shape shape in body.Shapes )
                    {
                        mainNotActiveUnitShapeContactGroups.Add( shape, shape.ContactGroup );
                        shape.ContactGroup = (int)ContactGroup.NoContact;
                    }
                }

                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = false;

                ControlledObject = unit;
                unit.SetIntellect( this, false );
                unit.Destroying += AlternativeUnitAllowPlayerControl_Destroying;
            }
        }