Пример #1
0
void LocationTree::RebuildLocationTree()
{
	GuiMapPtr map = chkd.maps.curr;
	EmptySubTree(hLocationRoot);

	buffer& MRGN = map->MRGN();
	if ( MRGN.exists() )
	{
		ChkLocation* loc;
		ChkdString locName;
		for ( u32 i=0; i<MRGN.size()/CHK_LOCATION_SIZE; i++ )
		{
			// In general a location must have a string or non-zero coordinates or a specified elevation
			if ( ( i != 63 || !map->LockAnywhere() ) && map->getLocation(loc, u8(i)) &&
				 ( loc->stringNum != 0 || loc->xc1 != 0 || loc->xc2 != 0 || loc->yc1 != 0 || loc->xc2 != 0 || loc->elevation != 0 ) )
			{
				if ( map->getLocationName((u16)i, locName) )
					InsertLocationItem(locName.c_str(), i);
				else
					InsertLocationItem(std::string("Location " + std::to_string(i)).c_str(), i);
			}
		}
	}

	if ( map->getLayer() == LAYER_LOCATIONS )
		ExpandItem(hLocationRoot);

	RedrawThis();
}
Пример #2
0
void ForcesWindow::RefreshWindow()
{
	HWND hWnd = getHandle();
	GuiMapPtr map = chkd.maps.curr;
	if ( map != nullptr )
	{
		for ( int force=0; force<4; force++ )
		{
			ChkdString forceName;
			bool allied = false, vision = false, random = false, av = false;
			map->getForceString(forceName, force);
			map->getForceInfo(force, allied, vision, random, av);

			SetWindowText(GetDlgItem(hWnd, EDIT_F1NAME+force), forceName.c_str());
			if ( allied ) SendMessage(GetDlgItem(hWnd, CHECK_F1ALLIED+force), BM_SETCHECK, BST_CHECKED  , 0);
			else		  SendMessage(GetDlgItem(hWnd, CHECK_F1ALLIED+force), BM_SETCHECK, BST_UNCHECKED, 0);
			if ( vision ) SendMessage(GetDlgItem(hWnd, CHECK_F1VISION+force), BM_SETCHECK, BST_CHECKED  , 0);
			else		  SendMessage(GetDlgItem(hWnd, CHECK_F1VISION+force), BM_SETCHECK, BST_UNCHECKED, 0);
			if ( random ) SendMessage(GetDlgItem(hWnd, CHECK_F1RANDOM+force), BM_SETCHECK, BST_CHECKED  , 0);
			else		  SendMessage(GetDlgItem(hWnd, CHECK_F1RANDOM+force), BM_SETCHECK, BST_UNCHECKED, 0);
			if ( av		) SendMessage(GetDlgItem(hWnd, CHECK_F1AV	 +force), BM_SETCHECK, BST_CHECKED  , 0);
			else		  SendMessage(GetDlgItem(hWnd, CHECK_F1AV	 +force), BM_SETCHECK, BST_UNCHECKED, 0);
		}

		for ( int i=0; i<4; i++ )
		{
			HWND hListBox = GetDlgItem(hWnd, LB_F1PLAYERS+i);
			if ( hListBox != NULL )
				while ( SendMessage(hListBox, LB_DELETESTRING, 0, 0) != LB_ERR );
		}

		for ( int player=0; player<8; player++ )
		{
			u8 force(0), color(0), race(0), displayOwner(map->getDisplayOwner(player));
			if ( map->getPlayerForce(player, force) )
			{
				map->getPlayerColor(player, color);
				map->getPlayerRace(player, race);
				std::stringstream ssplayer;
				ssplayer << "Player " << player+1 << " - " << playerColors.at(color) << " - "
						 << playerRaces.at(race) << " (" << playerOwners.at(displayOwner) << ")";
				HWND hListBox = GetDlgItem(hWnd, LB_F1PLAYERS+force);
				if ( hListBox != NULL )
					SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)ssplayer.str().c_str());
			}
		}
	}
}
Пример #3
0
bool ForcesWindow::CreateThis(HWND hParent, u32 windowId)
{
	if ( getHandle() != NULL )
		return SetParent(hParent);

	if ( ClassWindow::RegisterWindowClass(0, NULL, NULL, NULL, NULL, "Forces", NULL, false) &&
		 ClassWindow::CreateClassWindow(0, "Forces", WS_VISIBLE|WS_CHILD, 4, 22, 592, 524, hParent, (HMENU)windowId) )
	{
		GuiMapPtr map = chkd.maps.curr;
		HWND hForces = getHandle();
		textAboutForces.CreateThis(hForces, 5, 10, 587, 20,
			"Designate player forces, set force names, and force properties. It is recommended to separate computer and human players", 0);

		const char* forceGroups[] = { "Force 1", "Force 2", "Force 3", "Force 4" };
		for ( int y=0; y<2; y++ )
		{
			for ( int x=0; x<2; x++ )
			{
				int force = x+y*2;
				ChkdString forceName = "";
				bool allied = false, vision = false, random = false, av = false;
				if ( map != nullptr )
				{
					map->getForceString(forceName, force);
					map->getForceInfo(force, allied, vision, random, av);
				}

				groupForce[force].CreateThis(hForces, 5+293*x, 50+239*y, 288, 234, forceGroups[force], 0);
				editForceName[force].CreateThis(hForces, 20+293*x, 70+239*y, 268, 20, false, EDIT_F1NAME+force);
				editForceName[force].SetText(forceName.c_str());
				dragForces[force].CreateThis(hForces, 20+293*x, 95+239*y, 268, 121, LB_F1PLAYERS+force);
				checkAllied[force].CreateThis(hForces, 15+293*x, 232+239*y, 100, 20, allied, "Allied", CHECK_F1ALLIED+force);
				checkSharedVision[force].CreateThis(hForces, 15+293*x, 252+239*y, 100, 20, vision, "Share Vision", CHECK_F1VISION+force);
				checkRandomizeStart[force].CreateThis(hForces, 125+293*x, 232+239*y, 150, 20, random, "Randomize Start Location", CHECK_F1RANDOM+force);
				checkAlliedVictory[force].CreateThis(hForces, 125+293*x, 252+239*y, 150, 20, av, "Enable Allied Victory", CHECK_F1AV+force);
			}
		}

		if ( WM_DRAGNOTIFY == WM_NULL )
			WM_DRAGNOTIFY = RegisterWindowMessage(DRAGLISTMSGSTRING);

		return true;
	}
	else
		return false;
}
Пример #4
0
LRESULT StringEditorWindow::Command(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	switch ( HIWORD(wParam) )
	{
	case LBN_SELCHANGE:
		if ( LOWORD(wParam) == LB_STRINGS ) // Change selection, update info boxes and so fourth
		{
			if ( currSelString != 0 )
				updateString(currSelString);

			currSelString = 0;
			listUsage.ClearItems();
			int lbIndex;
			if ( listStrings.GetCurSel(lbIndex) )
			{
				ChkdString str;
				if ( listStrings.GetItemData(lbIndex, currSelString) && chkd.maps.curr != nullptr &&
					chkd.maps.curr->GetString(str, currSelString) && str.length() > 0 )
				{
					editString.SetText(str.c_str());

					u32 locs, trigs, briefs, props, forces, wavs, units, switches;
					chkd.maps.curr->getStringUse(currSelString, locs, trigs, briefs, props, forces, wavs, units, switches);
					addUseItem("Locations", locs);
					addUseItem("Triggers", trigs);
					addUseItem("Briefing Triggers", briefs);
					addUseItem("Map Properties", props);
					addUseItem("Forces", forces);
					addUseItem("WAVs", wavs);
					addUseItem("Units", units);
					addUseItem("Switches", switches);
					chkd.mapSettingsWindow.SetTitle((std::string("Map Settings - [String #") +
						std::to_string(currSelString) + ']').c_str());
				}
				else
					chkd.mapSettingsWindow.SetTitle("Map Settings");
				return 0;
			}
			else
				chkd.mapSettingsWindow.SetTitle("Map Settings");
			editString.SetText("");
		}
		break;
	case LBN_KILLFOCUS: // String list box item may have lost focus, check if string should be updated
		if ( LOWORD(wParam) == LB_STRINGS && currSelString != 0 && updateString(currSelString) )
			chkd.maps.curr->refreshScenario();
		break;
	case EN_KILLFOCUS: // String edit box may have lost focus, check if string should be updated
		if ( LOWORD(wParam) == EDIT_STRING && currSelString != 0 && updateString(currSelString) )
			chkd.maps.curr->refreshScenario();
		break;
	case BN_CLICKED:
		if ( LOWORD(wParam) == DELETE_STRING  &&
			MessageBox(hWnd, "Forcefully deleting a string could cause problems, continue?", "Warning", MB_ICONEXCLAMATION | MB_YESNO) == IDYES &&
			chkd.maps.curr != nullptr && currSelString != 0 && chkd.maps.curr->stringExists(currSelString)
			)
		{
			chkd.maps.curr->forceDeleteString(currSelString);
			chkd.maps.curr->refreshScenario();
		}
		else if ( LOWORD(wParam) == SAVE_TO && chkd.maps.curr != nullptr )
			saveStrings();
		break;
	}
	return 0;
}
Пример #5
0
void UnitSettingsWindow::RefreshWindow()
{
    refreshing = true;
    if ( selectedUnit >= 0 && selectedUnit < 228 && CM != nullptr )
    {
        u16 unitId = (u16)selectedUnit;
        if ( isDisabled )
            EnableUnitEditing();

        bool useDefaultSettings = CM->unitUsesDefaultSettings(unitId);
        if ( useDefaultSettings )
        {
            checkUseUnitDefaults.SetCheck(true);
            DisableUnitProperties();
        }
        else
        {
            checkUseUnitDefaults.SetCheck(false);
            EnableUnitProperties();
        }

        UNITDAT* unitDat = chkd.scData.UnitDat(unitId);
        u32 hitpoints,
            groundWeapon = (u32)unitDat->GroundWeapon,
            airWeapon    = (u32)unitDat->AirWeapon;
        u16 shieldPoints, buildTime, mineralCost, gasCost, baseGroundWeapon, bonusGroundWeapon,
            baseAirWeapon, bonusAirWeapon,
            subUnitId = unitDat->Subunit1;
        u8 armor, hitpointsByte;
        
        if ( subUnitId != 228 ) // If unit has a subunit
        {
            if ( groundWeapon == 130 ) // If unit might have a subunit ground attack
                groundWeapon = chkd.scData.UnitDat(subUnitId)->GroundWeapon;
            if ( airWeapon == 130 ) // If unit might have a subunit air attack
                airWeapon = chkd.scData.UnitDat(subUnitId)->AirWeapon;
        }

        if ( groundWeapon == 130 )
        {
            groupGroundWeapon.SetText("No Ground Weapon");
            groupGroundWeapon.DisableThis();
            editGroundDamage.SetText("");
            editGroundDamage.DisableThis();
            editGroundBonus.SetText("");
            editGroundBonus.DisableThis();
            textGroundDamage.DisableThis();
            textGroundBonus.DisableThis();
        }
        else
        {
            groupGroundWeapon.SetText("Ground Weapon [" + weaponNames.at(groundWeapon) + "]");
        }

        if ( airWeapon == 130 || airWeapon == groundWeapon )
        {
            if ( airWeapon != 130 && airWeapon == groundWeapon )
            {
                groupAirWeapon.SetText("Air Weapon [" + weaponNames.at(airWeapon) + "]");
            }
            else
                groupAirWeapon.SetText("No Air Weapon");

            groupAirWeapon.DisableThis();
            editAirDamage.SetText("");
            editAirDamage.DisableThis();
            editAirBonus.SetText("");
            editAirBonus.DisableThis();
            textAirDamage.DisableThis();
            textAirBonus.DisableThis();
        }
        else
        {
            groupAirWeapon.SetText("Air Weapon [" + weaponNames.at(airWeapon) + "]");
        }

        if ( useDefaultSettings )
        {
            editHitPoints.SetEditNum<u32>(unitDat->HitPoints/256);
            editHitPointsByte.SetEditNum<u32>(0);
            editShieldPoints.SetEditNum<u16>(unitDat->ShieldAmount);
            editArmor.SetEditNum<u8>(unitDat->Armor);
            editBuildTime.SetEditNum<u16>(unitDat->BuildTime);
            editMineralCost.SetEditNum<u16>(unitDat->MineralCost);
            editGasCost.SetEditNum<u16>(unitDat->VespeneCost);
            if ( groundWeapon != 130 )
            {
                editGroundDamage.SetEditNum<u16>(chkd.scData.WeaponDat(groundWeapon)->DamageAmount);
                editGroundBonus.SetEditNum<u16>(chkd.scData.WeaponDat(groundWeapon)->DamageBonus);
            }
            if ( airWeapon != 130 && airWeapon != groundWeapon )
            {
                editAirDamage.SetEditNum<u16>(chkd.scData.WeaponDat(airWeapon)->DamageAmount);
                editAirBonus.SetEditNum<u16>(chkd.scData.WeaponDat(airWeapon)->DamageBonus);
            }
        }
        else // Not default settings
        {
            if ( CM->getUnitSettingsHitpoints(unitId, hitpoints) )
                editHitPoints.SetEditNum<u32>(hitpoints);
            if ( CM->getUnitSettingsHitpointByte(unitId, hitpointsByte) )
                editHitPointsByte.SetEditNum<u8>(hitpointsByte);
            if ( CM->getUnitSettingsShieldPoints(unitId, shieldPoints) )
                editShieldPoints.SetEditNum<u16>(shieldPoints);
            if ( CM->getUnitSettingsArmor(unitId, armor) )
                editArmor.SetEditNum<u8>(armor);
            if ( CM->getUnitSettingsBuildTime(unitId, buildTime) )
                editBuildTime.SetEditNum<u16>(buildTime);
            if ( CM->getUnitSettingsMineralCost(unitId, mineralCost) )
                editMineralCost.SetEditNum<u16>(mineralCost);
            if ( CM->getUnitSettingsGasCost(unitId, gasCost) )
                editGasCost.SetEditNum<u16>(gasCost);
            if ( CM->getUnitSettingsBaseWeapon(groundWeapon, baseGroundWeapon) )
                editGroundDamage.SetEditNum<u16>(baseGroundWeapon);
            if ( CM->getUnitSettingsBonusWeapon(groundWeapon, bonusGroundWeapon) )
                editGroundBonus.SetEditNum<u16>(bonusGroundWeapon);
            if ( airWeapon != groundWeapon && CM->getUnitSettingsBaseWeapon(airWeapon, baseAirWeapon) )
                editAirDamage.SetEditNum<u16>(baseAirWeapon);
            if ( airWeapon != groundWeapon && CM->getUnitSettingsBonusWeapon(airWeapon, bonusAirWeapon) )
                editAirBonus.SetEditNum<u16>(bonusAirWeapon);
        }

        checkEnabledByDefault.SetCheck(CM->unitIsEnabled(unitId));

        for ( int i=0; i<12; i++ )
        {
            UnitEnabledState enabledState = CM->getUnitEnabledState(unitId, (u8)i);
            if ( enabledState == UnitEnabledState::Default )
                dropPlayerAvailability[i].SetSel(0);
            else if ( enabledState == UnitEnabledState::Enabled )
                dropPlayerAvailability[i].SetSel(1);
            else if ( enabledState == UnitEnabledState::Disabled )
                dropPlayerAvailability[i].SetSel(2);
        }

        u16 unitStringNum = 0;
        if ( CM->getUnitStringNum(unitId, unitStringNum) && unitStringNum == 0 )
        {
            editUnitName.DisableThis();
            checkUseDefaultName.SetCheck(true);
        }
        else
        {
            if ( !useDefaultSettings )
                editUnitName.EnableThis();
            checkUseDefaultName.SetCheck(false);
        }
            
        ChkdString unitName;
        CM->getUnitName(unitName, unitId);
        editUnitName.SetText(unitName.c_str());
        chkd.mapSettingsWindow.SetWinText((std::string("Map Settings - [") + DefaultUnitDisplayName[unitId] + ']').c_str());
    }
    else
        DisableUnitEditing();

    refreshing = false;
}
Пример #6
0
LRESULT UnitSettingsWindow::Command(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
    if ( refreshing )
        return ClassWindow::Command(hWnd, wParam, lParam);

    switch ( LOWORD(wParam) )
    {
    case BUTTON_RESETALLUNITDEFAULTS:
        if ( HIWORD(wParam) == BN_CLICKED )
        {
            if ( MessageBox(hWnd, "Are you sure you want to reset all unit settings?", "Confirm", MB_YESNO) == IDYES )
            {
                buffer newUNIS((u32)SectionId::UNIS), newUNIx((u32)SectionId::UNIx), newPUNI((u32)SectionId::PUNI);
                if ( Get_UNIS(newUNIS) )
                {
                    newUNIS.del(0, 8);
                    CM->ReplaceUNISSection(newUNIS);
                }
                if ( Get_UNIx(newUNIx) )
                {
                    newUNIx.del(0, 8);
                    CM->ReplaceUNIxSection(newUNIx);
                }
                if ( Get_PUNI(newPUNI) )
                {
                    newPUNI.del(0, 8);
                    CM->ReplacePUNISection(newPUNI);
                }

                CM->cleanStringTable(false);
                CM->cleanStringTable(true);
                DisableUnitEditing();
                RefreshWindow();
                CM->notifyChange(false);
            }
        }
        break;

    case CHECK_USEUNITDEFAULTS:
        if ( HIWORD(wParam) == BN_CLICKED )
        {
            LRESULT state = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
            if ( selectedUnit != -1 )
            {
                if ( state == BST_CHECKED )
                {
                    ClearDefaultUnitProperties();
                    DisableUnitProperties();
                    CM->setUnitUseDefaults((u8)selectedUnit, true);
                }
                else
                {
                    SetDefaultUnitProperties();
                    EnableUnitProperties();
                    CM->setUnitUseDefaults((u8)selectedUnit, false);
                }

                RefreshWindow();
                chkd.unitWindow.RepopulateList();
                RedrawWindow(chkd.unitWindow.getHandle(), NULL, NULL, RDW_INVALIDATE);
                CM->notifyChange(false);
            }
        }
        break;
    case CHECK_USEDEFAULTUNITNAME:
        if ( HIWORD(wParam) == BN_CLICKED )
        {
            LRESULT state = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
            if ( selectedUnit != -1 )
            {
                if ( state == BST_CHECKED )
                {
                    editUnitName.DisableThis();
                    CM->setUnisStringId(selectedUnit, 0);
                    CM->setUnixStringId(selectedUnit, 0);
                    ChkdString unitName;
                    CM->getUnitName(unitName, (u16)selectedUnit);
                    editUnitName.SetText(unitName.c_str());
                    chkd.unitWindow.RepopulateList();
                    RedrawWindow(chkd.unitWindow.getHandle(), NULL, NULL, RDW_INVALIDATE);
                }
                else
                    editUnitName.EnableThis();

                CM->notifyChange(false);
            }
        }
        break;
    case CHECK_ENABLEDBYDEFAULT:
        if ( HIWORD(wParam) == BN_CLICKED )
        {
            LRESULT state = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
            if ( selectedUnit != -1 )
            {
                CM->setUnitEnabled((u16)selectedUnit, state == BST_CHECKED);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITNAME:
        if ( HIWORD(wParam) == EN_CHANGE )
            possibleUnitNameUpdate = true;
        else if ( HIWORD(wParam) == EN_KILLFOCUS )
            CheckReplaceUnitName();
        break;
    case EDIT_UNITHITPOINTS:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u32 newHitPoints;
            if ( editHitPoints.GetEditNum<u32>(newHitPoints) )
            {
                CM->setUnitSettingsHitpoints((u16)selectedUnit, newHitPoints);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITHITPOINTSBYTE:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u8 newHitPointByte;
            if ( editHitPointsByte.GetEditNum<u8>(newHitPointByte) )
            {
                CM->setUnitSettingsHitpointByte((u16)selectedUnit, newHitPointByte);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITSHIELDPOINTS:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newShieldPoints;
            if ( editShieldPoints.GetEditNum<u16>(newShieldPoints) )
            {
                CM->setUnitSettingsShieldPoints((u16)selectedUnit, newShieldPoints);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITARMOR:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u8 newArmorByte;
            if ( editArmor.GetEditNum<u8>(newArmorByte) )
            {
                CM->setUnitSettingsArmor((u16)selectedUnit, newArmorByte);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITBUILDTIME:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newBuildTime;
            if ( editBuildTime.GetEditNum<u16>(newBuildTime) )
            {
                CM->setUnitSettingsBuildTime((u16)selectedUnit, newBuildTime);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITMINERALCOST:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newMineralCost;
            if ( editMineralCost.GetEditNum<u16>(newMineralCost) )
            {
                CM->setUnitSettingsMineralCost((u16)selectedUnit, newMineralCost);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITGASCOST:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newGasCost;
            if ( editGasCost.GetEditNum<u16>(newGasCost) )
            {
                CM->setUnitSettingsGasCost((u16)selectedUnit, newGasCost);
                CM->notifyChange(false);
            }
        }
        break;
    case EDIT_UNITGROUNDDAMAGE:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newGroundDamage;
            if ( editGroundDamage.GetEditNum<u16>(newGroundDamage) )
            {
                u32 groundWeapon = (u32)chkd.scData.UnitDat((u16)selectedUnit)->GroundWeapon;
                u16 subUnitId = chkd.scData.UnitDat((u16)selectedUnit)->Subunit1;

                if ( subUnitId != 228 && groundWeapon == 130 ) // If unit has a subunit
                    groundWeapon = chkd.scData.UnitDat(subUnitId)->GroundWeapon; // If unit might have a subunit ground attack
                if ( groundWeapon < 130 )
                {
                    CM->setUnitSettingsBaseWeapon(groundWeapon, newGroundDamage);
                    CM->notifyChange(false);
                }
            }
        }
        break;
    case EDIT_UNITGROUNDBONUS:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newGroundBonus;
            if ( editGroundBonus.GetEditNum<u16>(newGroundBonus) )
            {
                u32 groundWeapon = (u32)chkd.scData.UnitDat((u16)selectedUnit)->GroundWeapon;
                u16 subUnitId = chkd.scData.UnitDat((u16)selectedUnit)->Subunit1;

                if ( subUnitId != 228 && groundWeapon == 130 ) // If unit has a subunit
                    groundWeapon = chkd.scData.UnitDat(subUnitId)->GroundWeapon; // If unit might have a subunit ground attack
                if ( groundWeapon < 130 )
                {
                    CM->setUnitSettingsBonusWeapon(groundWeapon, newGroundBonus);
                    CM->notifyChange(false);
                }
            }
        }
        break;
    case EDIT_UNITAIRDAMAGE:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newAirDamage;
            if ( editAirDamage.GetEditNum<u16>(newAirDamage) )
            {
                u32 airWeapon = (u32)chkd.scData.UnitDat((u16)selectedUnit)->AirWeapon;
                u16 subUnitId = chkd.scData.UnitDat((u16)selectedUnit)->Subunit1;

                if ( subUnitId != 228 && airWeapon == 130 ) // If unit has a subunit
                    airWeapon = chkd.scData.UnitDat(subUnitId)->AirWeapon; // If unit might have a subunit ground attack
                if ( airWeapon < 130 )
                {
                    CM->setUnitSettingsBaseWeapon(airWeapon, newAirDamage);
                    CM->notifyChange(false);
                }
            }
        }
        break;
    case EDIT_UNITAIRBONUS:
        if ( HIWORD(wParam) == EN_CHANGE )
        {
            u16 newAirBonus;
            if ( editAirBonus.GetEditNum<u16>(newAirBonus) )
            {
                u32 airWeapon = (u32)chkd.scData.UnitDat((u16)selectedUnit)->AirWeapon;
                u16 subUnitId = chkd.scData.UnitDat((u16)selectedUnit)->Subunit1;

                if ( subUnitId != 228 && airWeapon == 130 ) // If unit has a subunit
                    airWeapon = chkd.scData.UnitDat(subUnitId)->AirWeapon; // If unit might have a subunit ground attack

                CM->setUnitSettingsBonusWeapon(airWeapon, newAirBonus);
                CM->notifyChange(false);
            }
        }
        break;
    default:
        if ( LOWORD(wParam) >= DROP_P1UNITAVAILABILITY && LOWORD(wParam) <= DROP_P12UNITAVAILABILITY &&
            HIWORD(wParam) == CBN_SELCHANGE )
        {
            u32 player = LOWORD(wParam) - DROP_P1UNITAVAILABILITY;
            int sel = dropPlayerAvailability[player].GetSel();
            if ( CM->setUnitEnabledState((u16)selectedUnit, (u8)player, (UnitEnabledState)dropPlayerAvailability[player].GetSel()) )
                CM->notifyChange(false);
            else
                RefreshWindow();
        }
        break;
    }
    return ClassWindow::Command(hWnd, wParam, lParam);
}
Пример #7
0
void UnitSettingsWindow::SetDefaultUnitProperties()
{
    refreshing = true;
    if ( selectedUnit >= 0 )
    {
        u16 unitId = (u16)selectedUnit;

        // Remove Custom Unit Name
        u16 origName = 0, expName = 0;
        CM->getUnisStringId(selectedUnit, origName);
        CM->getUnixStringId(selectedUnit, expName);
        CM->setUnisStringId(selectedUnit, 0);
        CM->setUnixStringId(selectedUnit, 0);
        ChkdString unitName;
        CM->getUnitName(unitName, (u16)selectedUnit);
        editUnitName.SetText(unitName.c_str());
        checkUseDefaultName.DisableThis();
        editUnitName.DisableThis();
        CM->removeUnusedString(origName);
        CM->removeUnusedString(expName);
        chkd.unitWindow.RepopulateList();
        RedrawWindow(chkd.unitWindow.getHandle(), NULL, NULL, RDW_INVALIDATE);

        u32 groundWeapon = (u32)chkd.scData.UnitDat(unitId)->GroundWeapon,
            airWeapon    = (u32)chkd.scData.UnitDat(unitId)->AirWeapon;

        u16 subUnitId = chkd.scData.UnitDat(unitId)->Subunit1;
        if ( subUnitId != 228 ) // If unit has a subunit
        {
            if ( groundWeapon == 130 ) // If unit might have a subunit ground attack
                groundWeapon = chkd.scData.UnitDat(subUnitId)->GroundWeapon;
            if ( airWeapon == 130 ) // If unit might have a subunit air attack
                airWeapon = chkd.scData.UnitDat(subUnitId)->AirWeapon;
        }
        
        CM->setUnitSettingsCompleteHitpoints(unitId, chkd.scData.UnitDat(unitId)->HitPoints);
        CM->setUnitSettingsShieldPoints(unitId, chkd.scData.UnitDat(unitId)->ShieldAmount);
        CM->setUnitSettingsArmor(unitId, chkd.scData.UnitDat(unitId)->Armor);
        CM->setUnitSettingsBuildTime(unitId, chkd.scData.UnitDat(unitId)->BuildTime);
        CM->setUnitSettingsMineralCost(unitId, chkd.scData.UnitDat(unitId)->MineralCost);
        CM->setUnitSettingsGasCost(unitId, chkd.scData.UnitDat(unitId)->VespeneCost);

        if ( groundWeapon != 130 )
        {
            u16 defaultBaseDamage = chkd.scData.WeaponDat(groundWeapon)->DamageAmount,
                defaultBonusDamage = chkd.scData.WeaponDat(groundWeapon)->DamageBonus;

            CM->setUnitSettingsBaseWeapon(groundWeapon, defaultBaseDamage);
            CM->setUnitSettingsBonusWeapon(groundWeapon, defaultBonusDamage);
        }

        if ( airWeapon != 130 )
        {
            u16 defaultBaseDamage = chkd.scData.WeaponDat(airWeapon)->DamageAmount,
                defaultBonusDamage = chkd.scData.WeaponDat(airWeapon)->DamageBonus;

            CM->setUnitSettingsBaseWeapon(airWeapon, defaultBaseDamage);
            CM->setUnitSettingsBonusWeapon(airWeapon, defaultBonusDamage);
        }

        CM->notifyChange(false);
    }
    refreshing = false;
}