mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Allow toggling quick combat spells usage
This commit is contained in:
		| @@ -93,6 +93,12 @@ void CBattleAI::initBattleInterface(std::shared_ptr<Environment> ENV, std::share | ||||
| 	movesSkippedByDefense = 0; | ||||
| } | ||||
|  | ||||
| void CBattleAI::initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB, AutocombatPreferences autocombatPreferences) | ||||
| { | ||||
| 	initBattleInterface(ENV, CB); | ||||
| 	autobattlePreferences = autocombatPreferences; | ||||
| } | ||||
|  | ||||
| BattleAction CBattleAI::useHealingTent(const CStack *stack) | ||||
| { | ||||
| 	auto healingTargets = cb->battleGetStacks(CBattleInfoEssentials::ONLY_MINE); | ||||
| @@ -283,7 +289,8 @@ void CBattleAI::activeStack( const CStack * stack ) | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		attemptCastingSpell(); | ||||
| 		if(autobattlePreferences.enableSpellsUsage) | ||||
| 			attemptCastingSpell(); | ||||
|  | ||||
| 		logAi->trace("Spellcast attempt completed in %lld", timeElapsed(start)); | ||||
|  | ||||
|   | ||||
| @@ -68,6 +68,7 @@ public: | ||||
| 	~CBattleAI(); | ||||
|  | ||||
| 	void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB) override; | ||||
| 	void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB, AutocombatPreferences autocombatPreferences) override; | ||||
| 	void attemptCastingSpell(); | ||||
|  | ||||
| 	void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only | ||||
| @@ -102,4 +103,5 @@ public: | ||||
| private: | ||||
| 	BattleAction goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes) const; | ||||
| 	std::vector<BattleHex> getBrokenWallMoatHexes() const; | ||||
| 	AutocombatPreferences autobattlePreferences = AutocombatPreferences(); | ||||
| }; | ||||
|   | ||||
| @@ -662,7 +662,11 @@ void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet | ||||
| 	if ((replayAllowed && useQuickCombat) || forceQuickCombat) | ||||
| 	{ | ||||
| 		autofightingAI = CDynLibHandler::getNewBattleAI(settings["server"]["friendlyAI"].String()); | ||||
| 		autofightingAI->initBattleInterface(env, cb); | ||||
|  | ||||
| 		AutocombatPreferences autocombatPreferences = AutocombatPreferences(); | ||||
| 		autocombatPreferences.enableSpellsUsage = settings["battle"]["enableAutocombatSpells"].Bool(); | ||||
|  | ||||
| 		autofightingAI->initBattleInterface(env, cb, autocombatPreferences); | ||||
| 		autofightingAI->battleStart(army1, army2, tile, hero1, hero2, side, false); | ||||
| 		isAutoFightOn = true; | ||||
| 		cb->registerBattleInterface(autofightingAI); | ||||
|   | ||||
| @@ -500,7 +500,11 @@ void BattleWindow::bAutofightf() | ||||
| 		blockUI(true); | ||||
|  | ||||
| 		auto ai = CDynLibHandler::getNewBattleAI(settings["server"]["friendlyAI"].String()); | ||||
| 		ai->initBattleInterface(owner.curInt->env, owner.curInt->cb); | ||||
|  | ||||
| 		AutocombatPreferences autocombatPreferences = AutocombatPreferences(); | ||||
| 		autocombatPreferences.enableSpellsUsage = settings["battle"]["enableAutocombatSpells"].Bool(); | ||||
|  | ||||
| 		ai->initBattleInterface(owner.curInt->env, owner.curInt->cb, autocombatPreferences); | ||||
| 		ai->battleStart(owner.army1, owner.army2, int3(0,0,0), owner.attackingHeroInstance, owner.defendingHeroInstance, owner.curInt->cb->battleGetMySide(), false); | ||||
| 		owner.curInt->autofightingAI = ai; | ||||
| 		owner.curInt->cb->registerBattleInterface(ai); | ||||
|   | ||||
| @@ -64,6 +64,10 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) | ||||
| 	{ | ||||
| 		showStickyHeroWindowsChangedCallback(value, owner); | ||||
| 	}); | ||||
| 	addCallback("enableAutocombatSpellsChanged", [this](bool value) | ||||
| 	{ | ||||
| 		enableAutocombatSpellsChangedCallback(value); | ||||
| 	}); | ||||
| 	build(config); | ||||
|  | ||||
| 	std::shared_ptr<CToggleGroup> animationSpeedToggle = widget<CToggleGroup>("animationSpeedPicker"); | ||||
| @@ -92,6 +96,9 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner) | ||||
|  | ||||
| 	std::shared_ptr<CToggleButton> skipBattleIntroMusicCheckbox = widget<CToggleButton>("skipBattleIntroMusicCheckbox"); | ||||
| 	skipBattleIntroMusicCheckbox->setSelected(settings["gameTweaks"]["skipBattleIntroMusic"].Bool()); | ||||
|  | ||||
| 	std::shared_ptr<CToggleButton> enableAutocombatSpellsCheckbox = widget<CToggleButton>("enableAutocombatSpellsCheckbox"); | ||||
| 	enableAutocombatSpellsCheckbox->setSelected(settings["battle"]["enableAutocombatSpells"].Bool()); | ||||
| } | ||||
|  | ||||
| int BattleOptionsTab::getAnimSpeed() const | ||||
| @@ -235,3 +242,9 @@ void BattleOptionsTab::skipBattleIntroMusicChangedCallback(bool value) | ||||
| 	musicSkipSettingValue->Bool() = value; | ||||
| } | ||||
|  | ||||
| void BattleOptionsTab::enableAutocombatSpellsChangedCallback(bool value) | ||||
| { | ||||
| 	Settings enableAutocombatSpells = settings.write["battle"]["enableAutocombatSpells"]; | ||||
| 	enableAutocombatSpells->Bool() = value; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -32,6 +32,7 @@ private: | ||||
| 	void queueSizeChangedCallback(int value, BattleInterface * parentBattleInterface); | ||||
| 	void skipBattleIntroMusicChangedCallback(bool value); | ||||
| 	void showStickyHeroWindowsChangedCallback(bool value, BattleInterface * parentBattleInterface); | ||||
| 	void enableAutocombatSpellsChangedCallback(bool value); | ||||
| public: | ||||
| 	BattleOptionsTab(BattleInterface * owner = nullptr); | ||||
| }; | ||||
|   | ||||
| @@ -7,6 +7,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) | ||||
| 		${MAIN_LIB_DIR}/StdInc.cpp | ||||
|  | ||||
| 		${MAIN_LIB_DIR}/battle/AccessibilityInfo.cpp | ||||
| 		${MAIN_LIB_DIR}/battle/AutocombatPreferences.cpp | ||||
| 		${MAIN_LIB_DIR}/battle/BattleAction.cpp | ||||
| 		${MAIN_LIB_DIR}/battle/BattleAttackInfo.cpp | ||||
| 		${MAIN_LIB_DIR}/battle/BattleHex.cpp | ||||
| @@ -322,6 +323,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) | ||||
| 		${MAIN_LIB_DIR}/../include/vcmi/Team.h | ||||
|  | ||||
| 		${MAIN_LIB_DIR}/battle/AccessibilityInfo.h | ||||
| 		${MAIN_LIB_DIR}/battle/AutocombatPreferences.h | ||||
| 		${MAIN_LIB_DIR}/battle/BattleAction.h | ||||
| 		${MAIN_LIB_DIR}/battle/BattleAttackInfo.h | ||||
| 		${MAIN_LIB_DIR}/battle/BattleHex.h | ||||
|   | ||||
| @@ -272,7 +272,7 @@ | ||||
| 			"type" : "object", | ||||
| 			"additionalProperties" : false, | ||||
| 			"default" : {}, | ||||
| 			"required" : [ "speedFactor", "mouseShadow", "cellBorders", "stackRange", "movementHighlightOnHover", "rangeLimitHighlightOnHover", "showQueue", "swipeAttackDistance", "queueSize", "stickyHeroInfoWindows" ], | ||||
| 			"required" : [ "speedFactor", "mouseShadow", "cellBorders", "stackRange", "movementHighlightOnHover", "rangeLimitHighlightOnHover", "showQueue", "swipeAttackDistance", "queueSize", "stickyHeroInfoWindows", "enableAutocombatSpells" ], | ||||
| 			"properties" : { | ||||
| 				"speedFactor" : { | ||||
| 					"type" : "number", | ||||
| @@ -314,6 +314,10 @@ | ||||
| 				"stickyHeroInfoWindows" : { | ||||
| 					"type" : "boolean", | ||||
| 					"default" : true | ||||
| 				}, | ||||
| 				"enableAutocombatSpells" : { | ||||
| 					"type": "boolean", | ||||
| 					"default": true | ||||
| 				} | ||||
| 			} | ||||
| 		}, | ||||
|   | ||||
| @@ -51,14 +51,37 @@ | ||||
| 			] | ||||
| 		}, | ||||
| 		{ | ||||
| 			"name": "autoCombatCheckboxes", | ||||
| 			"name": "autoCombatFakeCheckboxes", | ||||
| 			"type" : "verticalLayout", | ||||
| 			"customType" : "checkboxFake", | ||||
| 			"position": {"x": 380, "y": 83}, | ||||
| 			"items": | ||||
| 			[ | ||||
| 				{}, | ||||
| 				{}, | ||||
| 				{} | ||||
| 			] | ||||
| 		}, | ||||
|  | ||||
| 		{ | ||||
| 			"type" : "verticalLayout", | ||||
| 			"customType" : "checkbox", | ||||
| 			"position": {"x": 380, "y": 113}, | ||||
| 			"items": | ||||
| 			[ | ||||
| 				{ | ||||
| 					"name": "enableAutocombatSpellsCheckbox", | ||||
| 					"help": "vcmi.battleOptions.enableAutocombatSpells", | ||||
| 					"callback": "enableAutocombatSpellsChanged" | ||||
| 				} | ||||
| 			] | ||||
| 		}, | ||||
|  | ||||
| 		{ | ||||
| 			"name": "autoCombatFakeCheckboxes2", | ||||
| 			"type" : "verticalLayout", | ||||
| 			"customType" : "checkboxFake", | ||||
| 			"position": {"x": 380, "y": 143}, | ||||
| 			"items": | ||||
| 			[ | ||||
| 				{}, | ||||
| 				{}, | ||||
| 				{} | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
|  */ | ||||
| #pragma once | ||||
|  | ||||
| #include "battle/AutocombatPreferences.h" | ||||
| #include "battle/BattleAction.h" | ||||
| #include "IGameEventsReceiver.h" | ||||
|  | ||||
| @@ -76,6 +77,7 @@ public: | ||||
|  | ||||
| 	virtual ~CBattleGameInterface() {}; | ||||
| 	virtual void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB){}; | ||||
| 	virtual void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB, AutocombatPreferences autocombatPreferences){}; | ||||
|  | ||||
| 	//battle call-ins | ||||
| 	virtual void activeStack(const CStack * stack)=0; //called when it's turn of that stack | ||||
|   | ||||
							
								
								
									
										11
									
								
								lib/battle/AutocombatPreferences.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								lib/battle/AutocombatPreferences.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* | ||||
