/* maliesystem.txt */
/* Malie System */

#ifndef _MALIESYSTEM_TXT_
#define _MALIESYSTEM_TXT_

/* ------------------------------------------------------------------------- */
/*  */
#define IDS_Malie 1000
static int malie;
int _wipe;
int _name, _dress, _exp;
int _sound_num, _sound_play;
int _screen_id;
//char _face_name[32], _face_dress[32], _face_exp[32];

/* ------------------------------------------------------------------------- */
/* Malie System フォルダ識別子 */
#define MSFID_Bg    1 /* 背景       */
#define MSFID_Event 2 /* イベント   */
#define MSFID_Chara 3 /* キャラクタ */
#define MSFID_Mask  4 /* マスク     */
#define MSFID_Bgm   5 /* ＢＧＭ     */
#define MSFID_Se    6 /* 効果音     */
#define MSFID_Voice 7 /* 音声       */
#define MSFID_Max   8

/* ------------------------------------------------------------------------- */
/* Malie System メッセージ */
#define MSM_Message         100
#define MSM_SetFolder       (MSM_Message+1) /* フォルダ設定       */
#define MSM_SetTextMode     (MSM_Message+2) /* テキストモード設定 */
#define MSM_LoadBG          (MSM_Message+3) /* 背景イメージ読み込み */
#define MSM_SetTextSpeed    (MSM_Message+4) /* テキスト表示速度スピード設定 */
#define MSM_SetFontSize     (MSM_Message+5) /* フォントサイズの設定 */
#define MSM_Wait            (MSM_Message+6) /* ウェイト             */
#define MSM_SetTextPosition (MSM_Message+7) /* テキスト位置の設定   */

#define MSM_SetWipe         (MSM_Message+8) /* ワイプの設定 */
#define MSM_SetFrameRate    (MSM_Message+9) /* フレームレート設定   */

#define MSM_LoadMask        (MSM_Message+10) /* マスクの読み込み */

#define MSM_ClearSelect     (MSM_Message+15) /* 選択のクリア */
#define MSM_AddSelect       (MSM_Message+16) /* 選択項目追加 */
#define MSM_BeginSelect     (MSM_Message+17) /* 選択処理開始 */

#define MSM_ShowMessage     (MSM_Message+18) /* メッセージ枠の表示／非表示 */
#define MSM_ShowWaitCursor  (MSM_Message+19) /* ウェイトカーソルの表示／非表示 */

#define MSM_Exec            (MSM_Message+20) /* 起動 */
#define MSM_Exit            (MSM_Message+21) /* 戻る */

#define MSM_ClearAbsWait    (MSM_Message+24) /* 絶対時間クリア   */
#define MSM_AbsWait         (MSM_Message+25) /* 絶対時間ウェイト */
#define MSM_VoiceWait       (MSM_Message+26) /* 音声ウェイト */

#define MSM_SystemFade      (MSM_Message+27) /* システムフェード処理 */
#define MSM_SoundLoop       (MSM_Message+28) /* サウンドのループ制御 */
#define MSM_GetSystemTime   (MSM_Message+29) /* 時間の取得 */

#define MSM_Sound           (MSM_Message+40) /* ＢＧＭ再生 */
#define MSM_SoundStop       (MSM_Message+41) /* ＢＧＭ停止 */
#define MSM_Voice           (MSM_Message+42) /* 音声再生   */
#define MSM_Se              (MSM_Message+43) /* 効果音再生 */

#define MSM_Chara_Show        (MSM_Message+50) /* キャラ表示     */
#define MSM_Chara_Hide        (MSM_Message+51) /* キャラ非表示   */
#define MSM_Chara_Dress       (MSM_Message+52) /* キャラ服指定   */
#define MSM_Chara_Exp         (MSM_Message+53) /* キャラ表情指定 */
#define MSM_Chara_Update      (MSM_Message+54) /* キャラ更新     */
#define MSM_Chara_Arrangement (MSM_Message+55) /* 配置           */

#define MSM_Face_Show         (MSM_Message+56) 
#define MSM_SetCancel         (MSM_Message+57) /* キャンセルハンドラの設定 */

#define MSM_Chara_SetMoveName (MSM_Message+58)
#define MSM_Chara_SetMovePos  (MSM_Message+59)
#define MSM_Chara_SetMoveType (MSM_Message+60)
#define MSM_Chara_SetMoveTime (MSM_Message+61)
#define MSM_Chara_StartMove   (MSM_Message+62)
#define MSM_Chara_SetPos      (MSM_Message+63)

