private bool StepInitialize(short MapIdx, short sRPIndex, short dRPIndex) { this.ClearNodes(); this.m_sRPIdx = sRPIndex; this.m_dRPIdx = dRPIndex; GxRP gxRP = (this.m_sRPIdx <= 0) ? this.m_sTmpRP : this.m_pkRPSys.GetRP(MapIdx, (int)this.m_sRPIdx); GxRP gxRP2 = (this.m_dRPIdx <= 0) ? this.m_dTmpRP : this.m_pkRPSys.GetRP(MapIdx, (int)this.m_dRPIdx); this.m_iSX = (int)gxRP.GetX(); this.m_iSY = (int)gxRP.GetY(); this.m_iDX = (int)gxRP2.GetX(); this.m_iDY = (int)gxRP2.GetY(); GxRpAsNode gxRpAsNode = new GxRpAsNode(this.m_sRPIdx); gxRpAsNode.g = 0; gxRpAsNode.h = Math.Abs((int)(gxRP2.GetX() - gxRP.GetX())) + Math.Abs((int)(gxRP2.GetY() - gxRP.GetY())); gxRpAsNode.f = gxRpAsNode.g + gxRpAsNode.h; this.m_pOpen = gxRpAsNode; return(true); }
private void LinkedChild(short sMapIndex, ref GxRpAsNode parentNode, ref GxRpAsNode childNode) { short rPIdx = childNode.RPIdx; GxRP gxRP = (rPIdx <= 0) ? ((rPIdx != -100) ? this.m_dTmpRP : this.m_sTmpRP) : this.m_pkRPSys.GetRP(sMapIndex, (int)rPIdx); int num = parentNode.g + 1; GxRpAsNode gxRpAsNode = null; gxRpAsNode = this.CheckList(this.m_pOpen, rPIdx); if (gxRpAsNode != null) { parentNode.child.Add(gxRpAsNode); if (num < gxRpAsNode.g) { gxRpAsNode.parent = parentNode; gxRpAsNode.g = num; gxRpAsNode.f = num + gxRpAsNode.h; } } else { gxRpAsNode = this.CheckList(this.m_pClosed, rPIdx); if (gxRpAsNode != null) { parentNode.child.Add(gxRpAsNode); if (num < gxRpAsNode.g) { gxRpAsNode.parent = parentNode; gxRpAsNode.g = num; gxRpAsNode.f = num + gxRpAsNode.h; this.UpdateParents(ref gxRpAsNode); } } else { GxRpAsNode gxRpAsNode2 = new GxRpAsNode(rPIdx); gxRpAsNode2.parent = parentNode; gxRpAsNode2.g = num; gxRpAsNode2.h = Math.Abs((int)gxRP.GetX() - this.m_iDX) + Math.Abs((int)gxRP.GetY() - this.m_iDY); gxRpAsNode2.f = gxRpAsNode2.g + gxRpAsNode2.h; gxRpAsNode2.sMapIdx = sMapIndex; this.AddToOpen(ref gxRpAsNode2); parentNode.child.Add(gxRpAsNode2); } } }
private bool AutoLinkRPs(short MapIndex, short sRPIndex) { if (!this.UnLinkAll(MapIndex, sRPIndex)) { return(false); } GxRP gxRP = this.m_RPList[MapIndex][(int)sRPIndex]; int num = 0; this.m_ValidList.Clear(); this.m_FinalList.Clear(); this.GetValidRangeRPIndexes(gxRP.GetMapIndex(), gxRP.GetX(), gxRP.GetY(), false); if (this.m_ValidList.Count <= 4) { for (int i = 0; i < this.m_ValidList.Count; i++) { this.LinkRP(MapIndex, sRPIndex, this.m_ValidList[i]); } return(true); } for (int j = 0; j < this.m_ValidList.Count; j++) { if (sRPIndex != this.m_ValidList[j]) { GxRP rP = this.GetRP(MapIndex, (int)this.m_ValidList[j]); if (rP.GetLinkedCount() > 1) { short num2 = this.m_ValidList[j]; int num3 = rP.CalcCost(rP.GetX(), rP.GetY()); for (int k = 0; k < 4; k++) { if (rP.GetLinkedRP(k) != 0) { if (this.m_ValidList.Contains(rP.GetLinkedRP(k))) { GxRP rP2 = this.GetRP(MapIndex, (int)rP.GetLinkedRP(k)); int num4 = rP2.CalcCost(gxRP.GetX(), gxRP.GetY()); if (rP2 != null && num4 <= num3) { num2 = rP.GetLinkedRP(j); num3 = num4; } } } } if (!this.m_FinalList.Contains(num2)) { this.m_FinalList.AddFirst(num2); num++; } if (num2 != this.m_ValidList[j] && !this.m_FinalList.Contains(this.m_ValidList[j])) { this.m_FinalList.AddLast(this.m_ValidList[j]); } } else { this.m_FinalList.AddFirst(this.m_ValidList[j]); num++; } } } if (num > 4) { Debug.Log("MAX_LINK Over :" + sRPIndex.ToString()); return(false); } int num5 = 0; foreach (short current in this.m_FinalList) { if (num5 == 4) { break; } this.LinkRP(MapIndex, sRPIndex, current); num5++; } return(true); }