示例#1
0
		void PlaceInitialUnits ()
		{
			List<UnitInfo> unit_infos = scenario.Units;

			List<Unit> startLocations = new List<Unit>();

			units = new List<Unit>();

			foreach (UnitInfo unitinfo in unit_infos) {
				if (unitinfo.unit_id == 0xffff)
					break;

				Unit unit = new Unit (unitinfo);

				/* we handle start locations in a special way, below */
				if (unit.FlingyId == 140) {
					startLocations.Add (unit);
					continue;
				}

				//players[unitinfo.player].AddUnit (unit);

				unit.CreateSprite (mpq, tileset_palette);
				units.Add (unit);
			}

			if (template != null && (template.InitialUnits != InitialUnits.UseMapSettings)) {
				foreach (Unit sl in startLocations) {
					/* terran command center = 106,
					   zerg hatchery = 131,
					   protoss nexus = 154 */

					Unit unit = new Unit (154);
					unit.X = sl.X;
					unit.Y = sl.Y;

					unit.CreateSprite (mpq, tileset_palette);
					units.Add (unit);
				}
			}

			/* for now assume the player is at startLocations[0], and center the view there */
			Recenter (startLocations[0].X, startLocations[0].Y);
		}
示例#2
0
		public override void MouseButtonDown (MouseButtonEventArgs args)
		{
			if (mouseOverElement != null) {
				base.MouseButtonDown (args);
			}
			else if (args.X > MINIMAP_X && args.X < MINIMAP_X + MINIMAP_WIDTH &&
				 args.Y > MINIMAP_Y && args.Y < MINIMAP_Y + MINIMAP_HEIGHT) {
				RecenterFromMinimap (args.X, args.Y);
				buttonDownInMinimap = true;
			}
			else {
				if (selectedUnit != unitUnderCursor) {

					Console.WriteLine ("hey there, keyboard.modifierkeystate = {0}", Keyboard.ModifierKeyState);

					// if we have a selected unit and we
					// right click (or ctrl-click?), try
					// to move there
					if (selectedUnit != null && (Keyboard.ModifierKeyState & ModifierKeys.ShiftKeys) != 0) {
						Console.WriteLine ("And... we're walking");

						int pixel_x = args.X + topleft_x;
						int pixel_y = args.Y + topleft_y;

						// calculate the megatile
						int megatile_x = pixel_x >> 5;
						int megatile_y = pixel_y >> 5;

						Console.WriteLine ("megatile {0},{1}", megatile_x, megatile_y);

						// the mini tile
						int minitile_x = pixel_x >> 2;
						int minitile_y = pixel_y >> 2;

						Console.WriteLine ("minitile {0},{1} ({2},{3} in the megatile)",
								   minitile_x, minitile_y,
								   minitile_x - megatile_x * 8,
								   minitile_y - megatile_y * 8);

						if (selectedUnit.YesSound != null) {
							string sound_resource = String.Format ("sound\\{0}", selectedUnit.YesSound);
							Console.WriteLine ("sound_resource = {0}", sound_resource);
							GuiUtil.PlaySound (mpq, sound_resource);
						}

						selectedUnit.Move (mapRenderer, minitile_x, minitile_y);

						return;
					}
					
					portraitElement.Stop ();
					
					selectedUnit = unitUnderCursor;

					if (selectedUnit == null) {
						portraitElement.Visible = false;
						wireframeElement.Visible = false;
						for (int i = 0; i < (int)HudLabels.Count; i ++)
							labelElements[i].Visible = false;
					}
					else {
						Console.WriteLine ("selected unit: {0}", selectedUnit);
						Console.WriteLine ("selectioncircle = {0}", selectedUnit.SelectionCircleOffset);

						if (selectedUnit.Portrait == null) {
							portraitElement.Visible = false;
						}
						else {
							string portrait_resource = String.Format ("portrait\\{0}0.smk",
												  selectedUnit.Portrait);

							portraitElement.Player = new SmackerPlayer ((Stream)mpq.GetResource (portrait_resource), 1);
							portraitElement.Play ();
							portraitElement.Visible = true;
						}

						if (selectedUnit.WhatSound != null) {
							string sound_resource = String.Format ("sound\\{0}", selectedUnit.WhatSound);
							Console.WriteLine ("sound_resource = {0}", sound_resource);
							GuiUtil.PlaySound (mpq, sound_resource);
						}

						/* set up the wireframe */
						wireframeElement.Frame = selectedUnit.UnitId;
						wireframeElement.Visible = true;

						/* then display info about the selected unit */
						labelElements[(int)HudLabels.UnitName].Text = statTxt[selectedUnit.UnitId];
						if (true /* XXX unit is a building */) {
							labelElements[(int)HudLabels.ResourceUsed].Text = statTxt[820+(int)Game.Instance.Race];
							labelElements[(int)HudLabels.ResourceProvided].Text = statTxt[814+(int)Game.Instance.Race];
							labelElements[(int)HudLabels.ResourceTotal].Text = statTxt[817+(int)Game.Instance.Race];
							labelElements[(int)HudLabels.ResourceMax].Text = statTxt[823+(int)Game.Instance.Race];

							for (int i = 0; i < (int)HudLabels.Count; i ++)
								labelElements[i].Visible = true;
						}

						/* then fill in the command buttons */
						int[] cmd_indices;

						switch (selectedUnit.UnitId) {
						case 106:
							cmd_indices = new int[] { 7, -1, -1, -1, -1, 286, -1, -1, 282 };
							break;
						default:
							Console.WriteLine ("cmd_indices == -1");
							cmd_indices = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
							break;
						}

						for (int i = 0; i < cmd_indices.Length; i ++) {
							if (cmd_indices[i] == -1) {
								cmdButtonElements[i].Visible = false;
							}
							else {
								cmdButtonElements[i].Visible = true;
								cmdButtonElements[i].Frame = cmd_indices[i];
							}
						}
					}
				}
			}
		}