void
MsnWepDlg::OnLoadout(AWEvent* event)
{
	if (!elem) return;

	ShipDesign* design   = (ShipDesign*) elem->GetDesign();
	ShipLoad*   shipload = 0;

	if (loadout_list && design) {
		int   index    = loadout_list->GetListIndex();
		Text  loadname = loadout_list->GetItemText(index);

		ListIter<ShipLoad> sl = (List<ShipLoad>&) design->loadouts;
		while (++sl) {
			if (sl->name == loadname) {
				shipload = sl.value();
			}
		}

		if (!shipload) return;

		if (lbl_weight) {
			char weight[32];
			sprintf_s(weight, "%d kg", (int) ((design->mass + shipload->mass) * 1000));
			lbl_weight->SetText(weight);
		}

		if (elem->Loadouts().size() < 1) {
			MissionLoad* l = new(__FILE__,__LINE__) MissionLoad(-1, shipload->name);
			elem->Loadouts().append(l);
		}
		else {
			ListIter<MissionLoad> l = elem->Loadouts();
			while (++l) {
				// if the player chooses a std loadout,
				// tell the sim loader to use a named
				// loadout from the ship design:
				l->SetName(shipload->name);
			}
		}

		int  nstations = design->hard_points.size();
		int* loadout   = shipload->load;

		for (int i = 0; i < 8; i++)
		loads[i] = -1;

		for (int i = 0; i < nstations; i++)
		loads[i + first_station] = PointIndexToLoad(i, loadout[i]);

		for (int i = 0; i < 8; i++) {
			for (int n = 0; n < 8; n++) {
				btn_load[i][n]->SetPicture(i == loads[n] ? led_on: led_off);
			}
		}
	}
}
void
MsnWepDlg::OnMount(AWEvent* event)
{
	int station = -1;
	int item    = -1;

	for (int i = 0; i < 8 && item < 0; i++) {
		for (int n = 0; n < 8 && station < 0; n++) {
			if (btn_load[i][n] == event->window) {
				station = n;
				item    = i;
			}
		}
	}

	if (item >= 0 && station >= 0) {
		if (loads[station] == item)
		item = -1;

		loads[station] = item;

		for (int n = 0; n < 8; n++) {
			btn_load[n][station]->SetPicture(n == item ? led_on : led_off);
		}

		if (elem) {
			int nstations = elem->GetDesign()->hard_points.size();

			if (elem->Loadouts().size() < 1) {
				MissionLoad* l = new(__FILE__,__LINE__) MissionLoad;
				elem->Loadouts().append(l);

				for (int n = 0; n < nstations; n++)
				l->SetStation(n, LoadToPointIndex(n));
			}
			else {
				ListIter<MissionLoad> l = elem->Loadouts();
				while (++l) {
					// if the player customizes the loadout,
					// tell the sim loader not to use a named
					// loadout from the ship design:
					l->SetName("");

					for (int n = 0; n < nstations; n++)
					l->SetStation(n, LoadToPointIndex(n));
				}
			}
		}
	}

	if (loadout_list)
	loadout_list->ClearSelection();

	if (lbl_weight && elem) {
		ShipDesign* d         = (ShipDesign*) elem->GetDesign();
		int         nstations = d->hard_points.size();
		double      mass      = d->mass;

		for (int n = 0; n < nstations; n++) {
			int item = loads[n+first_station];
			mass += d->hard_points[n]->GetCarryMass(item);
		}

		char weight[32];
		sprintf_s(weight, "%d kg", (int) (mass * 1000));
		lbl_weight->SetText(weight);
	}
}