public IvyCreeper(NWGameSpace space, object owner, int creatureID, bool total, bool setName) : base(space, owner, creatureID, total, setName) { IvyBranchRec rec = dbIvyBranches[0]; IvySegment seg = (IvySegment)Add(); seg.X = -1; seg.Y = -1; seg.Id = 0; seg.EntryDir = Directions.DtNone; seg.AvailableEntries = new Directions(rec.Entries); seg.ImageIndex = 0; }
public override void DoTurn() { try { base.DoTurn(); CheckTile(false); if (AuxUtils.Chance(25)) { int idx; if (Size == 1) { idx = 0; } else { idx = RandomHelper.GetRandom(Size); } IvySegment seg = (IvySegment)GetSegment(idx); if (dbIvyBranches[seg.Id].Kind == IvyBranches.ibkLeaf) { idx = GetBranchByDir(seg.EntryDir, new IvyBranches(IvyBranches.ibkBranch)); if (idx >= 0) { Directions avEntries = new Directions(dbIvyBranches[idx].Entries); avEntries.Exclude(seg.EntryDir); seg.Id = idx; seg.AvailableEntries = avEntries; seg.ImageIndex = idx; } } int cnt = 0; List <int> entries = new List <int>(); for (int dir = Directions.DtNorth; dir <= Directions.DtEast; dir++) { if (seg.AvailableEntries.Contains(dir)) { cnt++; entries.Add(dir); } } if (cnt == 0) { return; } idx = RandomHelper.GetRandom(cnt); int bdir = entries[idx]; int nx = seg.X + Directions.Data[bdir].DX; int ny = seg.Y + Directions.Data[bdir].DY; seg.AvailableEntries.Exclude(bdir); int i = FindByPos(nx, ny); if (!CurrentMap.IsBarrier(nx, ny) && i < 0) { int opposite = Directions.Data[bdir].Opposite; idx = GetBranchByDir(opposite, new IvyBranches(IvyBranches.ibkBranch, IvyBranches.ibkLeaf)); if (idx >= 0) { Directions avEntries = new Directions(dbIvyBranches[idx].Entries); avEntries.Exclude(opposite); IvySegment newSeg = (IvySegment)Add(); newSeg.X = nx; newSeg.Y = ny; newSeg.Id = idx; newSeg.EntryDir = opposite; newSeg.AvailableEntries = avEntries; newSeg.ImageIndex = idx; } } } CheckTile(true); } catch (Exception ex) { Logger.Write("IvyCreeper.doTurn(): " + ex.Message); } }