|  * AutocombatPreferences.cpp, part of VCMI engine | ||||
|  * | ||||
|  * Authors: listed in file AUTHORS in main folder | ||||
|  * | ||||
|  * License: GNU General Public License v2.0 or later | ||||
|  * Full text of license available in license.txt file, in main folder | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "AutocombatPreferences.h" | ||||
							
								
								
									
										21
									
								
								lib/battle/AutocombatPreferences.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								lib/battle/AutocombatPreferences.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| /* | ||||
|  * AutocombatPreferences.h, part of VCMI engine | ||||
|  * | ||||
|  * Authors: listed in file AUTHORS in main folder | ||||
|  * | ||||
|  * License: GNU General Public License v2.0 or later | ||||
|  * Full text of license available in license.txt file, in main folder | ||||
|  * | ||||
|  */ | ||||
| #pragma once | ||||
|  | ||||
| struct AutocombatPreferences | ||||
| { | ||||
| 	bool enableSpellsUsage = true; | ||||
| 	//TODO: below options exist in original H3, consider usefulness of mixed human-AI combat when enabling autocombat inside battle | ||||
| 	bool enableUnitsUsage = true; | ||||
| 	bool enableCatapultUsage = true; | ||||
| 	bool enableBallistaUsage = true; | ||||
| 	bool enableFirstAidTendUsage = true; | ||||
| }; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user