From 7d5294b708542dc40fa015423bb6dd67c709c763 Mon Sep 17 00:00:00 2001
From: Crestwave <crestwave@users.noreply.github.com>
Date: Wed, 4 Mar 2020 16:41:54 +0800
Subject: Added Haiku support


diff --git a/src/lincity-ng/Config.cpp b/src/lincity-ng/Config.cpp
index fbfa4c6..b9389ea 100644
--- a/src/lincity-ng/Config.cpp
+++ b/src/lincity-ng/Config.cpp
@@ -44,8 +44,13 @@ Config::Config()
     assert(configPtr == 0);
 
     //Default Values
+#ifdef __HAIKU__
+    useOpenGL = false;
+    useFullScreen = false;
+#else
     useOpenGL = true;  //OpenGL is often way too slow
     useFullScreen = true;
+#endif
     videoX = 1024;
     videoY = 768;
 
diff --git a/src/lincity-ng/main.cpp b/src/lincity-ng/main.cpp
index 0f337ff..36b8470 100644
--- a/src/lincity-ng/main.cpp
+++ b/src/lincity-ng/main.cpp
@@ -50,6 +50,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include "lincity/lin-city.h"
 #include "lincity/init_game.h"
 
+#ifdef __HAIKU__
+#include <FindDirectory.h>
+#endif
+
 
 #ifdef ENABLE_BINRELOC
 #include "binreloc.h"
@@ -76,16 +80,27 @@ void initPhysfs(const char* argv0)
     const char* application = LC_SAVE_DIR;
     const char* userdir = PHYSFS_getUserDir();
     const char* dirsep = PHYSFS_getDirSeparator();
+#ifndef __HAIKU__
     char* writedir = new char[strlen(userdir) + strlen(application) + 2];
 
     // Set configuration directory
     //sprintf(writedir, "%s.%s", userdir, application);
     sprintf(writedir, "%s%s", userdir, application);
+#else
+    char path[B_PATH_NAME_LENGTH];
+    find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, path, B_PATH_NAME_LENGTH);
+    char* writedir = new char[strlen(path) + strlen(application) + 2];
+    sprintf(writedir, "%s%c%s", path, PATH_SLASH, application);
+#endif
     if(!PHYSFS_setWriteDir(writedir)) {
         // try to create the directory
         char* mkdir = new char[strlen(application) + 2];
         sprintf(mkdir, "%s", application);
+#ifndef __HAIKU__
         if(!PHYSFS_setWriteDir(userdir) || !PHYSFS_mkdir(mkdir)) {
+#else
+        if(!PHYSFS_setWriteDir(path) || !PHYSFS_mkdir(mkdir)) {
+#endif
             std::ostringstream msg;
             msg << "Failed creating configuration directory '" <<
                 writedir << "': " << PHYSFS_getLastError();
diff --git a/src/lincity/fileutil.cpp b/src/lincity/fileutil.cpp
index 17c0576..b4b568b 100644
--- a/src/lincity/fileutil.cpp
+++ b/src/lincity/fileutil.cpp
@@ -32,6 +32,10 @@
 #include <io.h>
 #endif
 
+#ifdef __HAIKU__
+#include <FindDirectory.h>
+#endif
+
 #if defined (TIME_WITH_SYS_TIME)
 #include <time.h>
 #include <sys/time.h>
@@ -377,14 +381,24 @@ void find_localized_paths(void)
 void init_path_strings(void)
 {
     find_libdir();
+    /* Various dirs and files */
+#if defined(__HAIKU__)
+    char path[B_PATH_NAME_LENGTH];
+    find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, path, B_PATH_NAME_LENGTH);
+
+    lc_save_dir_len = strlen(path) + strlen(LC_SAVE_DIR) + 1;
+    if ((lc_save_dir = (char *)malloc(lc_save_dir_len + 1)) == 0)
+        malloc_failure();
+    sprintf(lc_save_dir, "%s%c%s", path, PATH_SLASH, LC_SAVE_DIR);
+#else
     //TODO: use, remove unused vars.
     const char* homedir = PHYSFS_getUserDir();
 
-    /* Various dirs and files */
     lc_save_dir_len = strlen(homedir) + strlen(LC_SAVE_DIR) + 1;
     if ((lc_save_dir = (char *)malloc(lc_save_dir_len + 1)) == 0)
         malloc_failure();
     sprintf(lc_save_dir, "%s%c%s", homedir, PATH_SLASH, LC_SAVE_DIR);
+#endif
     sprintf(colour_pal_file, "%s%c%s", LIBDIR, PATH_SLASH, "colour.pal");
     sprintf(opening_path, "%s%c%s", LIBDIR, PATH_SLASH, "opening");
 #if defined (WIN32)
@@ -393,7 +407,11 @@ void init_path_strings(void)
     sprintf(opening_pic, "%s%c%s", opening_path, PATH_SLASH, "open.tga.gz");
 #endif
     sprintf(graphic_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "icons", PATH_SLASH);
+#if defined (__HAIKU__)
+    sprintf(lincityrc_file, "%s%c%s", path, PATH_SLASH, LINCITYRC_FILENAME);
+#else
     sprintf(lincityrc_file, "%s%c%s", homedir, PATH_SLASH, LINCITYRC_FILENAME);
+#endif
 
     /* Paths for message & help files, etc */
     find_localized_paths();
diff --git a/src/lincity/loadsave.h b/src/lincity/loadsave.h
index 3905308..8679093 100644
--- a/src/lincity/loadsave.h
+++ b/src/lincity/loadsave.h
@@ -18,8 +18,13 @@
 #   define PATH_SLASH_STRING "/"
 #endif
 
+#if defined(__HAIKU__)
+# define LC_SAVE_DIR "lincity-ng"
+# define LINCITYRC_FILENAME "lincity-NGrc"
+#else
 # define LC_SAVE_DIR ".lincity-ng"
 # define LINCITYRC_FILENAME ".lincity-NGrc"
+#endif
 
 #define RESULTS_FILENAME "results.txt"
 
-- 
2.24.1

