예제 #1
0
    private void _DistributeContractToAssignedDesks()
    {
        CContract contract = null;

        for (int i = 0; i < mWorld.mContracts.Count; ++i)
        {
            CContract c = mWorld.mContracts[i];
            if (c.mOwner == mPlayerId && c.GetUndistributedStacks() > 0)
            {
                contract = c;
                break;
            }
        }

        if (contract == null)
        {
            return;
        }

        for (int i = 0; i < mWorld.mItemProxies[mPlayerId].Count; ++i)
        {
            CItemProxy proxy = mWorld.mItemProxies[mPlayerId][i];

            if (proxy.mAsset.mItemType == EItemType.DESK && !proxy.mBlueprint && proxy.mAssignedUnitID != -1)
            {
                if (proxy.mAssignedPaperStacks.Count < proxy.mMaxPaperStackSlots)
                {
                    mWorld.ControllerDistributeContract(mPlayerId, contract.mID, proxy.mID);
                    return;
                }
            }
        }
    }
예제 #2
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Копирование параметров с указанного объекта
            /// </summary>
            /// <param name="source_object">Объект источник с которого будут скопированы параметры</param>
            //---------------------------------------------------------------------------------------------------------
            public override void CopyParameters(System.Object source_object)
            {
                base.CopyParameters(source_object);
                if (source_object != null && source_object is CContract)
                {
                    CContract source = source_object as CContract;

                    Subject  = source.mSubject;
                    Number   = source.mNumber;
                    Group    = source.mGroup;
                    SubGroup = source.mSubGroup;

                    DateOfConclusion = source.mDateOfConclusion;
                    Deadline         = source.mDeadline;

                    PlanedValue  = source.PlanedValue;
                    ClosureValue = source.ClosureValue;
                    ValueUnit    = source.ValueUnit;

                    PriceLocal    = source.mPriceLocal;
                    PriceRegional = source.mPriceRegional;
                    PriceFederal  = source.mPriceFederal;
                    PriceExtra    = source.mPriceExtra;

                    ClosureLocal    = source.ClosureLocal;
                    ClosureRegional = source.ClosureRegional;
                    ClosureFederal  = source.ClosureFederal;
                    ClosureExtra    = source.ClosureExtra;

                    ActivityStageID = source.ActivityStageID;
                    CustomerID      = source.CustomerID;
                    ContractorID    = source.ContractorID;
                }
            }
예제 #3
0
 public virtual CContractResult OnRequestReceived(CContract contract)
 {
     return(new CContractResult()
     {
         IsError = true, ErrorCode = 0
     });
 }
예제 #4
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Получение копии объекта
            /// </summary>
            /// <returns>Копия объекта</returns>
            //---------------------------------------------------------------------------------------------------------
            public override System.Object Clone()
            {
                CContract clone = new CContract();

                clone.CopyParameters(this);
                return(clone);
            }
예제 #5
0
    /// <summary>
    /// Create a contract for specified player.
    /// </summary>
    public CContract GenerateContract(int PlayerID)
    {
        CContract contract = CEntity.Create <CContract>(_world);

        contract.InitContract(this, mPlayerTier[PlayerID], PlayerID);
        return(contract);
    }
예제 #6
0
 public void CopyState(CContract Contract)
 {
     mNewOwner            = Contract.mOwner;
     mStackCount          = Contract.mStackCount;
     mUndistributedStacks = Contract.GetUndistributedStacks();
     mAcceptedTime        = Contract.mAcceptedTime;
     mUncompletedStacks   = Contract.GetUncompletedStacks();
 }
예제 #7
0
    private void _GetFirstAvailableContract()
    {
        for (int i = 0; i < mWorld.mContracts.Count; ++i)
        {
            CContract c = mWorld.mContracts[i];

            if (c.mOwner == -1)
            {
                mWorld.ControllerAcceptNotify(c.mID, mPlayerId);
                break;
            }
        }
    }
예제 #8
0
 public void CopyInitialState(CContract Contract)
 {
     mID             = Contract.mID;
     mOwner          = Contract.mOwner;
     mName           = Contract.mName;
     mTier           = Contract.mTier;
     mCompanyName    = Contract.mCompany.mName;
     mPenalty        = Contract.mPenalty;
     mDeadline       = Contract.mDeadlineTime;
     mValue          = Contract.mTotalStartPapers;
     mAvailableUntil = Contract.mAvailableUntil;
     mAvailableFor   = Contract.mAvailableFor;
 }