#define MSM_Name_SetImage     (MSM_Message+64) /* 名前イメージの指定 */

#define MSM_RefDollerString   (MSM_Message+65)
#define MSM_RefSharpString    (MSM_Message+66)
#define MSM_SetDollerString   (MSM_Message+67)

#define MSM_AddString         (MSM_Message+68) /* メッセージ文字列追加 */

#define MSM_ChangeGame        (MSM_Message+69) /* AS */
#define MSM_CheckGame         (MSM_Message+70) /* AS */

#define MSM_GetObject 500

#define DEFAULT_KEY "SIS"

#define _change_game(key) FrameLayer_SendMessage(malie, MSM_ChangeGame, 0, key)

/* ------------------------------------------------------------------------- */
/* MSM_GetSystemTime */
#define GST_Year   0 /* 年 */
#define GST_Month  1 /* 月 */
#define GST_Day    2 /* 日 */
#define GST_Hour   3 /* 時 */
#define GST_Minute 4 /* 分 */
#define GST_Second 5 /* 秒 */

#define WAIT(time) \
	FrameLayer_SendMessage(malie, MSM_Wait, time, 0)

#define _gethour(type) \
	FrameLayer_SendMessage(malie, MSM_GetSystemTime, type, 0)

/*  */
#define OL     0
#define NONE   1 /* 仮 */
#define CUT    2
#define MASK   3 /* マスク */
#define BREAK  4
#define RETURN 5
#define FLASH  11
#define SHAKE  12
#define SHADE  13
#define WO     20

#define _se(n) FrameLayer_SendMessage(malie, MSM_Se, n, 0)
#define _se_name(name) FrameLayer_SendMessage(malie, MSM_Se, 0, name)
/*  */
#define _setdollerstring(n, s) FrameLayer_SendMessage(malie, MSM_SetDollerString, n, s)
//#define _wait(n)   WAIT(300*(n))
#define _wait(n)   WAIT(n)
#define _wipe_set(wipe, time) FrameLayer_SendMessage(malie, MSM_SetWipe    , wipe, time)
#define _voice(name)          FrameLayer_SendMessage(malie, MSM_Voice      , 0   , name)
#define _wipe_mask(mask)      FrameLayer_SendMessage(malie, MSM_LoadMask   , 0   , mask)
#define _mask(name)           FrameLayer_SendMessage(malie, MSM_LoadMask   , 0   , name)
#define _loadcg(name)         FrameLayer_SendMessage(malie, MSM_LoadBG     , 0   , name)
#define _textmode(mode)       FrameLayer_SendMessage(malie, MSM_SetTextMode, mode, 0   )
#define _sound(num)           _sound_num = num; _sound_play = TRUE; FrameLayer_SendMessage(malie, MSM_Sound      , num , 0   )
#define _sound_fi(num)        _sound_num = num; _sound_play = TRUE; FrameLayer_SendMessage(malie, MSM_Sound      , num , 2000)
#define _soundstop(time)      _sound_play = FALSE; FrameLayer_SendMessage(malie, MSM_SoundStop  , 0   , time)
#define _showcursor(show)     FrameLayer_SendMessage(malie, MSM_ShowWaitCursor, 0, show)
#define _voicewait()          FrameLayer_SendMessage(malie, MSM_VoiceWait, 0, 0)
#define _soundloop(b)         FrameLayer_SendMessage(malie, MSM_SoundLoop, b, 0)

int _timer_count;
#define _timer_clear          FrameLayer_SendMessage(malie, MSM_ClearAbsWait, 0, 0); _timer_count = 0
#define _timer_wait(time)     FrameLayer_SendMessage(malie, MSM_AbsWait     , time, 0); _timer_count = time
#define _timer_wait2(time)    _timer_wait(_timer_count + time)

#define _changescreen(id) _screen_id = id; System_ChangeScreen(id)

#define _wipe_time(time) 
#define _fontsize(n)     
#define _chara_pos(pos)  
#define _chara_clear_pos(pos) 
#define _pause           &pause
#define _clear           &clear

#define rand Random

#define _exception(name, label) FrameLayer_SendMessage(malie, MSM_SetCancel, name, label)
#define _title_goto(lable)     _exception("title", lable)
#define _cancel_goto(label)    _exception("cancel", label)
#define _canceljump(label)     _exception("cancel", label)

/* TextMode */
#define TM_NORMAL 0 /* 通常 */
#define TM_SYNC   1 /* 同期 */
#define TM_SLOW   2 /* 遅い */

#define MAKELONG(a, b) ((a) | ((b)<<16))

