2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-12-24 00:00:10 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:39:29 +00:00
|
|
|
#include "openttd.h"
|
2005-07-22 16:14:24 +00:00
|
|
|
#include "variables.h"
|
2005-02-06 13:41:02 +00:00
|
|
|
#include "string.h"
|
2004-12-24 00:00:10 +00:00
|
|
|
#include "table/strings.h"
|
2005-06-02 10:39:46 +00:00
|
|
|
#include "gfx.h"
|
|
|
|
#include "gui.h"
|
2005-07-22 16:14:24 +00:00
|
|
|
#include "functions.h"
|
|
|
|
#include "macros.h"
|
2004-12-24 00:00:10 +00:00
|
|
|
|
|
|
|
#include <direct.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
2005-06-02 09:51:01 +00:00
|
|
|
#include <stdlib.h>
|
2004-12-24 00:00:10 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <dos.h>
|
|
|
|
|
2004-12-28 12:11:34 +00:00
|
|
|
#define INCL_WIN
|
2005-03-19 22:36:13 +00:00
|
|
|
#define INCL_WINCLIPBOARD
|
2004-12-27 10:40:04 +00:00
|
|
|
|
2004-12-24 00:00:10 +00:00
|
|
|
#include <os2.h>
|
2005-07-22 16:14:24 +00:00
|
|
|
#include <i86.h>
|
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
bool FiosIsRoot(const char *file)
|
2004-12-27 10:40:04 +00:00
|
|
|
{
|
2006-08-05 00:47:32 +00:00
|
|
|
return path[3] == '\0';
|
2004-12-27 10:40:04 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 00:47:32 +00:00
|
|
|
void FiosGetDrives(void)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
|
|
|
FiosItem *fios;
|
2006-08-05 00:47:32 +00:00
|
|
|
unsigned disk, disk2, save, total;
|
|
|
|
|
|
|
|
_dos_getdrive(&save); // save original drive
|
|
|
|
|
|
|
|
/* get an available drive letter */
|
|
|
|
for (disk = 1;; disk++) {
|
|
|
|
_dos_setdrive(disk, &total);
|
|
|
|
if (disk >= total) return;
|
|
|
|
_dos_getdrive(&disk2);
|
|
|
|
|
|
|
|
if (disk == disk2) {
|
|
|
|
FiosItem *fios = FiosAlloc();
|
|
|
|
fios->type = FIOS_TYPE_DRIVE;
|
|
|
|
fios->mtime = 0;
|
|
|
|
snprintf(fios->name, lengthof(fios->name), "%c:", 'A' + disk - 1);
|
|
|
|
ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-05 00:47:32 +00:00
|
|
|
_dos_setdrive(save, &total); // restore the original drive
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2006-08-05 00:53:09 +00:00
|
|
|
struct diskfree_t free;
|
|
|
|
char drive = path[0] - 'A' + 1;
|
2004-12-24 00:00:10 +00:00
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
if (tot != NULL && _getdiskfree(drive, &free) == 0) {
|
|
|
|
*tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector;
|
|
|
|
return true;
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
return false;
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2006-08-05 00:53:09 +00:00
|
|
|
char filename[MAX_PATH];
|
2004-12-24 00:00:10 +00:00
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
|
|
|
|
if (stat(filename, sb) != 0) return false;
|
2004-12-27 10:40:04 +00:00
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
return (ent->d_name[0] != '.'); // hidden file
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ChangeWorkingDirectory(char *exe)
|
|
|
|
{
|
|
|
|
char *s = strrchr(exe, '\\');
|
|
|
|
if (s != NULL) {
|
2005-03-11 14:14:54 +00:00
|
|
|
*s = '\0';
|
2004-12-24 00:00:10 +00:00
|
|
|
chdir(exe);
|
|
|
|
*s = '\\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowInfo(const char *str)
|
|
|
|
{
|
2004-12-28 12:11:34 +00:00
|
|
|
HAB hab;
|
|
|
|
HMQ hmq;
|
|
|
|
ULONG rc;
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2004-12-28 12:11:34 +00:00
|
|
|
// init PM env.
|
|
|
|
hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
|
|
|
|
|
|
|
|
// display the box
|
|
|
|
rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, str, "OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_INFORMATION);
|
|
|
|
|
|
|
|
// terminate PM env.
|
|
|
|
WinDestroyMsgQueue(hmq);
|
|
|
|
WinTerminate(hab);
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowOSErrorBox(const char *buf)
|
|
|
|
{
|
2004-12-28 12:11:34 +00:00
|
|
|
HAB hab;
|
|
|
|
HMQ hmq;
|
|
|
|
ULONG rc;
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2004-12-28 12:11:34 +00:00
|
|
|
// init PM env.
|
|
|
|
hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
|
|
|
|
|
|
|
|
// display the box
|
|
|
|
rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, buf, "OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_ERROR);
|
|
|
|
|
|
|
|
// terminate PM env.
|
|
|
|
WinDestroyMsgQueue(hmq);
|
|
|
|
WinTerminate(hab);
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CDECL main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
// change the working directory to enable doubleclicking in UIs
|
|
|
|
ChangeWorkingDirectory(argv[0]);
|
|
|
|
|
2006-08-24 10:19:59 +00:00
|
|
|
_random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
|
2004-12-24 00:00:10 +00:00
|
|
|
|
|
|
|
return ttd_main(argc, argv);
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
void DeterminePaths(void)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
2005-03-11 14:14:54 +00:00
|
|
|
_path.game_data_dir = malloc(MAX_PATH);
|
2004-12-24 00:00:10 +00:00
|
|
|
ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH);
|
|
|
|
#if defined SECOND_DATA_DIR
|
2005-03-11 14:14:54 +00:00
|
|
|
_path.second_data_dir = malloc(MAX_PATH);
|
|
|
|
ttd_strlcpy(_path.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
|
2004-12-24 00:00:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_HOMEDIR)
|
|
|
|
{
|
2005-03-11 14:14:54 +00:00
|
|
|
const char *homedir = getenv("HOME");
|
2004-12-24 00:00:10 +00:00
|
|
|
|
2005-03-11 14:14:54 +00:00
|
|
|
if (homedir == NULL) {
|
|
|
|
const struct passwd *pw = getpwuid(getuid());
|
|
|
|
if (pw != NULL) homedir = pw->pw_dir;
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* not defined(USE_HOMEDIR) */
|
|
|
|
|
2005-03-11 14:14:54 +00:00
|
|
|
_path.personal_dir = malloc(MAX_PATH);
|
2004-12-24 00:00:10 +00:00
|
|
|
ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH);
|
|
|
|
|
|
|
|
// check if absolute or relative path
|
|
|
|
s = strchr(_path.personal_dir, '\\');
|
|
|
|
|
|
|
|
// add absolute path
|
2005-03-11 14:14:54 +00:00
|
|
|
if (s == NULL || _path.personal_dir != s) {
|
2004-12-24 00:00:10 +00:00
|
|
|
getcwd(_path.personal_dir, MAX_PATH);
|
|
|
|
s = strchr(_path.personal_dir, 0);
|
|
|
|
*s++ = '\\';
|
|
|
|
ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(USE_HOMEDIR) */
|
|
|
|
|
|
|
|
s = strchr(_path.personal_dir, 0);
|
|
|
|
|
|
|
|
// append a / ?
|
2005-03-11 14:14:54 +00:00
|
|
|
if (s[-1] != '\\') strcpy(s, "\\");
|
2004-12-24 00:00:10 +00:00
|
|
|
|
|
|
|
_path.save_dir = str_fmt("%ssave", _path.personal_dir);
|
|
|
|
_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir);
|
|
|
|
_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
_path.heightmap_dir = str_fmt("%sscenario\\heightmap", _path.personal_dir);
|
2004-12-24 00:00:10 +00:00
|
|
|
_path.gm_dir = str_fmt("%sgm\\", _path.game_data_dir);
|
|
|
|
_path.data_dir = str_fmt("%sdata\\", _path.game_data_dir);
|
2005-03-10 21:44:17 +00:00
|
|
|
|
|
|
|
if (_config_file == NULL)
|
|
|
|
_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2005-03-11 14:14:54 +00:00
|
|
|
_highscore_file = str_fmt("%shs.dat", _path.personal_dir);
|
|
|
|
_log_file = str_fmt("%sopenttd.log", _path.personal_dir);
|
|
|
|
|
2004-12-24 00:00:10 +00:00
|
|
|
#if defined CUSTOM_LANG_DIR
|
|
|
|
// sets the search path for lng files to the custom one
|
|
|
|
_path.lang_dir = malloc( MAX_PATH );
|
|
|
|
ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
|
|
|
|
#else
|
|
|
|
_path.lang_dir = str_fmt("%slang\\", _path.game_data_dir);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// create necessary folders
|
|
|
|
mkdir(_path.personal_dir);
|
|
|
|
mkdir(_path.save_dir);
|
|
|
|
mkdir(_path.autosave_dir);
|
|
|
|
mkdir(_path.scenario_dir);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
mkdir(_path.heightmap_dir);
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2005-06-02 10:39:46 +00:00
|
|
|
/**
|
|
|
|
* Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
|
|
|
|
* and append this up to the maximum length (either absolute or screenlength). If maxlength
|
|
|
|
* is zero, we don't care about the screenlength but only about the physical length of the string
|
|
|
|
* @param tb @Textbuf type to be changed
|
|
|
|
* @return Return true on successfull change of Textbuf, or false otherwise
|
|
|
|
*/
|
2005-03-11 14:14:54 +00:00
|
|
|
bool InsertTextBufferClipboard(Textbuf *tb)
|
|
|
|
{
|
2005-06-02 19:55:37 +00:00
|
|
|
HAB hab = 0;
|
2005-03-19 22:36:13 +00:00
|
|
|
|
|
|
|
if (WinOpenClipbrd(hab))
|
|
|
|
{
|
2005-06-02 19:55:37 +00:00
|
|
|
const char* text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
if (text != NULL)
|
|
|
|
{
|
|
|
|
uint length = 0;
|
|
|
|
uint width = 0;
|
|
|
|
const char* i;
|
2005-03-19 22:36:13 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
for (i = text; IsValidAsciiChar(*i); i++)
|
|
|
|
{
|
|
|
|
uint w;
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
if (tb->length + length >= tb->maxlength - 1) break;
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2006-05-09 15:43:40 +00:00
|
|
|
w = GetCharacterWidth(FS_NORMAL, (byte)*i);
|
2005-06-02 19:55:37 +00:00
|
|
|
if (tb->maxwidth != 0 && width + tb->width + w > tb->maxwidth) break;
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
width += w;
|
|
|
|
length++;
|
|
|
|
}
|
|
|
|
|
|
|
|
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1);
|
|
|
|
memcpy(tb->buf + tb->caretpos, text, length);
|
|
|
|
tb->width += width;
|
|
|
|
tb->caretxoffs += width;
|
|
|
|
tb->length += length;
|
|
|
|
tb->caretpos += length;
|
|
|
|
|
|
|
|
WinCloseClipbrd(hab);
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
WinCloseClipbrd(hab);
|
|
|
|
}
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
return false;
|
2005-03-11 14:14:54 +00:00
|
|
|
}
|
2005-06-02 09:51:01 +00:00
|
|
|
|
2005-07-22 16:14:24 +00:00
|
|
|
|
|
|
|
void CSleep(int milliseconds)
|
|
|
|
{
|
|
|
|
delay(milliseconds);
|
|
|
|
}
|