예제 #9
0
 /// <summary>
 /// Remove a contract assignment.
 /// </summary>
 public void RemoveContractPapers(CContract Contract)
 {
     for (int i = 0; i < mAssignedPaperStacks.Count; ++i)
     {
         if (mAssignedPaperStacks[i].mContract == Contract)
         {
             mPaperStackUpdateTick = mWorld.mGameTick;
             mAssignedPaperStacks[i].mDistributed = false;
             mAssignedPaperStacks.RemoveAt(i);
             --i;
         }
     }
 }
예제 #10
0
    /// <summary>
    /// Creates entity and assigns ID.
    /// </summary>
    public static CEntity Create(EType Type, CWorld World, int ID = 0)
    {
        CEntity entity = null;

        switch (Type)
        {
        case EType.UNIT: entity = new CUnit(); break;

        case EType.ITEM_START: entity = new CItemStart(); break;

        case EType.ITEM_DECO: entity = new CItemDeco(); break;

        case EType.ITEM_DESK: entity = new CItemDesk(); break;

        case EType.ITEM_SAFE: entity = new CItemSafe(); break;

        case EType.ITEM_REST: entity = new CItemRest(); break;

        case EType.ITEM_FOOD: entity = new CItemFood(); break;

        case EType.ITEM_DOOR: entity = new CItemDoor(); break;

        case EType.RESUME: entity = new CResume(); break;

        case EType.CONTRACT: entity = new CContract(); break;

        case EType.PICKUP: entity = new CPickup(); break;

        case EType.MISSILE: entity = new CMissile(); break;

        case EType.VOLUME: entity = new CVolume(); break;

        case EType.DECAL: entity = new CDecal(); break;
        }

        if (entity != null)
        {
            _InitNewEntity(entity, World, ID);
        }
        else
        {
            Debug.LogError("Entity Factory couldn't create a " + (int)Type + " is");
        }

        return(entity);
    }
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Конфигурирование моделей
            /// </summary>
            /// <param name="model_builder">Интерфейс для построения моделей</param>
            //---------------------------------------------------------------------------------------------------------
            protected override void OnModelCreating(ModelBuilder model_builder)
            {
                // СУБЪЕКТЫ ГРАЖДАНСКИХ ПРАВООТНОШЕНИЙ
                CSubjectCivil.ModelCreating(model_builder);
                CIndividualPerson.ModelCreating(model_builder);
                CLegalEntityBase.ModelCreating(model_builder);
                CLegalEntity.ModelCreating(model_builder);
                CPublicAuthority.ModelCreating(model_builder);

                // МУНИЦИПАЛЬНЫЕ ПРОГРАММЫ И ЭЛЕМЕНТЫ
                CMunicipalProgram.ModelCreating(model_builder);
                CMunicipalSubProgram.ModelCreating(model_builder);
                CMunicipalProgramIndicator.ModelCreating(model_builder);
                CMunicipalProgramIndicatorData.ModelCreating(model_builder);
                CMunicipalProgramActivity.ModelCreating(model_builder);
                CMunicipalProgramActivityStage.ModelCreating(model_builder);

                // КОНТРАКТЫ
                CContract.ModelCreating(model_builder);

                // ТЕРРИТОРИАЛЬНО-АДРЕСНОЕ ХОЗЯЙСТВО
                //CVillageSettlement.ModelCreating(model_builder);
                //CVillage.ModelCreating(model_builder);
            }
예제 #12
0
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Сравнение объектов для упорядочивания
 /// </summary>
 /// <param name="other">Сравниваемый объект</param>
 /// <returns>Статус сравнения объектов</returns>
 //---------------------------------------------------------------------------------------------------------
 public Int32 CompareTo(CContract other)
 {
     return(mName.CompareTo(other.Name));
 }
예제 #13
0
 public CContractResult Request(CContract contract)
 {
     return(OnRequestReceived(contract));
 }