#define _clearbutton()          FrameLayer_SendMessage(malie, MSM_ClearSelect, 0, 0)
#define _addbutton(n, s)        FrameLayer_SendMessage(malie, MSM_AddSelect, MAKELONG(n, 1), s)
#define _addbutton_cmp(n, b, s) FrameLayer_SendMessage(malie, MSM_AddSelect, MAKELONG(n, b), s)
#define _beginselect()          FrameLayer_SendMessage(malie, MSM_BeginSelect, 0, 0)

#define MSM_ClearSelect     (MSM_Message+15) /* 選択のクリア */
#define MSM_AddSelect       (MSM_Message+16) /* 選択項目追加 */
#define MSM_BeginSelect     (MSM_Message+17) /* 選択処理開始 */

#define _flash() \
	_showcursor(FALSE); \
	System_TakeScreen(0); \
	_wipe_set(FLASH, 250); \
	System_TakeScreen(1); \
	&ol; \
	System_TakeScreen(2)

#define _shake() \
	_showcursor(FALSE); \
	System_TakeScreen(0); \
	_wipe_set(SHAKE, 250); \
	System_TakeScreen(1); \
	&ol; \
	System_TakeScreen(2)

#define _break() \
	_showcursor(FALSE); \
	System_TakeScreen(0); \
	_loadcg("black"); \
	System_TakeScreen(1); \
	_wipe_set(BREAK, 2000); \
	&ol; \
	System_TakeScreen(2)

/* ----------------------------------------------------------------------- */
/*  */
CG_BG:
{
	_showcursor(FALSE);
	System_TakeScreen(0);
	if (_wipe == NONE)
	{
		_wipe_mask("lrp");
		_wipe_set(MASK, 1000);
	}
	else
	{
		_wipe_set(_wipe, 1000);
	}
	_loadcg(_name);
	System_TakeScreen(1);
	&ol;
	System_TakeScreen(2);
	
	_end;
}

CG:
{
	_showcursor(FALSE);
	System_TakeScreen(0);
	if (_wipe == NONE)
	{
		_wipe = OL;
	}
	_wipe_set(_wipe, 1000);
	_loadcg(_name);
	System_TakeScreen(1);
	&ol;
	System_TakeScreen(2);
	
	_end;
}

#define _cg(name, wipe) _name = name; _wipe = wipe; _call(CG);
#define _cg_bg(name, wipe) _name = name; _wipe = wipe; _call(CG_BG);

/* ----------------------------------------------------------------------- */
/* フェードアウト */
FADEOUT:
{
	out_debug("FADEOUT %d\n", _wipe);
	if (_wipe == WO)
	{
		_wipe_mask("WO");
		_cg("white", MASK);
	}
	else if (_wipe == SHADE)
	{
		_cg("black", SHADE);
	}
	else
	{
		_cg("black", OL);
	}
	
	_end;
}

#define _fo(wipe)  _wipe = wipe; _call(FADEOUT)
#define _shadefo() _wipe = SHADE; _call(FADEOUT)

/* ----------------------------------------------------------------------- */
/* 立ちキャラ表示 */
CHARA_SHOW:
	_showcursor(FALSE);
	_wipe_set(OL, 500);
	System_TakeScreen(0);
	FrameLayer_SendMessage(malie, MSM_Chara_Show       , _name, NULL  );
	FrameLayer_SendMessage(malie, MSM_Chara_Exp        , _name, _exp  );
	FrameLayer_SendMessage(malie, MSM_Chara_Update     , _name, NULL  );
	FrameLayer_SendMessage(malie, MSM_Chara_Arrangement, NULL , NULL  );
	System_TakeScreen(1);
	&ol;
	System_TakeScreen(2);
	_end;

CHARA_SHOW_DRESS:
	_showcursor(FALSE);
	_wipe_set(OL, 500);
	System_TakeScreen(0);
	FrameLayer_SendMessage(malie, MSM_Chara_Show       , _name, NULL  );
	FrameLayer_SendMessage(malie, MSM_Chara_Dress      , _name, _dress);
	FrameLayer_SendMessage(malie, MSM_Chara_Exp        , _name, _exp  );
	FrameLayer_SendMessage(malie, MSM_Chara_Update     , _name, NULL  );
	FrameLayer_SendMessage(malie, MSM_Chara_Arrangement, NULL , NULL  );
	System_TakeScreen(1);
	&ol;
	System_TakeScreen(2);
	_end;

