@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222#include " filesys.h"
2323#include " settings.h"
2424#include " log.h"
25+ #include " strfnd.h"
2526#ifndef SERVER
2627#include " tile.h" // getImagePath
2728#endif
@@ -59,13 +60,35 @@ struct GameFindPath
5960 {}
6061};
6162
63+ Strfnd getSubgamePathEnv () {
64+ std::string sp;
65+ char *subgame_path = getenv (" MINETEST_SUBGAME_PATH" );
66+
67+ if (subgame_path) {
68+ sp = std::string (subgame_path);
69+ }
70+
71+ return Strfnd (sp);
72+ }
73+
6274SubgameSpec findSubgame (const std::string &id)
6375{
6476 if (id == " " )
6577 return SubgameSpec ();
6678 std::string share = porting::path_share;
6779 std::string user = porting::path_user;
6880 std::vector<GameFindPath> find_paths;
81+
82+ Strfnd search_paths = getSubgamePathEnv ();
83+
84+ while (!search_paths.atend ()) {
85+ std::string path = search_paths.next (" :" );
86+ find_paths.push_back (GameFindPath (
87+ path + DIR_DELIM + id, false ));
88+ find_paths.push_back (GameFindPath (
89+ path + DIR_DELIM + id + " _game" , false ));
90+ }
91+
6992 find_paths.push_back (GameFindPath (
7093 user + DIR_DELIM + " games" + DIR_DELIM + id + " _game" , true ));
7194 find_paths.push_back (GameFindPath (
@@ -129,6 +152,13 @@ std::set<std::string> getAvailableGameIds()
129152 std::set<std::string> gamespaths;
130153 gamespaths.insert (porting::path_share + DIR_DELIM + " games" );
131154 gamespaths.insert (porting::path_user + DIR_DELIM + " games" );
155+
156+ Strfnd search_paths = getSubgamePathEnv ();
157+
158+ while (!search_paths.atend ()) {
159+ gamespaths.insert (search_paths.next (" :" ));
160+ }
161+
132162 for (std::set<std::string>::const_iterator i = gamespaths.begin ();
133163 i != gamespaths.end (); i++){
134164 std::vector<fs::DirListNode> dirlist = fs::GetDirListing (*i);
0 commit comments