示例#1
0
        public void FinishConstruction(bool ignoreState, bool ignoreListener)
        {
            int state = this.m_level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                if (this.m_level.GetHomeOwnerAvatar() != null &&
                    this.m_level.GetHomeOwnerAvatar().IsClientAvatar())
                {
                    if (this.m_constructionTimer != null)
                    {
                        this.m_constructionTimer.Destruct();
                        this.m_constructionTimer = null;
                    }

                    LogicAvatar            homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                    LogicVillageObjectData data            = this.GetVillageObjectData();

                    if (data.IsRequiresBuilder())
                    {
                        this.m_level.GetWorkerManagerAt(data.GetVillageType()).DeallocateWorker(this);
                    }

                    this.m_locked = false;

                    if (this.m_upgLevel != 0 || this.m_upgrading)
                    {
                        int nextUpgLevel = this.m_upgLevel + 1;

                        if (this.m_upgLevel >= data.GetUpgradeLevelCount() - 1)
                        {
                            Debugger.Warning("LogicVillageObject - Trying to upgrade to level that doesn't exist! - " + data.GetName());
                            nextUpgLevel = data.GetUpgradeLevelCount() - 1;
                        }

                        int constructionTime = data.GetBuildTime(nextUpgLevel);
                        int xpGain           = LogicMath.Sqrt(constructionTime);

                        this.m_upgLevel = nextUpgLevel;

                        this.XpGainHelper(xpGain, homeOwnerAvatar, ignoreState);
                    }
                    else
                    {
                        int constructionTime = data.GetBuildTime(0);
                        int xpGain           = LogicMath.Sqrt(constructionTime);

                        this.XpGainHelper(xpGain, homeOwnerAvatar, ignoreState);
                    }

                    this.m_upgrading = false;

                    if (this.m_listener != null)
                    {
                        this.m_listener.RefreshState();
                    }

                    if (state == 1)
                    {
                        this.m_level.GetAchievementManager().RefreshStatus();
                    }
                }
                else
                {
                    Debugger.Error("LogicVillageObject::finishCostruction failed - Avatar is null or not client avatar");
                }
            }
        }
        public override void FindPath(LogicVector2 startPosition, LogicVector2 endPosition, bool clampPathFinderCost)
        {
            this.m_maxHeapLength = 0;

            if (this.m_tileMap.IsPassablePathFinder(startPosition.m_x, startPosition.m_y))
            {
                if (!this.IsReachable(endPosition.m_x, endPosition.m_y) && clampPathFinderCost)
                {
                    int distance = LogicMath.Sqrt((endPosition.m_x - startPosition.m_x) * (endPosition.m_x - startPosition.m_x) +
                                                  (endPosition.m_y - startPosition.m_y) * (endPosition.m_y - startPosition.m_y));
                    int lowDistanceX  = LogicMath.Clamp(endPosition.m_x - distance, 0, 2 * this.m_mapWidth);
                    int lowDistanceY  = LogicMath.Clamp(endPosition.m_y - distance, 0, 2 * this.m_mapHeight);
                    int highDistanceX = LogicMath.Clamp(endPosition.m_x + distance, 0, 2 * this.m_mapWidth);
                    int highDistanceY = LogicMath.Clamp(endPosition.m_y + distance, 0, 2 * this.m_mapHeight);

                    int minX        = -1;
                    int minY        = -1;
                    int minDistance = 0x7FFFFFFF;

                    while (lowDistanceX < highDistanceX)
                    {
                        int posX = lowDistanceX;

                        for (int posY = lowDistanceY; posY < highDistanceY; posY++)
                        {
                            if (this.IsReachable(posX, posY))
                            {
                                int pointDistance = (posX - endPosition.m_x) * (posX - endPosition.m_x) +
                                                    (posY - endPosition.m_y) * (posY - endPosition.m_y);

                                if (pointDistance < minDistance)
                                {
                                    minX        = posX;
                                    minY        = posY;
                                    minDistance = pointDistance;
                                }
                            }
                        }

                        ++lowDistanceX;
                    }

                    if (minX == -1)
                    {
                        this.m_pathLength = 0;
                        return;
                    }

                    endPosition.m_x = minX;
                    endPosition.m_y = minY;
                }

                if (this.IsReachable(endPosition.m_x, endPosition.m_y))
                {
                    int startTileIndex = startPosition.m_x + startPosition.m_y * this.m_mapWidth;
                    int endTileIndex   = endPosition.m_x + endPosition.m_y * this.m_mapWidth;

                    if (this.IsLineOfSightClear(startPosition.m_x, startPosition.m_y, endPosition.m_x, endPosition.m_y))
                    {
                        this.m_pathLength = 0;
                        this.m_pathBuffer[this.m_pathLength++] = endTileIndex;
                        this.m_pathBuffer[this.m_pathLength++] = startTileIndex;
                    }
                    else
                    {
                        this.AStar(startTileIndex, endTileIndex);

                        if (this.m_pathLength > 0)
                        {
                            this.m_pathBuffer[this.m_pathLength++] = startTileIndex;
                        }
                    }
                }
                else
                {
                    this.m_pathLength = 0;
                }
            }
            else
            {
                this.m_pathLength = 0;
            }
        }
示例#3
0
 /// <summary>
 ///     Converts the specified time to exp point.
 /// </summary>
 public static int TimeToExp(int time)
 {
     return(LogicMath.Sqrt(time));
 }