Пример #1
0
		public static Sprite CreateSprite (int sprite_number, byte[] palette, int x, int y)
		{
			Sprite sprite = new Sprite (our_mpq, sprite_number, palette, x, y);

			AddSprite (sprite);

			return sprite;
		}
Пример #2
0
		public static Sprite CreateSprite (Sprite parentSprite, ushort images_number, byte[] palette)
		{
			Sprite sprite = new Sprite (parentSprite, images_number, palette);

			AddSprite (sprite);

			return sprite;
		}
Пример #3
0
		public bool Tick (int millis_elapsed)
		{
			ushort warg1;
			ushort warg2;
			ushort warg3;
			byte barg1;
			byte barg2;
			//			byte barg3;

			if (pc == 0)
				return true;

			if (waiting > 0) {
				waiting--;
				return true;
			}
			
			Trace ("{0}: ", pc);
			switch ((IScriptOpcode)buf[pc++]) {
			case IScriptOpcode.playfram:
				warg1 = ReadWord (ref pc);
				TraceLine ("playfram: {0}", warg1);
				DoPlayFrame (warg1 + facing % 16);
				break;
			case IScriptOpcode.playframtile:
				warg1 = ReadWord (ref pc);
				TraceLine ("playframetile: {0}", warg1);
				break;
			case IScriptOpcode.sethorpos:
				barg1 = ReadByte (ref pc);
				TraceLine ("sethorpos: {0}", barg1);
				break;
			case IScriptOpcode.setpos:
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("setpos: {0} {1}", barg1, barg2);
				break;
			case IScriptOpcode.setvertpos:
				barg1 = ReadByte (ref pc);
				TraceLine ("setvertpos: {0}", barg1);
				break;
			case IScriptOpcode.wait:
				barg1 = ReadByte (ref pc);
				TraceLine ("wait: {0}", barg1);
				waiting = barg1;
				break;
			case IScriptOpcode.waitrand:
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("waitrand: {0} {1}", barg1, barg2);
				waiting = rng.Next(255) > 127 ? barg1 : barg2;
				break;
			case IScriptOpcode._goto:
				warg1 = ReadWord (ref pc);
				TraceLine ("goto: {0}", warg1);
				pc = warg1;
				break;
			case IScriptOpcode.imgol:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("imgol: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.imgul:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("imgul: {0} {1} {2}", warg1, barg1, barg2);
				Sprite dependent_sprite = SpriteManager.CreateSprite (this, warg1, palette);
				dependent_sprite.RunScript (AnimationType.Init);
				break;
			case IScriptOpcode.imgolorig:
				warg1 = ReadWord (ref pc);
				TraceLine ("imgolorig: {0}", warg1);
				break;
			case IScriptOpcode.switchul:
				warg1 = ReadWord (ref pc);
				TraceLine ("switchul: {0}", warg1);
				break;
			// __0c unknown
			case IScriptOpcode.imgoluselo:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("imgoluselo: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.imguluselo:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("imguluselo: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.sprol:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("sprol: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.highsprol:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("highsprol: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.lowsprul:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("lowsprul: {0} ({1},{2})", warg1, barg1, barg2);
 				Sprite s = SpriteManager.CreateSprite (warg1, palette, x, y);
 				s.RunScript (AnimationType.Init);
				dependentSprite = s;
				break;

				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("lowsprul: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.uflunstable:
				warg1 = ReadWord (ref pc);
				TraceLine ("uflunstable: {0}", warg1);
				break;
			case IScriptOpcode.spruluselo:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("spruluselo: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.sprul:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("sprul: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.sproluselo:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("sproleuselo: {0} {1} {2}", warg1, barg1, barg2);
				break;
			case IScriptOpcode.end:
				TraceLine ("end");
				return false;
			case IScriptOpcode.setflipstate:
				barg1 = ReadByte (ref pc);
				TraceLine ("setflipstate: {0}", barg1);
				break;
			case IScriptOpcode.playsnd:
				warg1 = ReadWord (ref pc);
				TraceLine ("playsnd: {0} ({1})", warg1 - 1, GlobalResources.Instance.SfxDataTbl[(int)GlobalResources.Instance.SfxDataDat.FileIndexes [warg1 - 1]]);
				break;
			case IScriptOpcode.playsndrand: {
				barg1 = ReadByte (ref pc);
				ushort[] wargs = new ushort[barg1];
				for (byte b = 0; b < barg1; b ++) {
					wargs[b] = ReadWord (ref pc);
				}
				Trace ("playsndrand: {0} (");
				for (int i = 0; i < wargs.Length; i ++) {
					Trace ("{0}", wargs[i]);
					if (i < wargs.Length - 1)
						Trace (", ");
				}
				TraceLine (")");
				break;
			}
			case IScriptOpcode.playsndbtwn:
				warg1 = ReadWord (ref pc);
				warg2 = ReadWord (ref pc);
				TraceLine ("playsndbtwn: {0} {1}", warg1, warg2);
				break;
			case IScriptOpcode.domissiledmg:
				TraceLine ("domissiledmg: unknown args");
				break;
			case IScriptOpcode.attackmelee: {
				barg1 = ReadByte (ref pc);
				ushort[] wargs = new ushort[barg1];
				for (byte b = 0; b < barg1; b ++) {
					wargs[b] = ReadWord (ref pc);
				}
				Trace ("attackmelee: {0} (");
				for (int i = 0; i < wargs.Length; i ++) {
					Trace ("{0}", wargs[i]);
					if (i < wargs.Length - 1)
						Trace (", ");
				}
				TraceLine (")");
				break;
			}
			case IScriptOpcode.followmaingraphic:
				TraceLine ("followmaingraphic:");
				if (parent_sprite != null)
					DoPlayFrame (parent_sprite.CurrentFrame);
				break;
			case IScriptOpcode.randcondjmp:
				barg1 = ReadByte (ref pc);
				warg1 = ReadWord (ref pc);
				TraceLine ("randcondjmp: {0} {1}", barg1, warg1);
				int rand = rng.Next(255);
				if (rand > barg1) {
					TraceLine ("+ choosing goto branch");
					pc = warg1;
				}
				break;
			case IScriptOpcode.turnccwise:
				barg1 = ReadByte (ref pc);
				TraceLine ("turnccwise: {0}", barg1);
				if (facing - barg1 < 0)
					facing = 15 - barg1;
				else
					facing -= barg1;
				break;
			case IScriptOpcode.turncwise:
				barg1 = ReadByte (ref pc);
				TraceLine ("turncwise: {0}", barg1);
				if (facing + barg1 > 15)
					facing = facing + barg1 - 15;
				else
					facing += barg1;
				break;
			case IScriptOpcode.turnlcwise:
				TraceLine ("turnlcwise: unknown args");
				break;
			case IScriptOpcode.turnrand:
				TraceLine ("turnrand:");
				if (rng.Next(255) > 127)
					goto case IScriptOpcode.turnccwise;
				else
					goto case IScriptOpcode.turncwise;
				break;
			case IScriptOpcode.setspawnframe:
				barg1 = ReadByte (ref pc);
				TraceLine ("setspawnframe {0}", barg1);
				break;
			case IScriptOpcode.sigorder:
				barg1 = ReadByte (ref pc);
				TraceLine ("sigorder {0}", barg1);
				break;
			case IScriptOpcode.attackwith:
				barg1 = ReadByte (ref pc);
				TraceLine ("attackwith {0}", barg1);
				break;
			case IScriptOpcode.attack:
				TraceLine ("attack:");
				break;
			case IScriptOpcode.castspell:
				TraceLine ("castspell:");
				break;
			case IScriptOpcode.useweapon:
				barg1 = ReadByte (ref pc);
				TraceLine ("useweapon: {0}", barg1);
				break;
			case IScriptOpcode.move:
				barg1 = ReadByte (ref pc);
				TraceLine ("move: {0}", barg1);
				break;
			case IScriptOpcode.gotorepeatattk:
				TraceLine ("gotorepeatattk");
				break;
			case IScriptOpcode.engframe:
				warg1 = ReadWord (ref pc);
				TraceLine ("engframe: {0}", warg1);
				break;
			case IScriptOpcode.engset:
				warg1 = ReadWord (ref pc);
				TraceLine ("engset: {0}", warg1);
				break;
			// __2d unknown
			case IScriptOpcode.nobrkcodestart:
				TraceLine ("nobrkcodestart:");
				break;
			case IScriptOpcode.nobrkcodeend:
				TraceLine ("nobrkcodeend:");
				break;
			case IScriptOpcode.ignorerest:
				TraceLine ("ignorerest");
				break;
			case IScriptOpcode.attkshiftproj:
				barg1 = ReadByte (ref pc);
				TraceLine ("attkshiftproj: {0}", barg1);
				break;
			case IScriptOpcode.tmprmgraphicstart:
				TraceLine ("tmprmgraphicstart:");
				break;
			case IScriptOpcode.tmprmgraphicend:
				TraceLine ("tmprmgraphicend:");
				break;
			case IScriptOpcode.setfldirect:
				barg1 = ReadByte (ref pc);
				TraceLine ("setfldirect: {0}", barg1);
				DoPlayFrame (barg1);
				break;
			case IScriptOpcode.call:
				warg1 = ReadWord (ref pc);
				TraceLine ("call: {0}", warg1);
				break;
			case IScriptOpcode._return:
				TraceLine ("return:");
				break;
			case IScriptOpcode.setflspeed:
				barg1 = ReadByte (ref pc);
				TraceLine ("setflspeed: {0}", barg1);
				break;
			case IScriptOpcode.creategasoverlays:
				barg1 = ReadByte (ref pc);
				TraceLine ("creategasoverlays: {0}", barg1);
				break;
			case IScriptOpcode.pwrupcondjmp:
				warg1 = ReadWord (ref pc);
				TraceLine ("pwrupcondjmp: {0}", warg1);
				break;
			case IScriptOpcode.trgtrangecondjmp:
				warg1 = ReadWord (ref pc);
				warg2 = ReadWord (ref pc);
				TraceLine ("trgtrangecondjmp {0} {1}", warg1, warg2);
				break;
			case IScriptOpcode.trgtarccondjmp:
				warg1 = ReadWord (ref pc);
				warg2 = ReadWord (ref pc);
				warg3 = ReadWord (ref pc);
				TraceLine ("trgtarccondjmp {0} {1} {2}", warg1, warg2, warg3);
				break;
			case IScriptOpcode.curdirectcondjmp:
				warg1 = ReadWord (ref pc);
				warg2 = ReadWord (ref pc);
				warg3 = ReadWord (ref pc);
				TraceLine ("curdirectcondjmp {0} {1} {2}", warg1, warg2, warg3);
				break;
			case IScriptOpcode.imgulnextid:
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("imgulnextid {0} {1}", barg1, barg2);
				break;
			// __3e unknown
			case IScriptOpcode.liftoffcondjmp:
				warg1 = ReadWord (ref pc);
				TraceLine ("liftoffcondjmp {0}", warg1);
				break;
			case IScriptOpcode.warpoverlay:
				warg1 = ReadWord (ref pc);
				TraceLine ("warpoverlay {0}", warg1);
				break;
			case IScriptOpcode.orderdone:
				barg1 = ReadByte (ref pc);
				TraceLine ("orderdone {0}", barg1);
				break;
			case IScriptOpcode.grdsprol:
				warg1 = ReadWord (ref pc);
				barg1 = ReadByte (ref pc);
				barg2 = ReadByte (ref pc);
				TraceLine ("grdsprol {0} {1} {2}", warg1, barg1, barg2);
				break;
			// __43 unknown
			case IScriptOpcode.dogrddamage:
				TraceLine ("dogrddamage");
				break;
			default:
				Console.WriteLine ("Unknown iscript opcode: 0x{0:x}", buf[pc-1]);
				break;
			}

			return true;
		}
Пример #4
0
		public Sprite (Sprite parentSprite, ushort images_entry, byte[] palette)
		{
			this.parent_sprite = parentSprite;
			this.mpq = parentSprite.mpq;
			this.palette = palette;
			this.images_entry = images_entry;

			uint grp_index = GlobalResources.Instance.ImagesDat.GrpIndexes [images_entry];

			grp_path = GlobalResources.Instance.ImagesTbl[(int)grp_index-1];

			grp = (Grp)mpq.GetResource ("unit\\" + grp_path);

			this.buf = GlobalResources.Instance.IScriptBin.Contents;
			iscript_entry = GlobalResources.Instance.ImagesDat.IScriptIndexes [images_entry];

			script_entry_offset = GlobalResources.Instance.IScriptBin.GetScriptEntryOffset (iscript_entry);

			Console.WriteLine ("new dependent sprite: unit\\{0} (image {1}, iscript id {2}, script_entry_offset {3:X})",
					   grp_path, images_entry, iscript_entry, script_entry_offset);

			/* make sure the offset points to "SCEP" */
			if (Util.ReadDWord (buf, script_entry_offset) != 0x45504353)
				Console.WriteLine ("invalid script_entry_offset");

			int x, y;
			parentSprite.GetPosition (out x, out y);
			SetPosition (x,y);
		}
Пример #5
0
		public static void RemoveSprite (Sprite sprite)
		{
			sprite.RemoveFromPainter ();

			sprites.Remove (sprite);
		}
Пример #6
0
		public static void AddSprite (Sprite sprite)
		{
			sprites.Add (sprite);
			sprite.AddToPainter ();
		}
Пример #7
0
		public Sprite CreateSprite (Mpq mpq, byte[] palette)
		{
			if (sprite != null)
				throw new Exception ();

			sprite = SpriteManager.CreateSprite (mpq, SpriteId, palette, x, y);

			sprite.RunScript (AnimationType.Init);

			return sprite;
		}