From 921c298c9cf066f4eca61045aa773a57444939bd Mon Sep 17 00:00:00 2001
From: Tim Felgentreff <timfelgentreff@gmail.com>
Date: Thu, 23 May 2013 01:23:25 +0200
Subject: [PATCH] add a button check to disable a button when a unit is
 available

---
 src/include/interface.h  |  2 ++
 src/ui/button_checks.cpp | 13 +++++++++++++
 src/ui/script_ui.cpp     |  2 ++
 3 files changed, 17 insertions(+)

diff --git a/src/include/interface.h b/src/include/interface.h
index f8840e58d..c3da5c05d 100644
--- a/src/include/interface.h
+++ b/src/include/interface.h
@@ -405,6 +405,8 @@ extern bool ButtonCheckUnitVariable(const CUnit &unit, const ButtonAction &butto
 extern bool ButtonCheckUnitsOr(const CUnit &unit, const ButtonAction &button);
 /// Check if allowed units exists
 extern bool ButtonCheckUnitsAnd(const CUnit &unit, const ButtonAction &button);
+/// Check if units don't exist
+extern bool ButtonCheckUnitsNot(const CUnit &unit, const ButtonAction &button);
 /// Check if have network play
 extern bool ButtonCheckNetwork(const CUnit &unit, const ButtonAction &button);
 /// Check if don't have network play
diff --git a/src/ui/button_checks.cpp b/src/ui/button_checks.cpp
index cdcc5ad7c..5601ed899 100644
--- a/src/ui/button_checks.cpp
+++ b/src/ui/button_checks.cpp
@@ -202,6 +202,19 @@ bool ButtonCheckUnitsAnd(const CUnit &unit, const ButtonAction &button)
 	return true;
 }
 
+/**
+**  Check for button enabled, if no unit is available.
+**
+**  @param unit    Pointer to unit for button.
+**  @param button  Pointer to button to check/enable.
+**
+**  @return        True if enabled.
+*/
+bool ButtonCheckUnitsNot(const CUnit &unit, const ButtonAction &button)
+{
+    return !ButtonCheckUnitsAnd(unit, button);
+}
+
 /**
 **  Check if network play is enabled.
 **
diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp
index e27ae109b..88527bec4 100644
--- a/src/ui/script_ui.cpp
+++ b/src/ui/script_ui.cpp
@@ -968,6 +968,8 @@ static int CclDefineButton(lua_State *l)
 				ba.Allowed = ButtonCheckUnitsOr;
 			} else if (!strcmp(value, "check-units-and")) {
 				ba.Allowed = ButtonCheckUnitsAnd;
+			} else if (!strcmp(value, "check-units-not")) {
+				ba.Allowed = ButtonCheckUnitsNot;
 			} else if (!strcmp(value, "check-network")) {
 				ba.Allowed = ButtonCheckNetwork;
 			} else if (!strcmp(value, "check-no-network")) {