frontlib: Added functions to query important constants from the library
authorMedo <smaxein@googlemail.com>
Sun, 12 Aug 2012 22:21:09 +0200
changeset 7479 c8c552ee3acb
parent 7476 2fb781bbdd51
child 7482 d70a5b0d1190
frontlib: Added functions to query important constants from the library
project_files/frontlib/hwconsts.c
project_files/frontlib/hwconsts.h
--- a/project_files/frontlib/hwconsts.c	Mon Aug 06 22:39:36 2012 +0200
+++ b/project_files/frontlib/hwconsts.c	Sun Aug 12 22:21:09 2012 +0200
@@ -19,5 +19,26 @@
 
 #include "hwconsts.h"
 
-const uint32_t flib_teamcolor_defaults[] = HW_TEAMCOLOR_ARRAY;
-const size_t flib_teamcolor_defaults_len = sizeof(flib_teamcolor_defaults)/sizeof(uint32_t)-1;
+const uint32_t flib_teamcolors[] = HW_TEAMCOLOR_ARRAY;
+const size_t flib_teamcolor_count = sizeof(flib_teamcolors)/sizeof(uint32_t)-1;
+
+
+uint32_t flib_get_teamcolor(int colorIndex) {
+	if(colorIndex>=0 && colorIndex < flib_teamcolor_count) {
+		return flib_teamcolors[colorIndex];
+	} else {
+		return 0;
+	}
+}
+
+int flib_get_teamcolor_count() {
+	return flib_teamcolor_count;
+}
+
+int flib_get_hedgehogs_per_team() {
+	return HEDGEHOGS_PER_TEAM;
+}
+
+int flib_get_weapons_count() {
+	return WEAPONS_COUNT;
+}
--- a/project_files/frontlib/hwconsts.h	Mon Aug 06 22:39:36 2012 +0200
+++ b/project_files/frontlib/hwconsts.h	Sun Aug 12 22:21:09 2012 +0200
@@ -20,6 +20,10 @@
 /**
  * This file contains important constants which might need to be changed to adapt to
  * changes in the engine or protocols.
+ *
+ * It also contains getter functions for some constants (in particular for constants
+ * that are important for the layout of data structures), so that client code can
+ * query the constants that the library was built with.
  */
 
 #ifndef HWCONSTS_H_
@@ -49,10 +53,29 @@
                               UINT32_C(0xff5f3605), /* brown  */ \
                               UINT32_C(0xffffff01), /* yellow */ \
                               /* add new colors here */ \
-                              0 } /* Keep this 0 at the end or the length will be calculated wrong */
+                              0 } /* Keep this 0 at the end */
+
+extern const size_t flib_teamcolor_count;
+extern const uint32_t flib_teamcolors[];
+
+/**
+ * Returns the team color (ARGB) corresponding to the color index (0 if index out of bounds)
+ */
+uint32_t flib_get_teamcolor(int colorIndex);
 
-// TODO allow setting alternative color lists?
-extern const size_t flib_teamcolor_defaults_len;
-extern const uint32_t flib_teamcolor_defaults[];
+/**
+ * Returns the number of team colors (i.e. the length of the flib_teamcolors array)
+ */
+int flib_get_teamcolor_count();
+
+/**
+ * Returns the HEDGEHOGS_PER_TEAM constant
+ */
+int flib_get_hedgehogs_per_team();
+
+/**
+ * Returns the WEAPONS_COUNT constant
+ */
+int flib_get_weapons_count();
 
 #endif