예제 #14
0
    /// <summary>
    /// Update entire view and alert session of changes.
    /// </summary>
    public bool Update(Vector2 MouseFloorPos)
    {
        // This is the only time that we lock the world on the primary thread (Except for rare debugging cases in CGameSession).
        // All state information is copied from the world from the perspective of a player (_viewPlayerIndex).
        // As little work as possible should be done during the state copy. We want to unlock the world ASAP.

        CGame.PrimaryThreadProfiler.Push(CProfiler.EID.I_RENDER_TICK);
        lock (_world)
        {
            // TODO: Check for a console var to remain on crash.
            if (_world.mCrashed)
            {
                CGame.PrimaryThreadProfiler.Pop();
                return(false);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            CGame.PrimaryThreadProfiler.Push(CProfiler.EID.I_RENDER_TICK);

            // Copy door segments for visibility
            _world.mMap.TrimStaticVisSegments();
            for (int i = 0; i < _world.mItems.Count; ++i)
            {
                CItem item = _world.mItems[i];
                if (item.mType == CEntity.EType.ITEM_DOOR && !item.mBluerprint && !(item as CItemDoor).mOpen)
                {
                    _world.mMap.mStaticVisSegments.Add(new CVisibilityBlockingSegment(item.ItemToWorldSpacePosition(new Vector2(0, 1)), item.ItemToWorldSpacePosition(new Vector2(1, 1))));
                }
            }

            // Copy all the state!!!!!
            mTransientEvents       = _world.SwapAndClearTransientEvents();
            mPaydayTimerNormalised = 1.0f - _world.GetPaydayTimeNormalize();
            mGameTick = _world.mGameTick;

            // Company Data
            // ...

            // Player Data
            for (int i = 0; i < mPlayerViews.Length; ++i)
            {
                CPlayer     player = _world.mPlayers[i];
                CPlayerView view   = mPlayerViews[i];

                view.mIndex                = player.mID;
                view.mColor                = player.mColor;
                view.mMoney                = player.mMoney;
                view.mDebt                 = player.mDebt;
                view.mSpawnPos             = player.GetSpawnPos();
                view.mCanInteractWithWorld = player.mCanInteractWithWorld;
                view.mCanInteractWithUI    = player.mCanInteractWithUI;
                view.mCanControlCamera     = player.mCanControlCamera;
                view.mMusicTrack           = player.mMusicTrack;
                view.mShowUI               = player.mShowUI;
                view.mCamPosition          = player.mCamPosition;
                view.mCamSpeed             = player.mCamSpeed;
                view.mAvailableItems       = player.mAvailableItems.ToArray();
            }

            // TODO: Should just iterate all entities and ask them if they are valid for state copy.

            // Unit Data
            // TODO: Surely the sim knows what units are visible to the player already?
            for (int i = 0; i < _world.mUnits.Count; ++i)
            {
                if (_world.mUnits[i].IsVisibleToPlayer(_viewPlayerIndex))
                {
                    if (_world.mUnits[i].mStateView == null)
                    {
                        CUnitView view = new CUnitView();
                        view.mState = CStateView.EState.NEW;
                        mStateViews.Add(view);
                        view.CopyInitialState(_world.mUnits[i]);
                        view.Init(_viewPlayerIndex, this);
                        _world.mUnits[i].mStateView = view;
                    }
                    else
                    {
                        _world.mUnits[i].mStateView.mState = CStateView.EState.UPDATING;
                    }

                    _world.mUnits[i].mStateView.CopyState(_world.mUnits[i]);
                }
                else
                {
                    _world.mUnits[i].mStateView = null;
                }
            }

            // Pickups
            for (int i = 0; i < _world.mPickups.Count; ++i)
            {
                if (_world.mPickups[i].IsVisibleToPlayer(_viewPlayerIndex))
                {
                    if (_world.mPickups[i].mStateView == null)
                    {
                        CPickupView view = new CPickupView();
                        view.mState = CStateView.EState.NEW;
                        mStateViews.Add(view);
                        view.CopyInitialState(_world.mPickups[i]);
                        view.Init(_viewPlayerIndex, this);
                        _world.mPickups[i].mStateView = view;
                    }
                    else
                    {
                        _world.mPickups[i].mStateView.mState = CStateView.EState.UPDATING;
                    }

                    _world.mPickups[i].mStateView.CopyState(_world.mPickups[i]);
                }
                else
                {
                    _world.mPickups[i].mStateView = null;
                }
            }

            // Missiles
            for (int i = 0; i < _world.mMissiles.Count; ++i)
            {
                if (_world.mMissiles[i].IsVisibleToPlayer(_viewPlayerIndex))
                {
                    if (_world.mMissiles[i].mStateView == null)
                    {
                        CMissileView view = new CMissileView();
                        view.mState = CStateView.EState.NEW;
                        mStateViews.Add(view);
                        view.CopyInitialState(_world.mMissiles[i]);
                        view.Init(_viewPlayerIndex, this);
                        _world.mMissiles[i].mStateView = view;
                    }
                    else
                    {
                        _world.mMissiles[i].mStateView.mState = CStateView.EState.UPDATING;
                    }

                    _world.mMissiles[i].mStateView.CopyState(_world.mMissiles[i]);
                }
                else
                {
                    _world.mMissiles[i].mStateView = null;
                }
            }

            // Item View Data
            for (int i = 0; i < _world.mItemProxies[_viewPlayerIndex].Count; ++i)
            {
                CItemProxy proxy = _world.mItemProxies[_viewPlayerIndex][i];

                if (proxy.mVisuals == null)
                {
                    // new
                    CItemView view = new CItemView();
                    view.mState = CStateView.EState.NEW;
                    mStateViews.Add(view);
                    view.CopyInitialState(proxy);
                    view.Init(_viewPlayerIndex, this);
                    proxy.mVisuals = view;
                }
                else
                {
                    proxy.mVisuals.mState = CStateView.EState.UPDATING;
                }

                proxy.mVisuals.CopyState(proxy);
            }

            // Contract Data
            for (int i = 0; i < _world.mContracts.Count; ++i)
            {
                CContract contract = _world.mContracts[i];

                // TODO: All contracts always part of user view state?
                //if (contract.mOwner == -1 || contract.mOwner == _viewPlayerIndex)
                if (true)
                {
                    if (contract.mStateView == null)
                    {
                        // new
                        CContractView view = new CContractView();
                        view.mState = CStateView.EState.NEW;
                        mStateViews.Add(view);
                        view.CopyInitialState(contract);
                        view.Init(_viewPlayerIndex, this);
                        contract.mStateView = view;
                    }
                    else
                    {
                        contract.mStateView.mState = CStateView.EState.UPDATING;
                    }

                    contract.mStateView.CopyState(contract);
                }
                else
                {
                    contract.mStateView = null;
                }
            }

            // Resume View Data
            for (int i = 0; i < _world.mResumes.Count; ++i)
            {
                CResume resume = _world.mResumes[i];

                if (resume.mOwner != -1)
                {
                    if (resume.mStateView == null)
                    {
                        // new
                        CResumeView view = new CResumeView();
                        view.mState = CStateView.EState.NEW;
                        mStateViews.Add(view);
                        view.CopyInitialState(resume);
                        view.Init(_viewPlayerIndex, this);
                        resume.mStateView = view;
                    }
                    else
                    {
                        resume.mStateView.mState = CStateView.EState.UPDATING;
                    }

                    resume.mStateView.CopyState(resume);
                }
                else
                {
                    resume.mStateView = null;
                }
            }

            // Decal View Data
            for (int i = 0; i < _world.mDecals.Count; ++i)
            {
                CDecal decal = _world.mDecals[i];

                // TODO: Allow decals to be visible to certain players only.

                if (decal.mStateView == null)
                {
                    // new
                    CDecalView view = new CDecalView();
                    view.mState = CStateView.EState.NEW;
                    mStateViews.Add(view);
                    view.CopyInitialState(decal);
                    view.Init(_viewPlayerIndex, this);
                    decal.mStateView = view;
                }
                else
                {
                    decal.mStateView.mState = CStateView.EState.UPDATING;
                }

                decal.mStateView.CopyState(decal);
            }

            sw.Stop();
            //Debug.Log("Copy " + sw.Elapsed.TotalMilliseconds + "ms");

            CGame.PrimaryThreadProfiler.Pop();
        }
        CGame.PrimaryThreadProfiler.Pop();

        // NOTE: Now that the state has been copied from the simulation and we have released the thread lock, we can
        // process the new state and make appropriate changes to the Unity scene.

        CGame.UIManager.PlayMusic(mPlayerViews[_viewPlayerIndex].mMusicTrack);
        CGame.UIManager.mShowUI       = mPlayerViews[_viewPlayerIndex].mShowUI;
        _userSession.mUserInteraction = mPlayerViews[_viewPlayerIndex].mCanInteractWithWorld;
        CGame.CameraManager.SetInteractable(mPlayerViews[_viewPlayerIndex].mCanControlCamera);
        CGame.CameraManager.SetLerpSpeed(mPlayerViews[_viewPlayerIndex].mCamSpeed);

        // TODO: Different bool to control tracked camera?
        if (!mPlayerViews[_viewPlayerIndex].mCanControlCamera)
        {
            // TODO: Immediate of on different cam step.
            CGame.CameraManager.SetTargetPosition(mPlayerViews[_viewPlayerIndex].mCamPosition, false, mPlayerViews[_viewPlayerIndex].mCamPosition.w);
        }

        for (int i = 0; i < mTransientEvents.Count; ++i)
        {
            CTransientEvent tev = mTransientEvents[i];

            // Ignore events that occured over 1 second ago.
            if (mGameTick > tev.mGameTick + 20)
            {
                continue;
            }

            if ((tev.mViewerFlags & (1 << _viewPlayerIndex)) == 0)
            {
                continue;
            }

            if (tev.mType == CTransientEvent.EType.SOUND)
            {
                //AudioSource.PlayClipAtPoint(CGame.PrimaryResources.AudioClips[tev.mData], tev.mPosition, 1.0f);
                AudioClip  clip   = CGame.PrimaryResources.AudioClips[tev.mData];
                GameObject source = new GameObject("AudioPosOneShot");
                source.transform.SetParent(_userSession.mPrimaryScene.transform);
                source.transform.position = tev.mPosition;
                AudioSource audio = source.AddComponent <AudioSource>();
                audio.clip = clip;
                audio.outputAudioMixerGroup = CGame.UIResources.SoundsMixer;
                audio.spatialBlend          = 1.0f;
                audio.Play();
                GameObject.Destroy(source, clip.length);
            }
            else if (tev.mType == CTransientEvent.EType.UI_SOUND)
            {
                CGame.UIManager.PlaySound(CGame.PrimaryResources.AudioClips[tev.mData]);
            }
            else if (tev.mType == CTransientEvent.EType.EFFECT)
            {
                GameObject.Instantiate(CGame.PrimaryResources.Particles, tev.mPosition, Quaternion.identity);
                //CGame.CameraManager.Shake();
            }
            else if (tev.mType == CTransientEvent.EType.PAYDAY)
            {
                CGame.UIManager.PlaySound(CGame.PrimaryResources.AudioClips[17]);
            }
            else if (tev.mType == CTransientEvent.EType.NOTIFY)
            {
                Debug.Log("Got notify: " + tev.mMessage);
                _userSession.CreateNotifyStackIcon(2, null, CGame.AssetManager.GetAsset <CItemAsset>(tev.mMessage));
            }
        }

        for (int i = 0; i < mStateViews.Count; ++i)
        {
            if (!mStateViews[i].Update(_userSession))
            {
                mStateViews.RemoveAt(i);
                --i;
            }
            else
            {
                mStateViews[i].mState = CStateView.EState.WAITING;
                mStateViews[i].DrawDebugPrims();
            }
        }

        /*
         * for (int i = 0; i < _stateViews.Count; ++i)
         * {
         *      _stateViews[i].DrawDebugPrims();
         * }
         */

        if (CGame.VarShowFlowField.mValue)
        {
            DrawFlowField();
        }

        if (CGame.VarShowNavMesh.mValue)
        {
            mNavMesh.DebugDraw();
        }

        if (CGame.VarShowNavRect.mValue > 0)
        {
            _world.mMap.mNavMeshes[CGame.VarShowNavRect.mValue - 1].DebugDraw();
        }

        return(true);
    }