private static Dictionary <string, TextDef> ReadTexts(XmlDocument doc, Dictionary <string, CharSet> charsets) { XmlNodeList txt = doc.SelectNodes("//text"); Dictionary <string, TextDef> txts = new Dictionary <string, TextDef>(); foreach (XmlNode t in txt) { TextDef text = new TextDef() { Name = t.Attributes["name"].Value, Value = t.Attributes["value"].Value }; //CharSet def = (from cs in charsets // where cs.Name == t.Attributes["charset"].Value // select cs).ToList()[0]; //text.CharacterSet = def; text.CharacterSet = charsets[t.Attributes["charset"].Value]; txts.Add(text.Name, text); } return(txts); }
private static List <Renderable> ReadUsage(Dictionary <string, AnimationDef> animDefs, Dictionary <string, CharSet> charsets, Dictionary <string, TextDef> textDefs, Dictionary <string, UsageGroup> groupDefs, XmlNode time, TimeBlock parent) { List <Renderable> objects = new List <Renderable>(); for (int i = 0; i < time.ChildNodes.Count; i++) { XmlNode use = time.ChildNodes[i]; if (use.Name.ToLower() == "useanim") { //AnimationDef aDef = (from ad in animDefs // where ad.Name == use.Attributes["name"].Value // select ad).ToList()[0]; Animation a = new Animation(parent, animDefs[use.Attributes["name"].Value]) { X = int.Parse(use.Attributes["x"].Value), Y = int.Parse(use.Attributes["y"].Value) }; ReadRenderableParams(i, use, a); // read animation attributes a.Attributes = ReadUsageAttributes(use); objects.Add(a); } else if (use.Name.ToLower() == "usetext") { //TextDef tDef = (from t in textDefs // where t.Name == use.Attributes["name"].Value // select t).ToList()[0]; TextDef tdef; if (use.Attributes["text"] != null && use.Attributes["charset"] != null) { tdef = new TextDef() { CharacterSet = charsets[use.Attributes["charset"].Value], Value = use.Attributes["text"].Value }; } else { tdef = textDefs[use.Attributes["name"].Value]; } Text txt = new Text(parent, tdef) { X = int.Parse(use.Attributes["x"].Value), Y = int.Parse(use.Attributes["y"].Value), }; ReadRenderableParams(i, use, txt); // read text attributes txt.Attributes = ReadUsageAttributes(use); objects.Add(txt); } else if (use.Name.ToLower() == "usegroup") { UsageGroup g = groupDefs[use.Attributes["name"].Value]; foreach (Renderable o in g.Objects) { Renderable oClone = o.Clone(); oClone.ParentBlock = parent; objects.Add(oClone); } } } return(objects); }
private int convertObject(MapDef mapdef, int oid, byte tile) { Debug.Assert(already.Add(oid)); Debug.Assert(oid != oidFree); Debug.Assert(oid != oidEnd); int dir = (oid >> 14) & 3; int cat = (oid >> 10) & 15; int num = (oid) & 1023; int objRef = d.objs.Count; ObjDef newObj = null; si.Position = offsetsToDatabase[cat] + dbSizes[cat] * num; int nextOid = br.ReadUInt16(); bool isWall = ((tileTypeIndex)(tile >> 5)) == tileTypeIndex.ttWall; switch ((dbIndex)cat) { case dbIndex.dbDoor: { int attr = br.ReadUInt16(); bool doorType1 = 0 != (attr & 1); int ornateIndex = (attr >> 1) & 15; d.objs.Add(newObj = new DoorDef { doorType = doorType1 ? mapdef.doorType1 : mapdef.doorType0, doorOrnate = mapdef.doorDecorationGraphics[ornateIndex], openVertical = 0 != ((attr >> 5) & 1), button = 0 != ((attr >> 6) & 1), destroyablebyFireball = 0 != ((attr >> 7) & 1), bashablebyChopping = 0 != ((attr >> 8) & 1), //9 //10 //11 buttonState = 0 != ((attr >> 12) & 1), //13 //14 //15 }); break; } case dbIndex.dbTeleporter: { int attr = br.ReadUInt16(); int attr2 = br.ReadUInt16(); d.objs.Add(newObj = new TeleporterDef { destMap = (attr2 >> 8) & 255, destX = (attr >> 0) & 31, destY = (attr >> 5) & 31, rotation = (attr >> 10) & 3, absoluteRotation = 0 != ((attr >> 12) & 1), scope = (attr >> 13) & 3, sound = 0 != ((attr >> 15) & 1), }); break; } case dbIndex.dbText: { int attr = br.ReadUInt16(); d.objs.Add(newObj = new TextDef { textVisibility = 0 != ((attr >> 0) & 1), textMode = (attr >> 1) & 3, textIndex = (attr >> 3) & 0x1fff, }); break; } case dbIndex.dbActuator: { int attr = br.ReadUInt16(); int attr2 = br.ReadUInt16(); int attr3 = br.ReadUInt16(); d.objs.Add(newObj = new ActuatorDef { actuatorType = (attr >> 0) & 127, actuatorData = (attr >> 7) & 511, onceOnlyActuator = 0 != ((attr2 >> 2) & 1), actionType = (attr2 >> 3) & 3, inversion = 0 != ((attr2 >> 5) & 1), sound = 0 != ((attr2 >> 6) & 1), delay = (attr2 >> 7) & 15, floorOrnate = isWall ? -1 : (attr2 >> 12) & 15, wallOrnate = isWall ? (attr2 >> 12) & 15 : -1, newDirection = (attr3 >> 4) & 3, xCoord = (attr3 >> 6) & 31, yCoord = (attr3 >> 11) & 31, }); break; } case dbIndex.dbCreature: { int childOid = br.ReadUInt16(); int creatureType = br.ReadByte(); int position = br.ReadByte(); int hp1 = br.ReadUInt16(); int hp2 = br.ReadUInt16(); int hp3 = br.ReadUInt16(); int hp4 = br.ReadUInt16(); CreatureDef me; d.objs.Add(newObj = me = new CreatureDef { creatureType = creatureType, position = position, hp1 = hp1, hp2 = hp2, hp3 = hp3, hp4 = hp4, }); if (childOid != oidEnd) { me.childObjRef = convertObject(mapdef, childOid, tile); } break; } case dbIndex.dbWeapon: { int attr = br.ReadUInt16(); d.objs.Add(newObj = new WeaponDef { itemType = (attr >> 0) & 127, important = 0 != ((attr >> 7) & 1), charges = (attr >> 10) & 15, }); break; } case dbIndex.dbCloth: { int attr = br.ReadUInt16(); d.objs.Add(newObj = new ClothDef { itemType = (attr >> 0) & 127, important = 0 != ((attr >> 7) & 1), charges = (attr >> 10) & 15, }); break; } case dbIndex.dbScroll: { int attr = br.ReadUInt16(); d.objs.Add(newObj = new ScrollDef { referredText = attr & 0x3ff, }); break; } case dbIndex.dbPotion: { int attr = br.ReadUInt16(); d.objs.Add(newObj = new PotionDef { potionPower = (attr >> 0) & 255, potionType = (attr >> 8) & 127, visiblePower = 0 != ((attr >> 15) & 1), }); break; } case dbIndex.dbContainer: { int childOid = br.ReadUInt16(); int attr = br.ReadByte(); int attr2 = br.ReadByte(); int attr3 = br.ReadUInt16(); ContainerDef me; d.objs.Add(newObj = me = new ContainerDef { isOpened = 0 != ((attr >> 0) & 1), containerType = (attr >> 1) & 3, destX = (attr3 >> 0) & 31, destY = (attr3 >> 5) & 31, destMap = (attr >> 10) & 63, }); if (childOid != oidEnd) { me.childObjRef = convertObject(mapdef, childOid, tile); } break; } case dbIndex.dbMiscellaneous_item: { int attr = br.ReadUInt16(); d.objs.Add(newObj = new MiscItemDef { itemType = (attr >> 0) & 127, important = 0 != ((attr >> 7) & 1), charges = (attr >> 8) & 0x3f, }); break; } case dbIndex.dbMissile: { int childOid = br.ReadUInt16(); MissileDef me; d.objs.Add(newObj = me = new MissileDef { }); if (childOid != oidEnd) { me.childObjRef = convertObject(mapdef, childOid, tile); } break; } case dbIndex.dbCloud: { d.objs.Add(newObj = new CloudDef { }); break; } default: throw new NotSupportedException(); } newObj.direction = dir; if (nextOid != oidEnd) { newObj.nextObjRef = convertObject(mapdef, nextOid, tile); } return(objRef); }