public void RedrawOnGround(CompiledRune rune, HexXY refPos) { HexXY pos = refPos + rune.relPos; if (Level.S.GetEntities(pos).Any(e => e is Rune)) { return; } Rune groundRune = new Rune(rune.dir); groundRune.entityType = (uint)rune.type; groundRune.Spawn(pos); for (int i = 0; i < 6; i++) { var n = rune.neighs[i]; if (n != null) { RedrawOnGround(n, refPos); } } }
public static Spell Load(System.IO.BinaryReader reader) { Spell spell = new Spell(); uint runeCount = reader.ReadUInt32(); for (uint i = 0; i < runeCount; i++) { var rune = new CompiledRune( (RuneType)reader.ReadUInt32(), new HexXY(reader.ReadInt32(), reader.ReadInt32()), reader.ReadUInt32(), i); if (i == 0) { spell.root = rune; } spell.allRunes.Add(rune); } for (int i = 0; i < runeCount; i++) { var rune = spell.allRunes[i]; for (int k = 0; k < 6; k++) { int idx = reader.ReadInt32(); if (idx != -1) { rune.neighsListIdxs[k] = idx; rune.neighs[k] = spell.allRunes[idx]; } } } return(spell); }
public void Compile(Rune compileRune, HexXY compileRunePos, List <Rune> visSeq = null) { HexXY refPos = realWorldStartRunePos = compileRunePos; root = new CompiledRune((RuneType)compileRune.entityType, new HexXY(0, 0), compileRune.dir, 0); allRunes.Add(root); compilationFront.Clear(); compilationMap.Clear(); compilationFront.Enqueue(root); compilationMap.Add(compileRunePos, root); //Nice visualization support included uint compileNextBatchCount = 0; uint compileBatchCount = 1; CompiledRune c; do { c = compilationFront.Dequeue(); if (visSeq != null) { visSeq.Add(GetRealRune(c)); } for (int i = 0; i < 6; i++) { var d = HexXY.neighbours[i]; var np = refPos + c.relPos + d; Rune rune = (Rune)Level.S.GetEntities(np).FirstOrDefault(ent => ent is Rune); if (rune == null) { continue; } CompiledRune nrune; if (compilationMap.TryGetValue(np, out nrune)) { int reverseIdx = (i + 3) % 6; c.neighs[i] = nrune; c.neighsListIdxs[i] = (int)nrune.listIdx; nrune.neighs[reverseIdx] = c; nrune.neighsListIdxs[reverseIdx] = (int)c.listIdx; } else { nrune = new CompiledRune((RuneType)rune.entityType, c.relPos + d, rune.dir, (uint)allRunes.Count); allRunes.Add(nrune); compilationFront.Enqueue(nrune); compilationMap.Add(np, nrune); compileNextBatchCount++; } } compileBatchCount--; if (compileBatchCount == 0) { compileBatchCount = compileNextBatchCount; compileNextBatchCount = 0; if (visSeq != null) { visSeq.Add(null); //Pause } } } while (compilationFront.Count > 0); //foreach (var r in spell.allRunes) // Logger.Log(r.relPos + " " + r.type); }
public Rune GetRealRune(CompiledRune compRune) { return(Level.S.GetEntities(realWorldStartRunePos + compRune.relPos).OfType <Rune>().First()); }