CHARA_HIDE:
	_showcursor(FALSE);
	_wipe_set(OL, 500);
	System_TakeScreen(0);
	FrameLayer_SendMessage(malie, MSM_Chara_Hide       , _name, NULL );
	FrameLayer_SendMessage(malie, MSM_Chara_Arrangement, NULL, NULL );
	System_TakeScreen(1);
	&ol;
	System_TakeScreen(2);
	_end;

/* 顔表示 */
FACE_SHOW:
//	strcpy(_face_name, _name );
//	strcpy(_face_exp , _exp  );
	FrameLayer_SendMessage(malie, MSM_Chara_Exp  , _name, _exp  );
	FrameLayer_SendMessage(malie, MSM_Face_Show  , _name, NULL  );
	_end;

FACE_SHOW_DRESS:
//	strcpy(_face_name , _name );
//	strcpy(_face_exp  , _exp  );
//	strcpy(_face_dress, _dress);
	FrameLayer_SendMessage(malie, MSM_Chara_Dress, _name, _dress);
	FrameLayer_SendMessage(malie, MSM_Chara_Exp  , _name, _exp  );
	FrameLayer_SendMessage(malie, MSM_Face_Show  , _name, NULL  );
	_end;

#define _chara_dress_exp(name, dress, exp) _name = name; _dress = dress; _exp = exp; _call(CHARA_SHOW_DRESS)
#define _chara_exp(name, exp) _name = name; _exp = exp; _call(CHARA_SHOW)

#define _face_dress_exp(name,dress,exp) _name = name; _dress = dress; _exp = exp; _call(FACE_SHOW_DRESS)
#define _face_exp(name,exp) _name = name; _exp = exp; _call(FACE_SHOW)

/* 立ちキャラを隠す */
#define _chara_clear(name) _name = name; _call(CHARA_HIDE)
#define _chara_clear_all() _chara_clear(NULL)

/* キャラ位置識別子 */
#define CHARA_LO  0 /* 左外   */
#define CHARA_L   1 /* 左     */
#define CHARA_C   2 /* 中央   */
#define CHARA_R   3 /* 右     */
#define CHARA_RO  4 /* 右外   */
#define CHARA_LBO 5 /* 左後外 */
#define CHARA_LB  6 /* 左後   */
#define CHARA_CB  7 /* 中央後 */
#define CHARA_RB  8 /* 右後   */
#define CHARA_RBO 9 /* 右後外 */
#define CHARA_AUTO -1

int _pos;

CHARA_SHOW_DRESS_POS:
{
	_showcursor(FALSE);
	_wipe_set(OL, 500);
	System_TakeScreen(0);
	FrameLayer_SendMessage(malie, MSM_Chara_Dress      , _name, _dress);
	FrameLayer_SendMessage(malie, MSM_Chara_Exp        , _name, _exp  );
	if (_pos != CHARA_AUTO)
	{
		FrameLayer_SendMessage(malie, MSM_Chara_SetPos     , _name, _pos  );
	}
	FrameLayer_SendMessage(malie, MSM_Chara_Show       , _name, NULL  );
	FrameLayer_SendMessage(malie, MSM_Chara_Update     , _name, NULL  );
	System_TakeScreen(1);
	&ol;
	System_TakeScreen(2);
	
	_end;
}

#define _chara_dress_exp_pos_time(name, dress, exp, pos, time) _name = name; _dress = dress; _exp = exp; _pos = pos; _call(CHARA_SHOW_DRESS_POS)

int _type_;
int _time_;

#define _chara_move(name, pos, type, time) \
	_name = name; _pos = pos; _type_ = type; _time_ = time; \
	_call(CHARA_MOVE)

CHARA_MOVE:
{
	FrameLayer_SendMessage(malie, MSM_Chara_SetMoveName, _name, 0);
	FrameLayer_SendMessage(malie, MSM_Chara_SetMovePos , _pos , 0);
	FrameLayer_SendMessage(malie, MSM_Chara_SetMoveType, _type_, 0);
	FrameLayer_SendMessage(malie, MSM_Chara_SetMoveTime, _time_, 0);
	FrameLayer_SendMessage(malie, MSM_Chara_StartMove  , 0   , 0);
	_end;
}

/* 名前イメージの指定 */
#define _name_image(name) \
	FrameLayer_SendMessage(malie, MSM_Name_SetImage, 0, name)

/* 特殊文字出力（ハート） */
#define _exchar(n) FrameLayer_SendMessage(malie, MSM_AddString, 0, "\xFF\x01")

#include "obj.txt" /* オブジェクト処理 */

#endif /* _MALIESYSTEM_TXT_ */

/* eof */