/// <summary>
    /// Do some checks before installing a module in a hardpoint to make sure
    /// that we can actually install it.
    /// </summary>
    public ModuleResult CanInstallModuleInto(Hardpoint hardpoint, GameObject prefab)
    {
        if (hardpoint == null)
        {
            return(ModuleResult.InvalidHardpoint);
        }
        if (!hardpoint.IsEmpty)
        {
            return(ModuleResult.HardpointNotEmpty);
        }
        if (prefab == null)
        {
            return(ModuleResult.NoModule);
        }

        ActorModule module = prefab.GetComponent <ActorModule>();

        if (module == null)
        {
            return(ModuleResult.NoModule);
        }
        if (!hardpoint.IsCompatible(module.socket))
        {
            return(ModuleResult.IncompatibleSocket);
        }
        return(ModuleResult.Success);
    }
Beispiel #2
0
    /// <summary>
    /// Determines whether this group can add the specified hardpoint.
    /// </summary>
    /// <param name="hardpoint">The hardpoint to try and add to the group.</param>
    /// <returns><c>true</c> if this group can add the specified hardpoint; otherwise, <c>false</c>.</returns>
    public bool CanAddHardPoint(Hardpoint hardpoint)
    {
        if (hardpoint.Module == null)
        {
            return(false);            // Cannot add an empty socket.
        }

        // See if the socket group can take the module.
        ActorModule module    = hardpoint.Module;
        HPSocket    typeFlags = module.socket;

        if ((typeFlags & HPSocket.Passive) == HPSocket.Passive)
        {
            return((flags & Flags.Passive) == Flags.Passive);
        }

        if ((typeFlags & HPSocket.Utility) == HPSocket.Utility)
        {
            return((flags & Flags.Utility) == Flags.Utility);
        }

        if ((typeFlags & HPSocket.Targeted) == HPSocket.Targeted)
        {
            return((flags & Flags.Targeted) == Flags.Targeted);
        }

        // Dunno what happened, so no.
        return(false);
    }
Beispiel #3
0
    /// <summary>
    /// Instantiates an instance of a module prefab and installs it into a specified hardpoint on a
    /// specified parent GameObject.  The instance of the module component is returned.
    /// </summary>
    public static ActorModule Instantiate(GameObject prefab, Hardpoint hardpoint, GameObject parent)
    {
        GameObject  go  = GameObject.Instantiate(prefab, parent.transform);
        ActorModule mod = go.GetComponent <ActorModule>();

        mod._prefab = prefab;
        mod.InstantiateModule(hardpoint.position, hardpoint.rotation);
        hardpoint.SetModule(mod);
        return(mod);
    }
 /// <summary>
 /// Register that a module was installed into a hardpoint after the fact.
 /// </summary>
 public void RegisterInstalledModuleIn(Hardpoint hardpoint, ActorModule module)
 {
     // TODO: Do something here.
     if (onChange != null)
     {
         onChange(ActorModule.Change.Installed, module);
     }
     if (module.DisabledBy == ActorModule.DisabledReason.ResourceLoss)
     {
         _autoDisabled += 1;
     }
 }
    /// <summary>
    /// Find and return the Hardpoint by installed module.
    /// </summary>
    public Hardpoint Get(ActorModule module)
    {
        // TODO Make this based off of the module's socket to speed it up.
        // Search through the Targeted hardpoints.
        int numTargeted = (targeted != null) ? targeted.Length : 0;

        for (int i = 0; i < numTargeted; ++i)
        {
            if (targeted[i].Module == module)
            {
                return(targeted[i]);
            }
        }

        // Search through the utility hardpoints.
        int numUtility = (utility != null) ? utility.Length : 0;

        for (int i = 0; i < numUtility; ++i)
        {
            if (utility[i].Module == module)
            {
                return(utility[i]);
            }
        }

        // Search through the passive hardpoints.
        int numPassive = (passive != null) ? passive.Length : 0;

        for (int i = 0; i < numPassive; ++i)
        {
            if (passive[i].Module == module)
            {
                return(passive[i]);
            }
        }

        // Search through the structural hardpoints.
        int numStructural = (structures != null) ? structures.Length : 0;

        for (int i = 0; i < numStructural; ++i)
        {
            if (structures[i].Module == module)
            {
                return(structures[i]);
            }
        }

        // Return null if we didn't find it.
        return(null);
    }
    /// <summary>
    /// Triggers the deactivation of the component.
    /// </summary>
    public ModuleResult Deactivate(ActorModule module)
    {
        // Make sure we're in the right state to Deactivate.
        if (!_isActive)
        {
            return(ModuleResult.AlreadyInactive);
        }

        ModuleResult result = OnDeactivation(module);

        MechaCoreComponent core = module.MechaCore;

        core.computer.DeallocateCpu(cpuResources);
        core.power.Free(energyUse);
        _isActive = false;

        return(result);
    }
Beispiel #7
0
    public OperationResult InstallModuleIn(Hardpoint hardpoint, GameObject prefab)
    {
        ModuleResult res = hardpoints.CanInstallModuleInto(hardpoint, prefab);

        switch (res)
        {
        case ModuleResult.Success:
            ActorModule module = ActorModule.Instantiate(prefab, hardpoint, gameObject);
            hardpoints.RegisterInstalledModuleIn(hardpoint, module);
            return(OperationResult.OK());

        case ModuleResult.HardpointNotEmpty:
            return(OperationResult.Fail("Selected hardpoint is not empty"));

        case ModuleResult.IncompatibleSocket:
            return(OperationResult.Fail("Module cannot be installed in selected hardpoint"));

        default:
            return(OperationResult.Fail("Failed to install Module: " + res.ToString()));
        }
    }
    /// <summary>
    /// Try and remove the currently installed module from the provided Hardpoint.
    /// </summary>
    /// <param name="reason">The reason why the module was being removed.</param>
    /// <param name="prefab">Holds the prefab that was used to create the module, or null.</param>
    public ModuleResult RemoveModuleFrom(Hardpoint hardpoint, ActorModule.Change reason, out GameObject prefab)
    {
        ModuleResult result = DisableModuleIn(hardpoint);

        if (result != ModuleResult.Success && result != ModuleResult.AlreadyDisabled)
        {
            prefab = null;
            return(result);
        }

        ActorModule module = hardpoint.Module;

        Clear(hardpoint);

        if (onChange != null)
        {
            onChange(reason, module);
        }

        prefab = module.DestroyModule();
        return(ModuleResult.Success);
    }
    /// <summary>
    /// Trigger the activation for the component.
    /// </summary>
    public ModuleResult Activate(ActorModule module)
    {
        // Do the basic checks to see if we can activate it.
        if (_isActive)
        {
            return(ModuleResult.AlreadyActive);
        }
        else if (_cooldown != null)
        {
            return(ModuleResult.InCooldownState);
        }

        // Check if we are using ammo, and if so, that we have some.
        AmmoStoreComponent ammoStore = module.ammoStore;

        if (ammoStore != null && !ammoStore.HasAmmo)
        {
            if (ammoStore.IsReloading)
            {
                return(ModuleResult.Reloading);
            }
            else
            {
                return(ModuleResult.NoAmmo);
            }
        }

        // Try and allocate the resources for the activation.
        MechaCoreComponent core = module.MechaCore;

        if (!core.computer.AllocateCpu(cpuResources))
        {
            return(ModuleResult.InsufficientCpu);
        }

        if ((isContinuous && !core.power.Reserve(energyUse)) ||
            (!core.power.Consume(energyUse)))
        {
            core.computer.DeallocateCpu(cpuResources);
            return(ModuleResult.InsufficientPower);
        }

        // All good, so do the activation.
        _isActive = true;
        ModuleResult result = OnActivation(module);


        if (result != ModuleResult.Success)
        {
            core.computer.DeallocateCpu(cpuResources);
            if (isContinuous)
            {
                core.power.Free(energyUse);
            }
            _isActive = false;
        }
        else if (!isContinuous)
        {
            core.computer.DeallocateCpu(cpuResources);
            _isActive = false;
            StartCooldown();
        }

        return(result);
    }
 public virtual ModuleResult OnDeactivation(ActorModule module)
 {
     return(ModuleResult.NotImplemented);
 }
Beispiel #11
0
 /// <summary>
 /// Set the module that is currently installed in the HardPoint.
 /// </summary>
 public void SetModule(ActorModule module)
 {
     this.module = module;
 }
Beispiel #12
0
 /// <summary>
 /// Clear any references from the HardPoint, for when the module is removed from it.
 /// </summary>
 public void Clear()
 {
     SetTarget(null);
     module = null;
 }
Beispiel #13
0
 /// <summary>Default constructor</summary>
 public Hardpoint()
 {
     name      = null;
     arcLimits = new TurretArc(45, 45, 45, 0);
     module    = null;
 }