1 Star 1 Fork 2

weimingtom/Onscripter-Official

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ONScripter_command.cpp 116.61 KB
一键复制 编辑 原始数据 按行查看 历史
只要998 提交于 2020-06-01 21:05 . 20200530
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334
/* -*- C++ -*-
*
* ONScripter_command.cpp - Command executer of ONScripter
*
* Copyright (c) 2001-2019 Ogapee. All rights reserved.
*
* ogapee@aqua.dti2.ne.jp
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ONScripter.h"
#if defined(LINUX) || defined(MACOSX) || defined(IOS)
#include <sys/types.h>
#include <sys/stat.h>
#elif defined(WIN32)
#include <direct.h>
#endif
#include "version.h"
#if defined(MACOSX) && (SDL_COMPILEDVERSION >= 1208)
#include <CoreFoundation/CoreFoundation.h>
#endif
extern SDL_TimerID timer_bgmfade_id;
extern "C" Uint32 SDLCALL bgmfadeCallback( Uint32 interval, void *param );
extern "C" void smpegCallback();
extern unsigned short convUTF162SJIS(unsigned short in);
#define CONTINUOUS_PLAY
int ONScripter::yesnoboxCommand()
{
bool yesno_flag = true;
if ( script_h.isName( "okcancelbox" ) ) yesno_flag = false;
script_h.readInt();
script_h.pushVariable();
script_h.readStr();
const char *mes1 = script_h.saveStringBuffer();
const char *mes2 = script_h.readStr();
ButtonLink *tmp_button_link = root_button_link.next;
root_button_link.next = NULL;
buildDialog(yesno_flag, mes1, mes2);
show_dialog_flag = true;
dirty_rect.add(dialog_info.pos);
flush(refreshMode());
while(1){
event_mode = WAIT_BUTTON_MODE;
waitEvent(-1);
if (current_button_state.button == -1 ||
current_button_state.button == 2){
script_h.setInt(&script_h.pushed_variable, 0);
break;
}
else if (current_button_state.button == 1){
script_h.setInt(&script_h.pushed_variable, 1);
break;
}
}
show_dialog_flag = false;
delete root_button_link.next->next;
delete root_button_link.next;
root_button_link.next = tmp_button_link;
dirty_rect.add(dialog_info.pos);
flush(refreshMode());
return RET_CONTINUE;
}
int ONScripter::wavestopCommand()
{
if ( wave_sample[MIX_WAVE_CHANNEL] ){
Mix_Pause( MIX_WAVE_CHANNEL );
Mix_FreeChunk( wave_sample[MIX_WAVE_CHANNEL] );
wave_sample[MIX_WAVE_CHANNEL] = NULL;
}
setStr( &wave_file_name, NULL );
return RET_CONTINUE;
}
int ONScripter::waveCommand()
{
wave_play_loop_flag = false;
if (script_h.isName( "waveloop" ))
wave_play_loop_flag = true;
wavestopCommand();
setStr(&wave_file_name, script_h.readStr());
playSound(wave_file_name, SOUND_CHUNK, wave_play_loop_flag, MIX_WAVE_CHANNEL);
return RET_CONTINUE;
}
int ONScripter::waittimerCommand()
{
int count = script_h.readInt() + internal_timer - SDL_GetTicks();
if (count < 0) count = 0;
event_mode = WAIT_TIMER_MODE;
waitEvent( count );
return RET_CONTINUE;
}
int ONScripter::waitCommand()
{
event_mode = WAIT_TIMER_MODE;
waitEvent( script_h.readInt() );
return RET_CONTINUE;
}
int ONScripter::vspCommand()
{
leaveTextDisplayMode();
bool vsp2_flag = false;
if (script_h.isName("vsp2")) vsp2_flag = true;
int no = script_h.readInt();
int v = script_h.readInt();
if (vsp2_flag){
sprite2_info[no].visible = (v==1)?true:false;
dirty_rect.add( sprite2_info[no].bounding_rect );
}
else{
sprite_info[no].visible = (v==1)?true:false;
dirty_rect.add( sprite_info[no].pos );
}
return RET_CONTINUE;
}
int ONScripter::voicevolCommand()
{
voice_volume = script_h.readInt();
if ( wave_sample[0] ) Mix_Volume( 0, voice_volume * MIX_MAX_VOLUME / 100 );
return RET_CONTINUE;
}
int ONScripter::vCommand()
{
char buf[256];
sprintf(buf, RELATIVEPATH "wav%c%s.wav", DELIMITER, script_h.getStringBuffer()+1);
playSound(buf, SOUND_CHUNK, false, MIX_WAVE_CHANNEL);
return RET_CONTINUE;
}
int ONScripter::trapCommand()
{
bool is_clicked = trap_mode & TRAP_CLICKED;
if ( script_h.isName( "lr_trap" ) ){
trap_mode = TRAP_LEFT_CLICK | TRAP_RIGHT_CLICK;
}
else if ( script_h.isName( "r_trap" ) ){
trap_mode = TRAP_RIGHT_CLICK;
}
else if ( script_h.isName( "trap" ) ){
trap_mode = TRAP_LEFT_CLICK;
}
if ( script_h.compareString("off") ){
script_h.readLabel();
trap_mode = TRAP_NONE;
return RET_CONTINUE;
}
else if ( script_h.compareString("stop") ){
script_h.readLabel();
trap_mode |= TRAP_STOP;
return RET_CONTINUE;
}
else if ( script_h.compareString("resume") ){
script_h.readLabel();
if (is_clicked) trapHandler();
return RET_CONTINUE;
}
const char *buf = script_h.readStr();
if ( buf[0] == '*' ){
setStr(&trap_dist, buf+1);
}
else{
printf("trapCommand: [%s] is not supported\n", buf );
}
return RET_CONTINUE;
}
int ONScripter::transbtnCommand()
{
transbtn_flag = true;
return RET_CONTINUE;
}
int ONScripter::textspeeddefaultCommand()
{
sentence_font.wait_time = -1;
return RET_CONTINUE;
}
int ONScripter::textspeedCommand()
{
sentence_font.wait_time = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::textshowCommand()
{
dirty_rect.fill( screen_width, screen_height );
refresh_shadow_text_mode = REFRESH_NORMAL_MODE | REFRESH_SHADOW_MODE | REFRESH_TEXT_MODE;
flush(refreshMode());
return RET_CONTINUE;
}
int ONScripter::textonCommand()
{
if (windowchip_sprite_no >= 0)
sprite_info[windowchip_sprite_no].visible = true;
enterTextDisplayMode();
text_on_flag = true;
return RET_CONTINUE;
}
int ONScripter::textoffCommand()
{
if (windowchip_sprite_no >= 0)
sprite_info[windowchip_sprite_no].visible = false;
leaveTextDisplayMode(true);
text_on_flag = false;
return RET_CONTINUE;
}
int ONScripter::texthideCommand()
{
dirty_rect.fill( screen_width, screen_height );
refresh_shadow_text_mode = REFRESH_NORMAL_MODE | REFRESH_SHADOW_MODE;
flush(refreshMode());
return RET_CONTINUE;
}
int ONScripter::textcolorCommand()
{
readColor( &sentence_font.color, script_h.readStr() );
return RET_CONTINUE;
}
int ONScripter::textclearCommand()
{
newPage();
return RET_CONTINUE;
}
int ONScripter::texecCommand()
{
if ( textgosub_clickstr_state == CLICK_NEWPAGE )
newPage();
else if ( textgosub_clickstr_state == (CLICK_WAIT|CLICK_EOL) ){
processEOT();
page_enter_status = 0;
}
saveon_flag = true;
return RET_CONTINUE;
}
int ONScripter::tateyokoCommand()
{
sentence_font.setTateyokoMode( script_h.readInt() );
return RET_CONTINUE;
}
int ONScripter::talCommand()
{
leaveTextDisplayMode();
char loc = script_h.readLabel()[0];
int no = -1, trans = 0;
if ( loc == 'l' ) no = 0;
else if ( loc == 'c' ) no = 1;
else if ( loc == 'r' ) no = 2;
if (no >= 0)
trans = script_h.readInt();
if (no >= 0){
tachi_info[ no ].trans = trans;
dirty_rect.add( tachi_info[ no ].pos );
}
EffectLink *el = parseEffect(true);
if (setEffect(el)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripter::tablegotoCommand()
{
int count = 0;
int no = script_h.readInt();
while( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
const char *buf = script_h.readStr();
if ( count++ == no ){
setCurrentLabel( buf+1 );
break;
}
}
return RET_CONTINUE;
}
int ONScripter::systemcallCommand()
{
system_menu_mode = getSystemCallNo( script_h.readLabel() );
executeSystemCall();
return RET_CONTINUE;
}
int ONScripter::strspCommand()
{
leaveTextDisplayMode();
bool v = true;
if ( script_h.isName( "strsph" ) ) v = false;
int sprite_no = script_h.readInt();
AnimationInfo *ai = &sprite_info[sprite_no];
ai->font_size_xy[0] = -1;
if (ai->image_surface && ai->visible)
dirty_rect.add( ai->pos );
ai->removeTag();
setStr(&ai->file_name, script_h.readStr());
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
FontInfo fi;
fi.enc = &script_h.enc;
fi.is_newline_accepted = true;
fi.num_xy[0] = script_h.readInt();
fi.num_xy[1] = script_h.readInt();
fi.font_size_xy[0] = script_h.readInt();
fi.font_size_xy[1] = script_h.readInt();
fi.pitch_xy[0] = script_h.readInt() + fi.font_size_xy[0];
fi.pitch_xy[1] = script_h.readInt() + fi.font_size_xy[1];
fi.is_bold = script_h.readInt()?true:false;
fi.is_shadow = script_h.readInt()?true:false;
char *buffer = script_h.getNext();
while(script_h.getEndStatus() & ScriptHandler::END_COMMA){
ai->num_of_cells++;
script_h.readStr();
}
if (ai->num_of_cells == 0){
ai->num_of_cells = 1;
ai->color_list = new uchar3[ai->num_of_cells];
ai->color_list[0][0] = ai->color_list[0][1] = ai->color_list[0][2] = 0xff;
}
else{
ai->color_list = new uchar3[ai->num_of_cells];
script_h.setCurrent(buffer);
for (int i=0 ; i<ai->num_of_cells ; i++)
readColor(&ai->color_list[i], script_h.readStr());
}
ai->trans_mode = AnimationInfo::TRANS_STRING;
ai->trans = -1;
ai->visible = v;
ai->is_single_line = false;
ai->is_tight_region = false;
ai->is_ruby_drawable = sentence_font.rubyon_flag;
setupAnimationInfo(ai, &fi);
if ( ai->visible ) dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripter::stopCommand()
{
mp3stopCommand();
wavestopCommand();
return RET_CONTINUE;
}
int ONScripter::sp_rgb_gradationCommand()
{
int no = script_h.readInt();
int upper_r = script_h.readInt();
int upper_g = script_h.readInt();
int upper_b = script_h.readInt();
int lower_r = script_h.readInt();
int lower_g = script_h.readInt();
int lower_b = script_h.readInt();
ONSBuf key_r = script_h.readInt();
ONSBuf key_g = script_h.readInt();
ONSBuf key_b = script_h.readInt();
Uint32 alpha = script_h.readInt();
AnimationInfo *ai;
if (no == -1) ai = &sentence_font_info;
else ai = &sprite_info[no];
SDL_Surface *surface = ai->image_surface;
if (surface == NULL) return RET_CONTINUE;
SDL_PixelFormat *fmt = surface->format;
ONSBuf key_mask = (((key_r >> fmt->Rloss) << fmt->Rshift) |
((key_g >> fmt->Gloss) << fmt->Gshift) |
((key_b >> fmt->Bloss) << fmt->Bshift));
ONSBuf rgb_mask = fmt->Rmask | fmt->Gmask | fmt->Bmask;
SDL_LockSurface(surface);
// check upper and lower bound
int i, j;
int upper_bound=0, lower_bound=0;
bool is_key_found = false;
for (i=0 ; i<surface->h ; i++){
ONSBuf *buf = (ONSBuf *)surface->pixels + surface->w * i;
for (j=0 ; j<surface->w ; j++, buf++){
if ((*buf & rgb_mask) == key_mask){
if (is_key_found == false){
is_key_found = true;
upper_bound = lower_bound = i;
}
else{
lower_bound = i;
}
break;
}
}
}
// replace pixels of the key-color with the specified color in gradation
for (i=upper_bound ; i<=lower_bound ; i++){
ONSBuf *buf = (ONSBuf *)surface->pixels + surface->w * i;
#if defined(BPP16)
unsigned char *alphap = ai->alpha_buf + surface->w * i;
#else
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
unsigned char *alphap = (unsigned char *)buf + 3;
#else
unsigned char *alphap = (unsigned char *)buf;
#endif
#endif
Uint32 color = alpha << surface->format->Ashift;
if (upper_bound != lower_bound){
color |= (((lower_r - upper_r) * (i-upper_bound) / (lower_bound - upper_bound) + upper_r) >> fmt->Rloss) << fmt->Rshift;
color |= (((lower_g - upper_g) * (i-upper_bound) / (lower_bound - upper_bound) + upper_g) >> fmt->Gloss) << fmt->Gshift;
color |= (((lower_b - upper_b) * (i-upper_bound) / (lower_bound - upper_bound) + upper_b) >> fmt->Bloss) << fmt->Bshift;
}
else{
color |= (upper_r >> fmt->Rloss) << fmt->Rshift;
color |= (upper_g >> fmt->Gloss) << fmt->Gshift;
color |= (upper_b >> fmt->Bloss) << fmt->Bshift;
}
for (j=0 ; j<surface->w ; j++, buf++){
if ((*buf & rgb_mask) == key_mask){
*buf = color;
*alphap = alpha;
}
#if defined(BPP16)
alphap++;
#else
alphap += 4;
#endif
}
}
SDL_UnlockSurface(surface);
if ( ai->visible )
dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripter::spstrCommand()
{
decodeExbtnControl( script_h.readStr() );
return RET_CONTINUE;
}
int ONScripter::spreloadCommand()
{
int no = script_h.readInt();
AnimationInfo *ai;
if (no == -1) ai = &sentence_font_info;
else ai = &sprite_info[no];
parseTaggedString( ai );
setupAnimationInfo( ai );
if ( ai->visible )
dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripter::splitCommand()
{
script_h.readStr();
const char *save_buf = script_h.saveStringBuffer();
char delimiter = script_h.readStr()[0];
char token256[256], *token=NULL;
while( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
unsigned int c=0;
while(save_buf[c] != delimiter && save_buf[c] != '\0')
c += script_h.enc.getBytes(save_buf[c]);
if (c < 256)
token = token256;
else
token = new char[c+1];
memcpy( token, save_buf, c );
token[c] = '\0';
script_h.readVariable();
if ( script_h.current_variable.type & ScriptHandler::VAR_INT ||
script_h.current_variable.type & ScriptHandler::VAR_ARRAY ){
script_h.setInt( &script_h.current_variable, atoi(token) );
}
else if ( script_h.current_variable.type & ScriptHandler::VAR_STR ){
setStr( &script_h.getVariableData(script_h.current_variable.var_no).str, token );
}
if (c >= 256) delete[] token;
save_buf += c;
if (save_buf[0] != '\0') save_buf++;
}
return RET_CONTINUE;
}
int ONScripter::spclclkCommand()
{
if ( !force_button_shortcut_flag )
spclclk_flag = true;
return RET_CONTINUE;
}
int ONScripter::spbtnCommand()
{
bool cellcheck_flag = false;
if ( script_h.isName( "cellcheckspbtn" ) )
cellcheck_flag = true;
int sprite_no = script_h.readInt();
int no = script_h.readInt();
if (no < 1 ||
sprite_no < 0 ||
sprite_no >= MAX_SPRITE_NUM ||
sprite_info[sprite_no].image_surface == NULL)
return RET_CONTINUE;
if ( cellcheck_flag ){
if ( sprite_info[ sprite_no ].num_of_cells < 2 ) return RET_CONTINUE;
}
else{
if ( sprite_info[ sprite_no ].num_of_cells == 0 ) return RET_CONTINUE;
}
ButtonLink *button = new ButtonLink();
root_button_link.insert( button );
button->button_type = ButtonLink::SPRITE_BUTTON;
button->sprite_no = sprite_no;
button->no = no;
if ( sprite_info[ sprite_no ].image_surface ||
sprite_info[ sprite_no ].trans_mode == AnimationInfo::TRANS_STRING )
button->image_rect = button->select_rect = sprite_info[ sprite_no ].pos;
return RET_CONTINUE;
}
int ONScripter::skipoffCommand()
{
skip_mode &= ~SKIP_NORMAL;
return RET_CONTINUE;
}
int ONScripter::showlangjpCommand()
{
script_h.current_language = 1;
text_info.fill( 0, 0, 0, 0 );
flush(refreshMode(), &sentence_font_info.pos);
return RET_CONTINUE;
}
int ONScripter::showlangenCommand()
{
script_h.current_language = 0;
text_info.fill( 0, 0, 0, 0 );
flush(refreshMode(), &sentence_font_info.pos);
return RET_CONTINUE;
}
int ONScripter::sevolCommand()
{
se_volume = script_h.readInt();
for ( int i=1 ; i<ONS_MIX_CHANNELS ; i++ )
if ( wave_sample[i] ) Mix_Volume( i, se_volume * MIX_MAX_VOLUME / 100 );
if ( wave_sample[MIX_LOOPBGM_CHANNEL0] ) Mix_Volume( MIX_LOOPBGM_CHANNEL0, se_volume * MIX_MAX_VOLUME / 100 );
if ( wave_sample[MIX_LOOPBGM_CHANNEL1] ) Mix_Volume( MIX_LOOPBGM_CHANNEL1, se_volume * MIX_MAX_VOLUME / 100 );
return RET_CONTINUE;
}
void ONScripter::setwindowCore()
{
sentence_font.ttf_font[0] = NULL;
sentence_font.ttf_font[1] = NULL;
sentence_font.top_xy[0] = script_h.readInt();
sentence_font.top_xy[1] = script_h.readInt();
sentence_font.num_xy[0] = script_h.readInt();
sentence_font.num_xy[1] = script_h.readInt();
sentence_font.font_size_xy[0] = script_h.readInt();
sentence_font.font_size_xy[1] = script_h.readInt();
sentence_font.pitch_xy[0] = script_h.readInt() + sentence_font.font_size_xy[0];
sentence_font.pitch_xy[1] = script_h.readInt() + sentence_font.font_size_xy[1];
sentence_font.wait_time = script_h.readInt();
sentence_font.is_bold = script_h.readInt()?true:false;
sentence_font.is_shadow = script_h.readInt()?true:false;
const char *buf = script_h.readStr();
dirty_rect.add( sentence_font_info.pos );
AnimationInfo *ai = &sentence_font_info;
if ( buf[0] == '#' ){
sentence_font.is_transparent = true;
readColor( &sentence_font.window_color, buf );
ai->remove();
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->orig_pos.w = script_h.readInt() - ai->orig_pos.x + 1;
ai->orig_pos.h = script_h.readInt() - ai->orig_pos.y + 1;
ai->scalePosXY( screen_ratio1, screen_ratio2 );
ai->scalePosWH( screen_ratio1, screen_ratio2 );
}
else{
if (buf[0] != 0){
ai->setImageName(buf);
parseTaggedString(ai);
setupAnimationInfo(ai);
}
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
if (script_h.getEndStatus() & ScriptHandler::END_COMMA)
script_h.readInt();
if (script_h.getEndStatus() & ScriptHandler::END_COMMA)
script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
sentence_font.is_transparent = false;
sentence_font.window_color[0] = sentence_font.window_color[1] = sentence_font.window_color[2] = 0xff;
}
sentence_font.old_xy[0] = sentence_font.x(false);
sentence_font.old_xy[1] = sentence_font.y(false);
}
int ONScripter::setwindow3Command()
{
setwindowCore();
clearCurrentPage();
indent_offset = 0;
line_enter_status = 0;
page_enter_status = 0;
display_mode = DISPLAY_MODE_NORMAL;
flush( refreshMode(), &sentence_font_info.pos );
return RET_CONTINUE;
}
int ONScripter::setwindow2Command()
{
const char *buf = script_h.readStr();
if ( buf[0] == '#' ){
sentence_font.is_transparent = true;
readColor( &sentence_font.window_color, buf );
sentence_font_info.remove();
}
else{
sentence_font.is_transparent = false;
sentence_font_info.setImageName( buf );
parseTaggedString( &sentence_font_info );
setupAnimationInfo( &sentence_font_info );
}
repaintCommand();
return RET_CONTINUE;
}
int ONScripter::setwindowCommand()
{
setwindowCore();
lookbackflushCommand();
indent_offset = 0;
line_enter_status = 0;
page_enter_status = 0;
display_mode = DISPLAY_MODE_NORMAL;
flush( refreshMode(), &sentence_font_info.pos );
return RET_CONTINUE;
}
int ONScripter::setcursorCommand()
{
bool abs_flag;
if ( script_h.isName( "abssetcursor" ) ){
abs_flag = true;
}
else{
abs_flag = false;
}
int no = script_h.readInt();
script_h.readStr();
const char* buf = script_h.saveStringBuffer();
int x = script_h.readInt();
int y = script_h.readInt();
loadCursor( no, buf, x, y, abs_flag );
return RET_CONTINUE;
}
int ONScripter::selectCommand()
{
enterTextDisplayMode();
int select_mode = SELECT_GOTO_MODE;
SelectLink *last_select_link;
if ( script_h.isName( "selnum" ) )
select_mode = SELECT_NUM_MODE;
else if ( script_h.isName( "selgosub" ) )
select_mode = SELECT_GOSUB_MODE;
else if ( script_h.isName( "select" ) )
select_mode = SELECT_GOTO_MODE;
else if ( script_h.isName( "csel" ) )
select_mode = SELECT_CSEL_MODE;
if ( select_mode == SELECT_NUM_MODE ){
script_h.readVariable();
script_h.pushVariable();
}
bool comma_flag = true;
if ( select_mode == SELECT_CSEL_MODE ){
if (saveon_flag && internal_saveon_flag) storeSaveFile();
saveon_flag = false;
}
shortcut_mouse_line = -1;
int xy[2];
xy[0] = sentence_font.xy[0];
xy[1] = sentence_font.xy[1];
if ( selectvoice_file_name[SELECTVOICE_OPEN] )
playSound(selectvoice_file_name[SELECTVOICE_OPEN],
SOUND_CHUNK, false, MIX_WAVE_CHANNEL );
last_select_link = &root_select_link;
while(1){
if ( script_h.getNext()[0] != 0x0a && comma_flag == true ){
const char *buf = script_h.readStr();
comma_flag = (script_h.getEndStatus() & ScriptHandler::END_COMMA);
if ( select_mode != SELECT_NUM_MODE && !comma_flag )
errorAndExit( "select: missing comma." );
// Text part
SelectLink *slink = new SelectLink();
setStr( &slink->text, buf );
//printf("Select text %s\n", slink->text);
// Label part
if (select_mode != SELECT_NUM_MODE){
script_h.readStr();
setStr( &slink->label, script_h.getStringBuffer()+1 );
//printf("Select label %s\n", slink->label );
}
last_select_link->next = slink;
last_select_link = last_select_link->next;
comma_flag = (script_h.getEndStatus() & ScriptHandler::END_COMMA);
//printf("2 comma %d %c %x\n", comma_flag, script_h.getCurrent()[0], script_h.getCurrent()[0]);
}
else if (script_h.getNext()[0] == 0x0a){
//printf("comma %d\n", comma_flag);
char *buf = script_h.getNext() + 1; // consume eol
while ( *buf == ' ' || *buf == '\t' ) buf++;
if (comma_flag && *buf == ',')
errorAndExit( "select: double comma." );
bool comma2_flag = false;
if (*buf == ','){
comma2_flag = true;
buf++;
while ( *buf == ' ' || *buf == '\t' ) buf++;
}
script_h.setCurrent(buf);
if (*buf == 0x0a){
comma_flag |= comma2_flag;
continue;
}
if (!comma_flag && !comma2_flag){
select_label_info.next_script = buf;
//printf("select: stop at the end of line\n");
break;
}
//printf("continue\n");
comma_flag = true;
}
else{ // if select ends at the middle of the line
select_label_info.next_script = script_h.getNext();
//printf("select: stop at the middle of the line\n");
break;
}
}
if ( select_mode != SELECT_CSEL_MODE ){
last_select_link = root_select_link.next;
int counter = 1;
while( last_select_link ){
if ( *last_select_link->text ){
ButtonLink *button = getSelectableSentence( last_select_link->text, &sentence_font );
root_button_link.insert( button );
button->no = counter;
}
counter++;
last_select_link = last_select_link->next;
}
}
if ( select_mode == SELECT_CSEL_MODE ){
setCurrentLabel( "customsel" );
return RET_CONTINUE;
}
automode_flag = false;
sentence_font.xy[0] = xy[0];
sentence_font.xy[1] = xy[1];
flush( refreshMode() );
refreshMouseOverButton();
event_mode = WAIT_TEXT_MODE | WAIT_BUTTON_MODE | WAIT_TIMER_MODE;
do{
skip_mode &= ~SKIP_NORMAL;
if (waitEvent(-1)) return RET_CONTINUE;
}
while(current_button_state.button <= 0 || skip_mode & SKIP_NORMAL);
if ( selectvoice_file_name[SELECTVOICE_SELECT] )
playSound(selectvoice_file_name[SELECTVOICE_SELECT],
SOUND_CHUNK, false, MIX_WAVE_CHANNEL );
deleteButtonLink();
int counter = 1;
last_select_link = root_select_link.next;
while ( last_select_link ){
if ( current_button_state.button == counter++ ) break;
last_select_link = last_select_link->next;
}
if ( select_mode == SELECT_GOTO_MODE ){
setCurrentLabel( last_select_link->label );
}
else if ( select_mode == SELECT_GOSUB_MODE ){
gosubReal( last_select_link->label, select_label_info.next_script );
}
else{ // selnum
script_h.setInt( &script_h.pushed_variable, current_button_state.button - 1 );
current_label_info = script_h.getLabelByAddress( select_label_info.next_script );
current_line = script_h.getLineByAddress( select_label_info.next_script );
script_h.setCurrent( select_label_info.next_script );
}
deleteSelectLink();
newPage();
return RET_CONTINUE;
}
int ONScripter::savetimeCommand()
{
int no = script_h.readInt();
SaveFileInfo info;
searchSaveFile( info, no );
script_h.readVariable();
if ( !info.valid ){
script_h.setInt( &script_h.current_variable, 0 );
for ( int i=0 ; i<3 ; i++ )
script_h.readVariable();
return RET_CONTINUE;
}
script_h.setInt( &script_h.current_variable, info.month );
script_h.readInt();
script_h.setInt( &script_h.current_variable, info.day );
script_h.readInt();
script_h.setInt( &script_h.current_variable, info.hour );
script_h.readInt();
script_h.setInt( &script_h.current_variable, info.minute );
return RET_CONTINUE;
}
int ONScripter::savescreenshotCommand()
{
if ( script_h.isName( "savescreenshot" ) ){
}
else if ( script_h.isName( "savescreenshot2" ) ){
}
SDL_Surface *surface = AnimationInfo::alloc32bitSurface( screenshot_w, screenshot_h, texture_format );
resizeSurface( screenshot_surface, surface );
const char *buf = script_h.readStr();
if (script_h.enc.getEncoding() == Encoding::CODE_UTF8){
char *dir = new char[strlen(archive_path) + strlen(buf) + 1];
sprintf(dir, "%s%s", archive_path, buf);
for (int i=strlen(dir)-1; i>=0; i--){
if (dir[i] == '/' || dir[i] == '\\'){
dir[i] = 0;
#if defined(LINUX) || defined(MACOSX) || defined(IOS)
mkdir(dir, 0755);
#elif defined(WIN32)
_mkdir(dir);
#endif
break;
}
}
delete[] dir;
}
FILE *fp = fopen(buf, "wb");
if (fp){
SDL_RWops *rwops = SDL_RWFromFP(fp, SDL_TRUE);
SDL_SaveBMP_RW(surface, rwops, 1);
}
SDL_FreeSurface(surface);
return RET_CONTINUE;
}
int ONScripter::savepointCommand()
{
storeSaveFile();
return RET_CONTINUE;
}
int ONScripter::saveonCommand()
{
if (!autosaveoff_flag)
saveon_flag = true;
return RET_CONTINUE;
}
int ONScripter::saveoffCommand()
{
if (!autosaveoff_flag){
if (saveon_flag && internal_saveon_flag) storeSaveFile();
saveon_flag = false;
}
return RET_CONTINUE;
}
int ONScripter::savegameCommand()
{
bool savegame2_flag = false;
if ( script_h.isName( "savegame2" ) )
savegame2_flag = true;
int no = script_h.readInt();
const char* savestr = NULL;
if (savegame2_flag)
savestr = script_h.readStr();
if (saveon_flag && internal_saveon_flag) storeSaveFile();
writeSaveFile( no, savestr );
return RET_CONTINUE;
}
int ONScripter::savefileexistCommand()
{
script_h.readInt();
script_h.pushVariable();
int no = script_h.readInt();
SaveFileInfo info;
searchSaveFile( info, no );
script_h.setInt( &script_h.pushed_variable, (info.valid==true)?1:0 );
return RET_CONTINUE;
}
int ONScripter::rndCommand()
{
int upper, lower;
if ( script_h.isName( "rnd2" ) ){
script_h.readInt();
script_h.pushVariable();
lower = script_h.readInt();
upper = script_h.readInt();
}
else{
script_h.readInt();
script_h.pushVariable();
lower = 0;
upper = script_h.readInt() - 1;
}
script_h.setInt( &script_h.pushed_variable, lower + (int)( (double)(upper-lower+1)*rand()/(RAND_MAX+1.0)) );
return RET_CONTINUE;
}
int ONScripter::rmodeCommand()
{
if ( script_h.readInt() == 1 ) rmode_flag = true;
else rmode_flag = false;
return RET_CONTINUE;
}
int ONScripter::resettimerCommand()
{
internal_timer = SDL_GetTicks();
return RET_CONTINUE;
}
int ONScripter::resetCommand()
{
int fadeout = mp3fadeout_duration;
mp3fadeout_duration = 0; //don't use fadeout during a reset
resetSub();
mp3fadeout_duration = fadeout;
start_page = current_page = &page_list[0];
clearCurrentPage();
flush( refreshMode(), &sentence_font_info.pos );
/* Initialize local variables */
for (int i=0 ; i<script_h.global_variable_border ; i++)
script_h.getVariableData(i).reset(false);
setCurrentLabel( "start" );
storeSaveFile();
return RET_CONTINUE;
}
int ONScripter::repaintCommand()
{
dirty_rect.fill( screen_width, screen_height );
flush( refreshMode() );
return RET_CONTINUE;
}
int ONScripter::quakeCommand()
{
int quake_type;
if ( script_h.isName( "quakey" ) ){
quake_type = 0;
}
else if ( script_h.isName( "quakex" ) ){
quake_type = 1;
}
else{
quake_type = 2;
}
tmp_effect.no = script_h.readInt();
tmp_effect.duration = script_h.readInt();
if ( tmp_effect.duration < tmp_effect.no * 4 ) tmp_effect.duration = tmp_effect.no * 4;
tmp_effect.effect = MAX_EFFECT_NUM + quake_type;
dirty_rect.fill( screen_width, screen_height );
SDL_BlitSurface( accumulation_surface, NULL, effect_dst_surface, NULL );
if (setEffect(&tmp_effect)) return RET_CONTINUE;
while (doEffect(&tmp_effect));
return RET_CONTINUE;
}
int ONScripter::puttextCommand()
{
enterTextDisplayMode(false);
script_h.readStr();
string_buffer_offset = 0;
if (script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR)
string_buffer_offset = 1; // skip the heading `
int s = line_enter_status;
while(processText());
line_enter_status = s;
return RET_CONTINUE;
}
int ONScripter::prnumclearCommand()
{
for ( int i=0 ; i<MAX_PARAM_NUM ; i++ ) {
if ( prnum_info[i] ) {
dirty_rect.add( prnum_info[i]->pos );
delete prnum_info[i];
prnum_info[i] = NULL;
}
}
return RET_CONTINUE;
}
int ONScripter::prnumCommand()
{
leaveTextDisplayMode();
int no = script_h.readInt();
if (no < 0 || no >= MAX_PARAM_NUM){
script_h.readInt();
script_h.readInt();
script_h.readInt();
script_h.readInt();
script_h.readInt();
script_h.readStr();
return RET_CONTINUE;
}
if ( prnum_info[no] ){
dirty_rect.add( prnum_info[no]->pos );
delete prnum_info[no];
}
AnimationInfo *ai = prnum_info[no] = new AnimationInfo();
ai->trans_mode = AnimationInfo::TRANS_STRING;
ai->num_of_cells = 1;
ai->setCell(0);
ai->color_list = new uchar3[ ai->num_of_cells ];
ai->param = script_h.readInt();
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
ai->font_size_xy[0] = script_h.readInt();
ai->font_size_xy[1] = script_h.readInt();
ai->font_pitch[0] = ai->font_size_xy[0];
ai->font_pitch[1] = ai->font_size_xy[1];
const char *buf = script_h.readStr();
readColor( &ai->color_list[0], buf );
char num_buf[7];
script_h.getStringFromInteger( num_buf, ai->param, 3 );
setStr( &ai->file_name, num_buf );
setupAnimationInfo( ai );
dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripter::printCommand()
{
leaveTextDisplayMode();
EffectLink *el = parseEffect(true);
if (setEffect(el)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripter::playstopCommand()
{
stopBGM( false );
return RET_CONTINUE;
}
int ONScripter::playCommand()
{
bool loop_flag = true;
if ( script_h.isName( "playonce" ) )
loop_flag = false;
const char *buf = script_h.readStr();
if ( buf[0] == '*' ){
cd_play_loop_flag = loop_flag;
int new_cd_track = atoi( buf + 1 );
#ifdef CONTINUOUS_PLAY
if ( current_cd_track != new_cd_track ) {
#endif
stopBGM( false );
current_cd_track = new_cd_track;
playCDAudio();
#ifdef CONTINUOUS_PLAY
}
#endif
}
else{ // play MIDI
stopBGM( false );
setStr(&midi_file_name, buf);
midi_play_loop_flag = loop_flag;
if (playSound(midi_file_name, SOUND_MIDI, midi_play_loop_flag) != SOUND_MIDI){
fprintf(stderr, "can't play MIDI file %s\n", midi_file_name);
}
}
return RET_CONTINUE;
}
int ONScripter::ofscopyCommand()
{
#ifdef USE_SDL_RENDERER
SDL_Surface *tmp_surface = AnimationInfo::alloc32bitSurface( screen_device_width, screen_device_height, texture_format );
SDL_Rect rect = {(device_width -screen_device_width)/2,
(device_height-screen_device_height)/2,
screen_device_width, screen_device_height};
SDL_LockSurface(tmp_surface);
SDL_RenderReadPixels(renderer, &rect, tmp_surface->format->format, tmp_surface->pixels, tmp_surface->pitch);
SDL_UnlockSurface(tmp_surface);
resizeSurface( tmp_surface, accumulation_surface );
SDL_FreeSurface(tmp_surface);
#else
SDL_BlitSurface(screen_surface, NULL, accumulation_surface, NULL);
#endif
return RET_CONTINUE;
}
int ONScripter::negaCommand()
{
nega_mode = script_h.readInt();
dirty_rect.fill( screen_width, screen_height );
return RET_CONTINUE;
}
int ONScripter::nextcselCommand()
{
script_h.readInt();
if (last_nest_info != &root_nest_info &&
last_nest_info->nest_mode == NestInfo::LABEL){
char *buf = last_nest_info->next_script;
while (*buf == ' ' || *buf == '\t' || *buf == 0x0a) buf++;
if (strncmp( buf, "csel", 4) == 0)
script_h.setInt( &script_h.current_variable, 1 );
else
script_h.setInt( &script_h.current_variable, 0 );
}
else
script_h.setInt( &script_h.current_variable, 0 );
return RET_CONTINUE;
}
int ONScripter::mspCommand()
{
leaveTextDisplayMode();
bool msp2_flag = false;
if (script_h.isName("msp2")) msp2_flag = true;
int no = script_h.readInt();
AnimationInfo *ai = NULL;
if (msp2_flag) {
ai = &sprite2_info[no];
dirty_rect.add( ai->bounding_rect );
}
else{
ai = &sprite_info[no];
dirty_rect.add( ai->pos );
}
ai->orig_pos.x += script_h.readInt();
ai->orig_pos.y += script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
if (msp2_flag){
ai->scale_x += script_h.readInt();
ai->scale_y += script_h.readInt();
ai->rot += script_h.readInt();
ai->calcAffineMatrix();
dirty_rect.add( ai->bounding_rect );
}
else{
dirty_rect.add( ai->pos );
}
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
if (ai->trans == -1)
ai->trans = 255 + script_h.readInt();
else
ai->trans += script_h.readInt();
if (ai->trans < 0) ai->trans = 0;
else if (ai->trans > 255) ai->trans = 255;
}
return RET_CONTINUE;
}
int ONScripter::mpegplayCommand()
{
script_h.readStr();
const char *save_buf = script_h.saveStringBuffer();
bool click_flag = (script_h.readInt()==1)?true:false;
stopBGM( false );
if (playMPEG( save_buf, click_flag )) endCommand();
repaintCommand();
return RET_CONTINUE;
}
int ONScripter::mp3volCommand()
{
music_volume = script_h.readInt();
Mix_VolumeMusic( music_volume * MIX_MAX_VOLUME / 100 );
return RET_CONTINUE;
}
int ONScripter::mp3stopCommand()
{
if (Mix_PlayingMusic() == 1 && timer_bgmfade_id && mp3fadeout_duration_internal > 0) // already in fadeout
return RET_CONTINUE;
if (Mix_PlayingMusic() == 1 && mp3fadeout_duration > 0){
// do a bgm fadeout
Mix_HookMusicFinished( NULL );
mp3fadeout_duration_internal = mp3fadeout_duration;
mp3fade_start = SDL_GetTicks();
timer_bgmfade_id = SDL_AddTimer(20, bgmfadeCallback, 0);
setStr(&fadeout_music_file_name, music_file_name);
char *ext = NULL;
if (music_file_name) ext = strrchr(music_file_name, '.');
if (ext && (!strcmp(ext+1, "OGG") || !strcmp(ext+1, "ogg"))){
// do not wait until fadout is finished when playing ogg
event_mode = IDLE_EVENT_MODE;
waitEvent(0);
setStr( &music_file_name, NULL ); // to ensure not to play music during fadeout
return RET_CONTINUE;
}
else{
// wait until fadout is finished when playing music other than ogg
event_mode = WAIT_TIMER_MODE;
waitEvent(-1);
}
}
stopBGM( false );
return RET_CONTINUE;
}
int ONScripter::mp3fadeoutCommand()
{
mp3fadeout_duration = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::mp3fadeinCommand()
{
mp3fadein_duration = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::mp3Command()
{
bool loop_flag = false;
if ( script_h.isName( "mp3save" ) ){
mp3save_flag = true;
}
else if ( script_h.isName( "bgmonce" ) ){
mp3save_flag = false;
}
else if ( script_h.isName( "mp3loop" ) ||
script_h.isName( "bgm" ) ){
mp3save_flag = true;
loop_flag = true;
}
else{
mp3save_flag = false;
}
mp3stopCommand();
stopBGM( false );
music_play_loop_flag = loop_flag;
music_loopback_offset = 0.0;
const char *buf = script_h.readStr();
if (buf[0] != '\0'){
if (buf[0]=='('){
buf++;
bool integer_flag = true;
double decimal = 0.1;
while (*buf != ')' && *buf != '\0'){
if (*buf >= '0' && *buf <= '9'){
if (integer_flag)
music_loopback_offset = music_loopback_offset*10.0 + *buf - '0';
else{
music_loopback_offset += decimal*(*buf - '0');
decimal *= 0.1;
}
}
else if (*buf == '.')
integer_flag = false;
buf++;
}
if (*buf == ')') buf++;
}
int tmp = music_volume;
setStr(&music_file_name, buf);
if (mp3fadein_duration > 0)
music_volume = 0;
playSound(music_file_name,
SOUND_MUSIC | SOUND_MIDI | SOUND_CHUNK,
music_play_loop_flag, MIX_BGM_CHANNEL);
music_volume = tmp;
if (mp3fadein_duration > 0) {
// do a bgm fadein
mp3fadein_duration_internal = mp3fadein_duration;
mp3fade_start = SDL_GetTicks();
timer_bgmfade_id = SDL_AddTimer(20, bgmfadeCallback,
(void*)&timer_bgmfade_id);
char *ext = NULL;
if (music_file_name) ext = strrchr(music_file_name, '.');
if (ext && (!strcmp(ext+1, "OGG") || !strcmp(ext+1, "ogg"))){
// do not wait until fadin is finished when playing ogg
event_mode = IDLE_EVENT_MODE;
waitEvent(0);
}
else{
// wait until fadin is finished when playing music other than ogg
event_mode = WAIT_TIMER_MODE;
waitEvent(-1);
}
}
}
return RET_CONTINUE;
}
int ONScripter::movieCommand()
{
if (script_h.compareString("stop")){
script_h.readLabel();
fprintf(stderr, " [movie stop] is not supported yet!!\n");
return RET_CONTINUE;
}
script_h.readStr();
const char *filename = script_h.saveStringBuffer();
bool click_flag = false;
bool loop_flag = false;
bool nosound_flag = false;
while (script_h.getEndStatus() & ScriptHandler::END_COMMA){
if (script_h.compareString("pos")){ // not supported yet
script_h.readLabel();
script_h.readInt();
script_h.readInt();
script_h.readInt();
script_h.readInt();
fprintf(stderr, " [movie pos] is not supported yet!!\n");
}
else if (script_h.compareString("click")){
script_h.readLabel();
click_flag = true;
}
else if (script_h.compareString("loop")){
script_h.readLabel();
loop_flag = true;
}
else if (script_h.compareString("async")){ // not supported yet
script_h.readLabel();
fprintf(stderr, " [movie async] is not supported yet!!\n");
}
else if (script_h.compareString("nosound")){
script_h.readLabel();
nosound_flag = true;
}
else{
script_h.readLabel();
}
}
if (!nosound_flag) stopBGM(false);
if (playMPEG(filename, click_flag, loop_flag, nosound_flag)) endCommand();
return RET_CONTINUE;
}
int ONScripter::movemousecursorCommand()
{
int x = script_h.readInt() * screen_ratio1 / screen_ratio2;
int y = script_h.readInt() * screen_ratio1 / screen_ratio2;
x = x * screen_device_width / screen_width;
y = y * screen_device_width / screen_width;
SDL_WarpMouse(x, y);
return RET_CONTINUE;
}
int ONScripter::monocroCommand()
{
if ( script_h.compareString( "off" ) ){
script_h.readLabel();
monocro_flag = false;
}
else{
monocro_flag = true;
readColor( &monocro_color, script_h.readStr() );
for (int i=0 ; i<256 ; i++){
monocro_color_lut[i][0] = (monocro_color[0] * i) >> 8;
monocro_color_lut[i][1] = (monocro_color[1] * i) >> 8;
monocro_color_lut[i][2] = (monocro_color[2] * i) >> 8;
}
}
dirty_rect.fill( screen_width, screen_height );
return RET_CONTINUE;
}
int ONScripter::menu_windowCommand()
{
if ( fullscreen_mode ){
#if !defined(PSP)
if ( !SDL_WM_ToggleFullScreen( screen_surface ) ){
screen_surface = SDL_SetVideoMode( screen_device_width, screen_device_height, screen_bpp, DEFAULT_VIDEO_SURFACE_FLAG );
#ifdef ANDROID
SDL_SetSurfaceBlendMode(screen_surface, SDL_BLENDMODE_NONE);
#endif
flushDirect( screen_rect, refreshMode() );
}
#endif
fullscreen_mode = false;
}
return RET_CONTINUE;
}
int ONScripter::menu_fullCommand()
{
if ( !fullscreen_mode ){
#if !defined(PSP)
if ( !SDL_WM_ToggleFullScreen( screen_surface ) ){
screen_surface = SDL_SetVideoMode( screen_device_width, screen_device_height, screen_bpp, DEFAULT_VIDEO_SURFACE_FLAG|SDL_FULLSCREEN );
#ifdef ANDROID
SDL_SetSurfaceBlendMode(screen_surface, SDL_BLENDMODE_NONE);
#endif
flushDirect( screen_rect, refreshMode() );
}
#endif
fullscreen_mode = true;
}
return RET_CONTINUE;
}
int ONScripter::menu_click_pageCommand()
{
skip_mode |= SKIP_TO_EOP;
return RET_CONTINUE;
}
int ONScripter::menu_click_defCommand()
{
skip_mode &= ~SKIP_TO_EOP;
return RET_CONTINUE;
}
int ONScripter::menu_automodeCommand()
{
automode_flag = true;
skip_mode &= ~SKIP_NORMAL;
printf("menu_automode: change to automode\n");
return RET_CONTINUE;
}
int ONScripter::lsp2Command()
{
leaveTextDisplayMode();
bool v=true;
if ( script_h.isName( "lsph2" ) ||
script_h.isName( "lsph2add" ) ||
script_h.isName( "lsph2sub" ))
v = false;
int blend_mode = AnimationInfo::BLEND_NORMAL;
if ( script_h.isName( "lsp2add" ) || script_h.isName( "lsph2add" ))
blend_mode = AnimationInfo::BLEND_ADD;
else if ( script_h.isName( "lsp2sub" ) || script_h.isName( "lsph2sub" ))
blend_mode = AnimationInfo::BLEND_SUB;
int no = script_h.readInt();
AnimationInfo *ai = &sprite2_info[no];
if (ai->image_surface && ai->visible)
dirty_rect.add( ai->bounding_rect );
ai->visible = v;
ai->blending_mode = blend_mode;
const char *buf = script_h.readStr();
ai->setImageName( buf );
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
ai->scale_x = script_h.readInt();
ai->scale_y = script_h.readInt();
ai->rot = script_h.readInt();
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
ai->trans = script_h.readInt();
else
ai->trans = -1;
parseTaggedString( ai );
setupAnimationInfo( ai );
ai->calcAffineMatrix();
if ( ai->visible )
dirty_rect.add( ai->bounding_rect );
return RET_CONTINUE;
}
int ONScripter::lspCommand()
{
leaveTextDisplayMode();
bool v=true;
if ( script_h.isName( "lsph" ) ) v = false;
int no = script_h.readInt();
AnimationInfo *ai = &sprite_info[no];
if (ai->image_surface && ai->visible)
dirty_rect.add( ai->pos );
ai->visible = v;
const char *buf = script_h.readStr();
if (buf[0] == '*'){ // layer
int layer_num=0, c=1;
while (buf[c] >= '0' && buf[c] <= '9')
layer_num = layer_num*10 + buf[c++] - '0';
LayerInfo *li = &layer_info[layer_num];
if (!li->str){
fprintf(stderr, " lsp: layer %d is not configured.\n", layer_num);
return RET_CONTINUE;
}
int w=1, h=1;
size_t len = strlen("wcmpg.dll");
if (strlen(li->str) >= len &&
strncmp(li->str+strlen(li->str)-len, "wcmpg.dll", len) == 0){
printf("lsp: %d wcmpg.dll is enabled.\n", no);
smpeg_info = ai;
w = screen_width;
h = screen_height;
}
li->sprite_num = no;
char filename[64];
sprintf(filename, ":a/1,%d,0;>%d,%d,#000000", li->duration, w, h);
ai->setImageName( filename );
ai->orig_pos.x = 0;
ai->orig_pos.y = 0;
ai->scalePosXY( screen_ratio1, screen_ratio2 );
ai->default_alpha = 0;
sprintf(filename, ":a;>%d,%d,#000000", w, h);
effect_src_info.setImageName( filename );
effect_src_info.orig_pos.x = 0;
effect_src_info.orig_pos.y = 0;
effect_src_info.scalePosXY( screen_ratio1, screen_ratio2 );
effect_src_info.blending_mode = AnimationInfo::BLEND_ADD2;
parseTaggedString( &effect_src_info );
setupAnimationInfo( &effect_src_info );
}
else{
ai->setImageName( buf );
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
ai->trans = script_h.readInt();
else
ai->trans = -1;
}
parseTaggedString( ai );
setupAnimationInfo( ai );
if ( ai->visible ) dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripter::loopbgmstopCommand()
{
if ( wave_sample[MIX_LOOPBGM_CHANNEL0] ){
Mix_Pause(MIX_LOOPBGM_CHANNEL0);
Mix_FreeChunk( wave_sample[MIX_LOOPBGM_CHANNEL0] );
wave_sample[MIX_LOOPBGM_CHANNEL0] = NULL;
}
if ( wave_sample[MIX_LOOPBGM_CHANNEL1] ){
Mix_Pause(MIX_LOOPBGM_CHANNEL1);
Mix_FreeChunk( wave_sample[MIX_LOOPBGM_CHANNEL1] );
wave_sample[MIX_LOOPBGM_CHANNEL1] = NULL;
}
setStr(&loop_bgm_name[0], NULL);
return RET_CONTINUE;
}
int ONScripter::loopbgmCommand()
{
const char *buf = script_h.readStr();
setStr( &loop_bgm_name[0], buf );
buf = script_h.readStr();
setStr( &loop_bgm_name[1], buf );
playSound(loop_bgm_name[1],
SOUND_PRELOAD|SOUND_CHUNK, false, MIX_LOOPBGM_CHANNEL1);
playSound(loop_bgm_name[0],
SOUND_CHUNK, false, MIX_LOOPBGM_CHANNEL0);
return RET_CONTINUE;
}
int ONScripter::lookbackflushCommand()
{
current_page = current_page->next;
for ( int i=0 ; i<max_page_list-1 ; i++ ){
current_page->text_count = 0;
current_page = current_page->next;
}
clearCurrentPage();
start_page = current_page;
return RET_CONTINUE;
}
int ONScripter::lookbackbuttonCommand()
{
for ( int i=0 ; i<4 ; i++ ){
const char *buf = script_h.readStr();
setStr( &lookback_info[i].image_name, buf );
parseTaggedString( &lookback_info[i] );
setupAnimationInfo( &lookback_info[i] );
}
return RET_CONTINUE;
}
int ONScripter::logspCommand()
{
leaveTextDisplayMode();
bool logsp2_flag = false;
if ( script_h.isName( "logsp2" ) )
logsp2_flag = true;
int no = script_h.readInt();
AnimationInfo *ai = &sprite_info[no];
if (ai->image_surface && ai->visible)
dirty_rect.add( ai->pos );
ai->remove();
setStr( &ai->file_name, script_h.readStr() );
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
ai->trans_mode = AnimationInfo::TRANS_STRING;
if (logsp2_flag){
ai->font_size_xy[0] = script_h.readInt();
ai->font_size_xy[1] = script_h.readInt();
ai->font_pitch[0] = script_h.readInt() + ai->font_size_xy[0];
ai->font_pitch[1] = script_h.readInt() + ai->font_size_xy[1];
}
else{
ai->font_size_xy[0] = sentence_font.font_size_xy[0];
ai->font_size_xy[1] = sentence_font.font_size_xy[1];
ai->font_pitch[0] = sentence_font.pitch_xy[0];
ai->font_pitch[1] = sentence_font.pitch_xy[1];
}
char *current = script_h.getNext();
int num = 0;
while(script_h.getEndStatus() & ScriptHandler::END_COMMA){
script_h.readStr();
num++;
}
script_h.setCurrent(current);
if (num == 0){
ai->num_of_cells = 1;
ai->color_list = new uchar3[ ai->num_of_cells ];
readColor( &ai->color_list[0], "#ffffff" );
}
else{
ai->num_of_cells = num;
ai->color_list = new uchar3[ ai->num_of_cells ];
for (int i=0 ; i<num ; i++){
readColor( &ai->color_list[i], script_h.readStr() );
}
}
ai->is_single_line = false;
ai->is_tight_region = false;
ai->is_ruby_drawable = sentence_font.rubyon_flag;
sentence_font.is_newline_accepted = true;
setupAnimationInfo( ai );
sentence_font.is_newline_accepted = false;
ai->visible = true;
dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripter::locateCommand()
{
int x = script_h.readInt();
int y = script_h.readInt();
sentence_font.setXY( x, y );
return RET_CONTINUE;
}
int ONScripter::loadgameCommand()
{
int no = script_h.readInt();
int fadeout = mp3fadeout_duration;
mp3fadeout_duration = 0; //don't use fadeout during a load
if ( !loadSaveFile( no ) ){
dirty_rect.fill( screen_width, screen_height );
flush( refreshMode() );
saveon_flag = true;
internal_saveon_flag = true;
skip_mode &= ~SKIP_NORMAL;
automode_flag = false;
deleteButtonLink();
deleteSelectLink();
text_on_flag = false;
indent_offset = 0;
line_enter_status = 0;
page_enter_status = 0;
string_buffer_offset = 0;
break_flag = false;
flushEvent();
#ifdef USE_LUA
if (lua_handler.isCallbackEnabled(LUAHandler::LUA_LOAD)){
if (lua_handler.callFunction(true, "load", &no))
errorAndExit( lua_handler.error_str );
}
#endif
if (loadgosub_label)
gosubReal( loadgosub_label, script_h.getCurrent() );
}
mp3fadeout_duration = fadeout;
return RET_CONTINUE;
}
int ONScripter::ldCommand()
{
leaveTextDisplayMode();
char loc = script_h.readLabel()[0];
int no = -1;
if (loc == 'l') no = 0;
else if (loc == 'c') no = 1;
else if (loc == 'r') no = 2;
const char *buf = NULL;
if (no >= 0) buf = script_h.readStr();
if (no >= 0){
AnimationInfo *ai = &tachi_info[no];
if (ai->image_surface) dirty_rect.add( ai->pos );
ai->setImageName( buf );
parseTaggedString( ai );
setupAnimationInfo( ai );
if ( ai->image_surface ){
ai->visible = true;
ai->orig_pos.x = screen_width * (no+1) * screen_ratio2 / (4 * screen_ratio1) - ai->orig_pos.w / 2;
ai->orig_pos.y = underline_value - ai->image_surface->h * screen_ratio2 / screen_ratio1;
ai->scalePosXY( screen_ratio1, screen_ratio2 );
dirty_rect.add( ai->pos );
}
}
EffectLink *el = parseEffect(true);
if (setEffect(el)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
#if defined(USE_SMPEG)
static void smpeg_filter_callback( SDL_Overlay * dst, SDL_Overlay * src, SDL_Rect * region, SMPEG_FilterInfo * filter_info, void * data )
{
if (dst){
dst->w = 0;
dst->h = 0;
}
ONScripter *ons = (ONScripter*)data;
AnimationInfo *ai = ons->getSMPEGInfo();
if (!ai) return;
ai->convertFromYUV(src);
ons->updateEffect();
}
static void smpeg_filter_destroy( struct SMPEG_Filter * filter )
{
}
#endif
int ONScripter::layermessageCommand()
{
int no = script_h.readInt();
const char *buf = script_h.readStr();
if (!layer_info[no].str) return RET_CONTINUE;
#if defined(USE_SMPEG)
if (&sprite_info[layer_info[no].sprite_num] == smpeg_info){
if (strncmp(buf, "open/",5) == 0){
unsigned long length = script_h.cBR->getFileLength( buf+5 );
if (length == 0){
fprintf( stderr, " *** can't find file [%s] ***\n", buf+5 );
return RET_CONTINUE;
}
stopSMPEG();
layer_smpeg_buffer = new unsigned char[length];
script_h.cBR->getFile( buf+5, layer_smpeg_buffer );
layer_smpeg_sample = SMPEG_new_rwops( SDL_RWFromMem( layer_smpeg_buffer, length ), NULL, 0 );
if ( SMPEG_error( layer_smpeg_sample ) ) return RET_CONTINUE;
SMPEG_enableaudio( layer_smpeg_sample, 0 );
SMPEG_enablevideo( layer_smpeg_sample, 1 );
#ifdef USE_SDL_RENDERER
// workaround to set a non-NULL value in the second argument
SMPEG_setdisplay( layer_smpeg_sample, accumulation_surface, NULL, NULL);
#else
SMPEG_setdisplay( layer_smpeg_sample, screen_surface, NULL, NULL);
#endif
}
else if (strcmp(buf, "play") == 0){
smpeg_info->visible = true;
layer_smpeg_filter.data = this;
layer_smpeg_filter.callback = smpeg_filter_callback;
layer_smpeg_filter.destroy = smpeg_filter_destroy;
SMPEG_filter( layer_smpeg_sample, &layer_smpeg_filter );
SMPEG_loop( layer_smpeg_sample, layer_smpeg_loop_flag?1:0);
SMPEG_renderFrame( layer_smpeg_sample, 1 );
SMPEG_play( layer_smpeg_sample );
}
else if (strcmp(buf, "pause") == 0){
if (layer_smpeg_sample)
SMPEG_pause( layer_smpeg_sample );
}
else if (strcmp(buf, "close") == 0){
smpeg_info->visible = false;
stopSMPEG();
}
else if (strncmp(buf, "setloop/", 8) == 0){
if (buf[8] == '1')
layer_smpeg_loop_flag = true;
else
layer_smpeg_loop_flag = false;
}
}
#endif
return RET_CONTINUE;
}
int ONScripter::langjpCommand()
{
current_read_language = 1;
return RET_CONTINUE;
}
int ONScripter::langenCommand()
{
current_read_language = 0;
return RET_CONTINUE;
}
int ONScripter::kinsokuCommand()
{
if (script_h.compareString("on")){
is_kinsoku = true;
script_h.readLabel();
}
else if (script_h.compareString("off")){
is_kinsoku = false;
script_h.readLabel();
}
return RET_CONTINUE;
}
int ONScripter::jumpfCommand()
{
char *buf = script_h.getNext();
while(*buf != '\0' && *buf != '~') buf++;
if (*buf == '~') buf++;
script_h.setCurrent(buf);
current_label_info = script_h.getLabelByAddress(buf);
current_line = script_h.getLineByAddress(buf);
return RET_CONTINUE;
}
int ONScripter::jumpbCommand()
{
script_h.setCurrent( last_tilde.next_script );
current_label_info = script_h.getLabelByAddress( last_tilde.next_script );
current_line = script_h.getLineByAddress( last_tilde.next_script );
return RET_CONTINUE;
}
int ONScripter::ispageCommand()
{
script_h.readInt();
if ( textgosub_clickstr_state == CLICK_NEWPAGE )
script_h.setInt( &script_h.current_variable, 1 );
else
script_h.setInt( &script_h.current_variable, 0 );
return RET_CONTINUE;
}
int ONScripter::isfullCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, fullscreen_mode?1:0 );
return RET_CONTINUE;
}
int ONScripter::isskipCommand()
{
script_h.readInt();
if ( automode_flag )
script_h.setInt( &script_h.current_variable, 2 );
else if ( skip_mode & SKIP_NORMAL )
script_h.setInt( &script_h.current_variable, 1 );
else
script_h.setInt( &script_h.current_variable, 0 );
return RET_CONTINUE;
}
int ONScripter::isdownCommand()
{
script_h.readInt();
if ( current_button_state.down_flag )
script_h.setInt( &script_h.current_variable, 1 );
else
script_h.setInt( &script_h.current_variable, 0 );
return RET_CONTINUE;
}
int ONScripter::inputCommand()
{
script_h.readStr();
if ( script_h.current_variable.type != ScriptHandler::VAR_STR )
errorAndExit( "input: no string variable." );
int no = script_h.current_variable.var_no;
script_h.readStr(); // description
const char *buf = script_h.readStr(); // default value
setStr( &script_h.getVariableData(no).str, buf );
printf( "*** inputCommand(): $%d is set to the default value: %s\n",
no, buf );
script_h.readInt(); // maxlen
script_h.readInt(); // widechar flag
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
script_h.readInt(); // window width
script_h.readInt(); // window height
script_h.readInt(); // text box width
script_h.readInt(); // text box height
}
return RET_CONTINUE;
}
int ONScripter::indentCommand()
{
indent_offset = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::humanorderCommand()
{
leaveTextDisplayMode();
const char *buf = script_h.readStr();
int i;
for (i=0 ; i<3 ; i++){
if (buf[i] == 'l') human_order[i] = 0;
else if (buf[i] == 'c') human_order[i] = 1;
else if (buf[i] == 'r') human_order[i] = 2;
else human_order[i] = -1;
}
for ( i=0 ; i<3 ; i++ )
if (tachi_info[i].image_surface)
dirty_rect.add( tachi_info[i].pos );
EffectLink *el = parseEffect(true);
if (setEffect(el)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripter::getzxcCommand()
{
getzxc_flag = true;
return RET_CONTINUE;
}
int ONScripter::getvoicevolCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, voice_volume );
return RET_CONTINUE;
}
int ONScripter::getversionCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, NSC_VERSION );
return RET_CONTINUE;
}
int ONScripter::gettimerCommand()
{
bool gettimer_flag=false;
if ( script_h.isName( "gettimer" ) ){
gettimer_flag = true;
}
else if ( script_h.isName( "getbtntimer" ) ){
}
script_h.readInt();
if ( gettimer_flag ){
script_h.setInt( &script_h.current_variable, SDL_GetTicks() - internal_timer );
}
else{
script_h.setInt( &script_h.current_variable, btnwait_time );
}
return RET_CONTINUE;
}
int ONScripter::gettextCommand()
{
script_h.readStr();
int no = script_h.current_variable.var_no;
char *buf = new char[ current_page->text_count + 1 ];
int i, j;
for ( i=0, j=0 ; i<current_page->text_count ; i++ ){
if ( current_page->text[i] != 0x0a )
buf[j++] = current_page->text[i];
}
buf[j] = '\0';
setStr( &script_h.getVariableData(no).str, buf );
delete[] buf;
return RET_CONTINUE;
}
int ONScripter::gettaglogCommand()
{
script_h.readVariable();
script_h.pushVariable();
int page_no = script_h.readInt();
Page *page = current_page;
while(page != start_page && page_no > 0){
page_no--;
page = page->previous;
}
if (page->tag)
setStr(&script_h.getVariableData(script_h.pushed_variable.var_no).str, page->tag);
else
setStr(&script_h.getVariableData(script_h.pushed_variable.var_no).str, NULL);
return RET_CONTINUE;
}
int ONScripter::gettagCommand()
{
if ( !last_nest_info->previous || last_nest_info->nest_mode != NestInfo::LABEL )
errorAndExit( "gettag: not in a subroutine, i.e. pretextgosub" );
char *buf = pretext_buf;
int n = script_h.enc.getBytes(buf[0]);
unsigned short unicode1 = script_h.enc.getUTF16(buf);
unsigned short unicode2 = script_h.enc.getUTF16("", Encoding::CODE_CP932);
if (buf[0] == '[')
buf++;
else if (zenkakko_flag && unicode1 == unicode2)
buf += n;
else
buf = NULL;
int end_status;
do{
script_h.readVariable();
end_status = script_h.getEndStatus();
script_h.pushVariable();
if ( script_h.pushed_variable.type & ScriptHandler::VAR_INT ||
script_h.pushed_variable.type & ScriptHandler::VAR_ARRAY ){
if (buf)
script_h.setInt( &script_h.pushed_variable, script_h.parseInt(&buf));
else
script_h.setInt( &script_h.pushed_variable, 0);
}
else if ( script_h.pushed_variable.type & ScriptHandler::VAR_STR ){
if (buf){
const char *buf_start = buf;
unicode1 = script_h.enc.getUTF16(buf);
unicode2 = script_h.enc.getUTF16("", Encoding::CODE_CP932);
while(*buf != '/' && *buf != 0 && *buf != ']' &&
(!zenkakko_flag || unicode1 != unicode2)){
buf += script_h.enc.getBytes(buf[0]);
}
setStr( &script_h.getVariableData(script_h.pushed_variable.var_no).str, buf_start, buf-buf_start );
}
else{
setStr( &script_h.getVariableData(script_h.pushed_variable.var_no).str, NULL);
}
}
if (buf) pretext_buf = buf;
if (buf && *buf == '/')
buf++;
else
buf = NULL;
}
while(end_status & ScriptHandler::END_COMMA);
n = script_h.enc.getBytes(pretext_buf[0]);
unicode1 = script_h.enc.getUTF16(pretext_buf);
unicode2 = script_h.enc.getUTF16("", Encoding::CODE_CP932);
if (pretext_buf[0] == ']')
pretext_buf++;
else if (zenkakko_flag && unicode1 == unicode2)
pretext_buf += n;
return RET_CONTINUE;
}
int ONScripter::gettabCommand()
{
gettab_flag = true;
return RET_CONTINUE;
}
int ONScripter::getspsizeCommand()
{
int no = script_h.readInt();
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].orig_pos.w );
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].orig_pos.h );
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].num_of_cells );
}
return RET_CONTINUE;
}
int ONScripter::getspposCommand()
{
int no = script_h.readInt();
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].orig_pos.x );
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].orig_pos.y );
return RET_CONTINUE;
}
int ONScripter::getspmodeCommand()
{
script_h.readVariable();
script_h.pushVariable();
int no = script_h.readInt();
script_h.setInt( &script_h.pushed_variable, sprite_info[no].visible?1:0 );
return RET_CONTINUE;
}
int ONScripter::getsevolCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, se_volume );
return RET_CONTINUE;
}
int ONScripter::getscreenshotCommand()
{
int w = script_h.readInt();
if (disable_rescale_flag) w = w * screen_ratio1 / screen_ratio2;
int h = script_h.readInt();
if (disable_rescale_flag) h = h * screen_ratio1 / screen_ratio2;
if ( w == 0 ) w = 1;
if ( h == 0 ) h = 1;
screenshot_w = w;
screenshot_h = h;
#ifdef USE_SDL_RENDERER
SDL_Rect rect = {(device_width -screen_device_width)/2,
(device_height-screen_device_height)/2,
screen_device_width, screen_device_height};
SDL_LockSurface(screenshot_surface);
SDL_RenderReadPixels(renderer, &rect, screenshot_surface->format->format, screenshot_surface->pixels, screenshot_surface->pitch);
SDL_UnlockSurface(screenshot_surface);
#else
SDL_BlitSurface(screen_surface, NULL, screenshot_surface, NULL);
#endif
return RET_CONTINUE;
}
int ONScripter::getsavestrCommand()
{
script_h.readVariable();
if ( script_h.current_variable.type != ScriptHandler::VAR_STR )
errorAndExit( "getsavestr: no string variable." );
script_h.pushVariable();
int no = script_h.readInt();
char *buf = readSaveStrFromFile( no );
setStr( &script_h.getVariableData(script_h.pushed_variable.var_no).str, buf );
if (buf) delete[] buf;
return RET_CONTINUE;
}
int ONScripter::getreadlangCommand()
{
script_h.readInt();
script_h.setInt(&script_h.current_variable, current_read_language);
return RET_CONTINUE;
}
int ONScripter::getpageupCommand()
{
getpageup_flag = true;
return RET_CONTINUE;
}
int ONScripter::getpageCommand()
{
getpageup_flag = true;
getpagedown_flag = true;
return RET_CONTINUE;
}
int ONScripter::getretCommand()
{
script_h.readVariable();
if ( script_h.current_variable.type == ScriptHandler::VAR_INT ||
script_h.current_variable.type == ScriptHandler::VAR_ARRAY ){
script_h.setInt( &script_h.current_variable, getret_int );
}
else if ( script_h.current_variable.type == ScriptHandler::VAR_STR ){
int no = script_h.current_variable.var_no;
setStr( &script_h.getVariableData(no).str, getret_str );
}
else errorAndExit( "getret: no variable." );
return RET_CONTINUE;
}
int ONScripter::getregCommand()
{
script_h.readVariable();
if ( script_h.current_variable.type != ScriptHandler::VAR_STR )
errorAndExit( "getreg: no string variable." );
int no = script_h.current_variable.var_no;
const char *buf = script_h.readStr();
char path[256], key[256];
strcpy( path, buf );
buf = script_h.readStr();
strcpy( key, buf );
printf(" reading Registry file for [%s] %s\n", path, key );
FILE *fp;
if ( ( fp = fopen( registry_file, "r" ) ) == NULL ){
fprintf( stderr, "Cannot open file [%s]\n", registry_file );
return RET_CONTINUE;
}
char reg_buf[256], reg_buf2[256];
bool found_flag = false;
while( fgets( reg_buf, 256, fp) && !found_flag ){
if ( reg_buf[0] == '[' ){
unsigned int c=0;
while ( reg_buf[c] != ']' && reg_buf[c] != '\0' ) c++;
if ( !strncmp( reg_buf + 1, path, (c-1>strlen(path))?(c-1):strlen(path) ) ){
while( fgets( reg_buf2, 256, fp) ){
script_h.pushCurrent( reg_buf2 );
buf = script_h.readStr();
if ( strncmp( buf,
key,
(strlen(buf)>strlen(key))?strlen(buf):strlen(key) ) ){
script_h.popCurrent();
continue;
}
if ( !script_h.compareString("=") ){
script_h.popCurrent();
continue;
}
script_h.setCurrent(script_h.getNext()+1);
buf = script_h.readStr();
setStr( &script_h.getVariableData(no).str, buf );
script_h.popCurrent();
printf(" $%d = %s\n", no, script_h.getVariableData(no).str );
found_flag = true;
break;
}
}
}
}
if ( !found_flag ) fprintf( stderr, " The key is not found.\n" );
fclose(fp);
return RET_CONTINUE;
}
int ONScripter::getmclickCommand()
{
getmclick_flag = true;
return RET_CONTINUE;
}
int ONScripter::getmp3volCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, music_volume );
return RET_CONTINUE;
}
int ONScripter::getmouseposCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, current_button_state.x * screen_ratio2 / screen_ratio1 );
script_h.readInt();
script_h.setInt( &script_h.current_variable, current_button_state.y * screen_ratio2 / screen_ratio1 );
return RET_CONTINUE;
}
int ONScripter::getmouseoverCommand()
{
getmouseover_flag = true;
getmouseover_lower = script_h.readInt();
getmouseover_upper = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::getlogCommand()
{
bool getlogtext_flag=false;
if ( script_h.isName( "getlogtext" ) )
getlogtext_flag = true;
script_h.readVariable();
script_h.pushVariable();
int page_no = script_h.readInt();
Page *page = current_page;
while(page != start_page && page_no > 0){
page_no--;
page = page->previous;
}
if (page_no > 0)
setStr( &script_h.getVariableData(script_h.pushed_variable.var_no).str, NULL );
else{
char *buf = page->text;
int count = page->text_count;
if (getlogtext_flag){
char *p = page->text;
char *p2 = buf = new char[page->text_count];
count = 0;
for (int i=0 ; i<page->text_count ; i++){
int n = script_h.enc.getBytes(*p);
if (n >= 2){
for (int j=0; j<n; j++)
p2[count++] = *p++;
i += n-1;
}
else if (*p != 0x0a)
p2[count++] = *p++;
else
p++;
}
}
setStr( &script_h.getVariableData(script_h.pushed_variable.var_no).str, buf, count );
if (getlogtext_flag) delete[] buf;
}
return RET_CONTINUE;
}
int ONScripter::getinsertCommand()
{
getinsert_flag = true;
return RET_CONTINUE;
}
int ONScripter::getfunctionCommand()
{
getfunction_flag = true;
return RET_CONTINUE;
}
int ONScripter::getenterCommand()
{
if ( !force_button_shortcut_flag )
getenter_flag = true;
return RET_CONTINUE;
}
int ONScripter::getcursorpos2Command()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, sentence_font.old_xy[0] );
script_h.readInt();
script_h.setInt( &script_h.current_variable, sentence_font.old_xy[1] );
return RET_CONTINUE;
}
int ONScripter::getcursorposCommand()
{
FontInfo fi = sentence_font;
if ( fi.isEndOfLine() ){
fi.newLine();
for (int i=0 ; i<indent_offset ; i++)
fi.advanceCharInHankaku(2);
}
script_h.readInt();
script_h.setInt( &script_h.current_variable, fi.x(false) );
script_h.readInt();
script_h.setInt( &script_h.current_variable, fi.y(false) );
return RET_CONTINUE;
}
int ONScripter::getcursorCommand()
{
if ( !force_button_shortcut_flag )
getcursor_flag = true;
return RET_CONTINUE;
}
int ONScripter::getcselstrCommand()
{
script_h.readVariable();
script_h.pushVariable();
int csel_no = script_h.readInt();
int counter = 0;
SelectLink *link = root_select_link.next;
while (link){
if (csel_no == counter++) break;
link = link->next;
}
setStr(&script_h.getVariableData(script_h.pushed_variable.var_no).str, link?(link->text):NULL);
return RET_CONTINUE;
}
int ONScripter::getcselnumCommand()
{
int count = 0;
SelectLink *link = root_select_link.next;
while ( link ) {
count++;
link = link->next;
}
script_h.readInt();
script_h.setInt( &script_h.current_variable, count );
return RET_CONTINUE;
}
int ONScripter::gameCommand()
{
if ( current_mode != DEFINE_MODE )
errorAndExit( "game: not in the define section" );
int i;
current_mode = NORMAL_MODE;
/* ---------------------------------------- */
if ( !lookback_info[0].image_surface ){
setStr( &lookback_info[0].image_name, DEFAULT_LOOKBACK_NAME0 );
parseTaggedString( &lookback_info[0] );
setupAnimationInfo( &lookback_info[0] );
}
if ( !lookback_info[1].image_surface ){
setStr( &lookback_info[1].image_name, DEFAULT_LOOKBACK_NAME1 );
parseTaggedString( &lookback_info[1] );
setupAnimationInfo( &lookback_info[1] );
}
if ( !lookback_info[2].image_surface ){
setStr( &lookback_info[2].image_name, DEFAULT_LOOKBACK_NAME2 );
parseTaggedString( &lookback_info[2] );
setupAnimationInfo( &lookback_info[2] );
}
if ( !lookback_info[3].image_surface ){
setStr( &lookback_info[3].image_name, DEFAULT_LOOKBACK_NAME3 );
parseTaggedString( &lookback_info[3] );
setupAnimationInfo( &lookback_info[3] );
}
/* ---------------------------------------- */
/* Initialize text buffer */
page_list = new Page[max_page_list];
for ( i=0 ; i<max_page_list-1 ; i++ ){
page_list[i].next = &page_list[i+1];
page_list[i+1].previous = &page_list[i];
}
page_list[0].previous = &page_list[max_page_list-1];
page_list[max_page_list-1].next = &page_list[0];
resetCommand();
loadCursor( 0, NULL, 0, 0 );
loadCursor( 1, NULL, 0, 0 );
#ifdef USE_LUA
lua_handler.loadInitScript();
if (lua_handler.isCallbackEnabled(LUAHandler::LUA_RESET)){
if (lua_handler.callFunction(true, "reset"))
errorAndExit( lua_handler.error_str );
}
#endif
return RET_CONTINUE;
}
int ONScripter::fileexistCommand()
{
script_h.readInt();
script_h.pushVariable();
const char *buf = script_h.readStr();
script_h.setInt( &script_h.pushed_variable, (script_h.cBR->getFileLength(buf)>0)?1:0 );
return RET_CONTINUE;
}
int ONScripter::exec_dllCommand()
{
const char *buf = script_h.readStr();
char dll_name[256];
unsigned int c=0, c2=0;
while(buf[c] != '/' && buf[c] != 0x0){
if (buf[c] == '\\'){
c++;
c2 = 0;
continue;
}
dll_name[c2++] = buf[c++];
}
dll_name[c2] = '\0';
if (strcmp(dll_name, "fileutil.dll") == 0){
if (strncmp(buf+c, "/mkdir", 6) == 0){
c += 7;
char *dir = new char[strlen(archive_path) + strlen(buf+c) + 1];
sprintf(dir, "%s%s", archive_path, buf+c);
#if defined(LINUX) || defined(MACOSX) || defined(IOS)
mkdir(dir, 0755);
#elif defined(WIN32)
_mkdir(dir);
#endif
delete[] dir;
}
return RET_CONTINUE;
}
FILE *fp;
if ( ( fp = fopen( dll_file, "r" ) ) == NULL ){
fprintf( stderr, "Cannot open file [%s] while reading %s\n", dll_file, dll_name );
return RET_CONTINUE;
}
char dll_buf[256], dll_buf2[256];
bool found_flag = false;
while( fgets( dll_buf, 256, fp) && !found_flag ){
if ( dll_buf[0] == '[' ){
c=0;
while ( dll_buf[c] != ']' && dll_buf[c] != '\0' ) c++;
if ( !strncmp( dll_buf + 1, dll_name, (c-1>strlen(dll_name))?(c-1):strlen(dll_name) ) ){
found_flag = true;
while( fgets( dll_buf2, 256, fp) ){
c=0;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
if ( !strncmp( &dll_buf2[c], "str", 3 ) ){
c+=3;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
if ( dll_buf2[c] != '=' ) continue;
c++;
while ( dll_buf2[c] != '"' ) c++;
unsigned int c2 = ++c;
while ( dll_buf2[c2] != '"' && dll_buf2[c2] != '\0' ) c2++;
dll_buf2[c2] = '\0';
setStr( &getret_str, &dll_buf2[c] );
printf(" getret_str = %s\n", getret_str );
}
else if ( !strncmp( &dll_buf2[c], "ret", 3 ) ){
c+=3;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
if ( dll_buf2[c] != '=' ) continue;
c++;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
getret_int = atoi( &dll_buf2[c] );
printf(" getret_int = %d\n", getret_int );
}
else if ( dll_buf2[c] == '[' )
break;
}
}
}
}
if ( !found_flag ) fprintf( stderr, " The DLL is not found in %s.\n", dll_file );
fclose( fp );
return RET_CONTINUE;
}
int ONScripter::exbtnCommand()
{
int sprite_no=-1, no=0;
ButtonLink *bl;
if ( script_h.isName( "exbtn_d" ) ||
script_h.isName( "bdef" )){
bl = &exbtn_d_button_link;
for (int i=0 ; i<3 ; i++){
if ( bl->exbtn_ctl[i] ){
delete[] bl->exbtn_ctl[i];
bl->exbtn_ctl[i] = NULL;
}
}
}
else{
bool cellcheck_flag = false;
if ( script_h.isName( "cellcheckexbtn" ) )
cellcheck_flag = true;
sprite_no = script_h.readInt();
no = script_h.readInt();
if (no < 1 ||
sprite_no < 0 ||
sprite_no >= MAX_SPRITE_NUM ||
sprite_info[sprite_no].image_surface == NULL ||
( cellcheck_flag && sprite_info[ sprite_no ].num_of_cells < 2) ||
(!cellcheck_flag && sprite_info[ sprite_no ].num_of_cells == 0)){
script_h.readStr();
return RET_CONTINUE;
}
bl = new ButtonLink();
root_button_link.insert( bl );
is_exbtn_enabled = true;
}
const char *buf = script_h.readStr();
bl->button_type = ButtonLink::SPRITE_BUTTON;
bl->sprite_no = sprite_no;
bl->no = no;
setStr( &bl->exbtn_ctl[1], buf );
if ( sprite_no >= 0 &&
( sprite_info[ sprite_no ].image_surface ||
sprite_info[ sprite_no ].trans_mode == AnimationInfo::TRANS_STRING ) )
bl->image_rect = bl->select_rect = sprite_info[ sprite_no ].pos;
return RET_CONTINUE;
}
int ONScripter::erasetextwindowCommand()
{
erase_text_window_mode = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::endCommand()
{
quit();
stopSMPEG();
exit(0);
return RET_CONTINUE; // dummy
}
int ONScripter::dwavestopCommand()
{
int ch = script_h.readInt();
if (ch < 0) ch = 0;
else if (ch >= ONS_MIX_CHANNELS) ch = ONS_MIX_CHANNELS-1;
if ( wave_sample[ch] ){
Mix_Pause( ch );
Mix_FreeChunk( wave_sample[ch] );
wave_sample[ch] = NULL;
}
return RET_CONTINUE;
}
int ONScripter::dwaveCommand()
{
int play_mode = WAVE_PLAY;
bool loop_flag = false;
if ( script_h.isName( "dwaveloop" ) ){
loop_flag = true;
}
else if ( script_h.isName( "dwaveload" ) ){
play_mode = WAVE_PRELOAD;
}
else if ( script_h.isName( "dwaveplayloop" ) ){
play_mode = WAVE_PLAY_LOADED;
loop_flag = true;
}
else if ( script_h.isName( "dwaveplay" ) ){
play_mode = WAVE_PLAY_LOADED;
loop_flag = false;
}
int ch = script_h.readInt();
if (ch < 0) ch = 0;
else if (ch >= ONS_MIX_CHANNELS) ch = ONS_MIX_CHANNELS-1;
if (play_mode == WAVE_PLAY_LOADED){
Mix_PlayChannel(ch, wave_sample[ch], loop_flag?-1:0);
}
else{
const char *buf = script_h.readStr();
int fmt = SOUND_CHUNK;
if (play_mode == WAVE_PRELOAD) fmt |= SOUND_PRELOAD;
playSound(buf, fmt, loop_flag, ch);
}
return RET_CONTINUE;
}
int ONScripter::dvCommand()
{
char buf[256];
sprintf(buf, RELATIVEPATH "voice%c%s.wav", DELIMITER, script_h.getStringBuffer()+2);
playSound(buf, SOUND_CHUNK, false, 0);
return RET_CONTINUE;
}
int ONScripter::drawtextCommand()
{
SDL_Rect clip;
clip.x = clip.y = 0;
clip.w = accumulation_surface->w;
clip.h = accumulation_surface->h;
text_info.blendOnSurface( accumulation_surface, 0, 0, clip, layer_alpha_buf );
return RET_CONTINUE;
}
int ONScripter::drawsp3Command()
{
int sprite_no = script_h.readInt();
int cell_no = script_h.readInt();
int alpha = script_h.readInt();
int x = script_h.readInt() * screen_ratio1 / screen_ratio2;
int y = script_h.readInt() * screen_ratio1 / screen_ratio2;
AnimationInfo *ai = &sprite_info[sprite_no];
int old_cell_no = ai->current_cell;
ai->setCell(cell_no);
ai->mat[0][0] = script_h.readInt();
ai->mat[0][1] = script_h.readInt();
ai->mat[1][0] = script_h.readInt();
ai->mat[1][1] = script_h.readInt();
int denom = (ai->mat[0][0]*ai->mat[1][1]-ai->mat[0][1]*ai->mat[1][0])/1000;
if (denom != 0){
ai->inv_mat[0][0] = ai->mat[1][1] * 1000 / denom;
ai->inv_mat[0][1] = -ai->mat[0][1] * 1000 / denom;
ai->inv_mat[1][0] = -ai->mat[1][0] * 1000 / denom;
ai->inv_mat[1][1] = ai->mat[0][0] * 1000 / denom;
}
ai->blendOnSurface2( accumulation_surface, x, y, screen_rect, layer_alpha_buf, alpha );
ai->setCell(old_cell_no);
return RET_CONTINUE;
}
int ONScripter::drawsp2Command()
{
int sprite_no = script_h.readInt();
int cell_no = script_h.readInt();
int alpha = script_h.readInt();
AnimationInfo *ai = &sprite_info[sprite_no];
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
ai->scale_x = script_h.readInt();
ai->scale_y = script_h.readInt();
ai->rot = script_h.readInt();
ai->calcAffineMatrix();
ai->setCell(cell_no);
ai->blendOnSurface2( accumulation_surface, ai->pos.x, ai->pos.y, screen_rect, layer_alpha_buf, alpha );
return RET_CONTINUE;
}
int ONScripter::drawspCommand()
{
int sprite_no = script_h.readInt();
int cell_no = script_h.readInt();
int alpha = script_h.readInt();
int x = script_h.readInt() * screen_ratio1 / screen_ratio2;
int y = script_h.readInt() * screen_ratio1 / screen_ratio2;
AnimationInfo *ai = &sprite_info[sprite_no];
int old_cell_no = ai->current_cell;
ai->setCell(cell_no);
SDL_Rect clip;
clip.x = clip.y = 0;
clip.w = accumulation_surface->w;
clip.h = accumulation_surface->h;
ai->blendOnSurface( accumulation_surface, x, y, clip, layer_alpha_buf, alpha );
ai->setCell(old_cell_no);
return RET_CONTINUE;
}
int ONScripter::drawfillCommand()
{
int r = script_h.readInt();
int g = script_h.readInt();
int b = script_h.readInt();
SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( accumulation_surface->format, r, g, b, 0xff) );
return RET_CONTINUE;
}
int ONScripter::drawclearCommand()
{
SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( accumulation_surface->format, 0, 0, 0, 0xff) );
return RET_CONTINUE;
}
int ONScripter::drawbgCommand()
{
SDL_Rect clip;
clip.x = clip.y = 0;
clip.w = accumulation_surface->w;
clip.h = accumulation_surface->h;
bg_info.blendOnSurface( accumulation_surface, bg_info.pos.x, bg_info.pos.y, clip, layer_alpha_buf );
return RET_CONTINUE;
}
int ONScripter::drawbg2Command()
{
AnimationInfo bi = bg_info;
bi.orig_pos.x = script_h.readInt();
bi.orig_pos.y = script_h.readInt();
bi.scalePosXY( screen_ratio1, screen_ratio2 );
bi.scale_x = script_h.readInt();
bi.scale_y = script_h.readInt();
bi.rot = script_h.readInt();
bi.calcAffineMatrix();
bi.blendOnSurface2( accumulation_surface, bi.pos.x, bi.pos.y, screen_rect, layer_alpha_buf, 255 );
return RET_CONTINUE;
}
int ONScripter::drawCommand()
{
flushDirect( screen_rect, REFRESH_NONE_MODE );
dirty_rect.clear();
return RET_CONTINUE;
}
int ONScripter::delayCommand()
{
int val = script_h.readInt();
if (skip_mode & SKIP_NORMAL || ctrl_pressed_status)
return RET_CONTINUE;
event_mode = WAIT_TIMER_MODE | WAIT_INPUT_MODE;
waitEvent( val );
return RET_CONTINUE;
}
int ONScripter::defineresetCommand()
{
saveGlovalData();
script_h.reset();
ScriptParser::reset();
reset();
setCurrentLabel( "define" );
if ( loadFileIOBuf( "gloval.sav" ) > 0 )
readVariables( script_h.global_variable_border, script_h.variable_range );
#ifdef USE_LUA
lua_handler.init(this, &script_h, screen_ratio1, screen_ratio2);
#endif
current_mode = DEFINE_MODE;
return RET_CONTINUE;
}
int ONScripter::cspCommand()
{
leaveTextDisplayMode();
bool csp2_flag = false;
if (script_h.isName("csp2")) csp2_flag = true;
int no = script_h.readInt();
AnimationInfo *si = NULL;
int num = 0;
if (csp2_flag) {
num = MAX_SPRITE2_NUM;
si = sprite2_info;
}
else{
num = MAX_SPRITE_NUM;
si = sprite_info;
}
if ( no == -1 )
for ( int i=0 ; i<num ; i++ ){
if ( si[i].visible ){
if (csp2_flag)
dirty_rect.add( si[i].bounding_rect );
else
dirty_rect.add( si[i].pos );
}
if ( si[i].image_name ){
si[i].orig_pos.x = -1000;
si[i].orig_pos.y = -1000;
si[i].scalePosXY( screen_ratio1, screen_ratio2 );
}
if (!csp2_flag) root_button_link.removeSprite(i);
si[i].remove();
}
else if (no >= 0 && no < MAX_SPRITE_NUM){
if ( si[no].visible ){
if (csp2_flag)
dirty_rect.add( si[no].bounding_rect );
else
dirty_rect.add( si[no].pos );
}
if (!csp2_flag) root_button_link.removeSprite(no);
si[no].remove();
}
return RET_CONTINUE;
}
int ONScripter::cselgotoCommand()
{
int csel_no = script_h.readInt();
int counter = 0;
SelectLink *link = root_select_link.next;
while( link ){
if ( csel_no == counter++ ) break;
link = link->next;
}
if ( !link ) errorAndExit( "cselgoto: no select link" );
setCurrentLabel( link->label );
deleteSelectLink();
newPage();
return RET_CONTINUE;
}
int ONScripter::cselbtnCommand()
{
int csel_no = script_h.readInt();
int button_no = script_h.readInt();
FontInfo csel_info = sentence_font;
csel_info.rubyon_flag = false;
csel_info.top_xy[0] = script_h.readInt();
csel_info.top_xy[1] = script_h.readInt();
int counter = 0;
SelectLink *link = root_select_link.next;
while ( link ){
if ( csel_no == counter++ ) break;
link = link->next;
}
if ( link == NULL || link->text == NULL || *link->text == '\0' )
return RET_CONTINUE;
openFont(&csel_info);
csel_info.setLineArea(link->text);
csel_info.clear();
ButtonLink *button = getSelectableSentence( link->text, &csel_info );
root_button_link.insert( button );
button->no = button_no;
button->sprite_no = csel_no;
sentence_font.ttf_font[0] = csel_info.ttf_font[0];
sentence_font.ttf_font[1] = csel_info.ttf_font[1];
return RET_CONTINUE;
}
int ONScripter::clickCommand()
{
bool lrclick_flag = false;
if ( script_h.isName( "lrclick" ) ) lrclick_flag = true;
skip_mode &= ~SKIP_NORMAL;
event_mode = WAIT_TIMER_MODE | WAIT_INPUT_MODE;
if (lrclick_flag) event_mode |= WAIT_RCLICK_MODE;
waitEvent(-1);
if (lrclick_flag)
getret_int = (current_button_state.button == -1)?0:1;
return RET_CONTINUE;
}
int ONScripter::clCommand()
{
leaveTextDisplayMode();
char loc = script_h.readLabel()[0];
if ( loc == 'l' || loc == 'a' ){
dirty_rect.add( tachi_info[0].pos );
tachi_info[0].remove();
}
if ( loc == 'c' || loc == 'a' ){
dirty_rect.add( tachi_info[1].pos );
tachi_info[1].remove();
}
if ( loc == 'r' || loc == 'a' ){
dirty_rect.add( tachi_info[2].pos );
tachi_info[2].remove();
}
EffectLink *el = parseEffect(true);
if (setEffect(el)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripter::chvolCommand()
{
int ch = script_h.readInt();
if (ch < 0) ch = 0;
else if (ch >= ONS_MIX_CHANNELS) ch = ONS_MIX_CHANNELS-1;
int vol = script_h.readInt();
if ( wave_sample[ch] ) Mix_Volume( ch, vol * MIX_MAX_VOLUME / 100 );
return RET_CONTINUE;
}
int ONScripter::checkpageCommand()
{
script_h.readVariable();
script_h.pushVariable();
if ( script_h.pushed_variable.type != ScriptHandler::VAR_INT &&
script_h.pushed_variable.type != ScriptHandler::VAR_ARRAY )
errorAndExit( "checkpage: no integer variable." );
int page_no = script_h.readInt();
Page *page = current_page;
while(page != start_page && page_no > 0){
page_no--;
page = page->previous;
}
if (page_no > 0)
script_h.setInt( &script_h.pushed_variable, 0 );
else
script_h.setInt( &script_h.pushed_variable, 1 );
return RET_CONTINUE;
}
int ONScripter::checkkeyCommand()
{
script_h.readVariable();
script_h.pushVariable();
const char *str = script_h.readStr();
if (strcmp(current_button_state.str, str) == 0)
script_h.setInt( &script_h.pushed_variable, 1 );
else
script_h.setInt( &script_h.pushed_variable, 0 );
return RET_CONTINUE;
}
int ONScripter::cellCommand()
{
int sprite_no = script_h.readInt();
int no = script_h.readInt();
sprite_info[sprite_no].setCell(no);
dirty_rect.add( sprite_info[sprite_no].pos );
return RET_CONTINUE;
}
int ONScripter::captionCommand()
{
const char* buf = script_h.readStr();
size_t len = strlen(buf);
char *buf2 = new char[len*3+1];
#if defined(MACOSX) && (SDL_COMPILEDVERSION >= 1208) /* convert sjis to utf-8 */
DirectReader::convertFromSJISToUTF8(buf2, buf);
#elif defined(LINUX) || (defined(WIN32) && defined(UTF8_CAPTION))
#if defined(UTF8_CAPTION)
if (script_h.enc.getEncoding() == Encoding::CODE_UTF8)
strcpy(buf2, buf);
else
DirectReader::convertFromSJISToUTF8(buf2, buf);
#else
if (script_h.enc.getEncoding() == Encoding::CODE_UTF8){
int c = 0;
while(buf[0] != 0){
int n = script_h.enc.getBytes(buf[0]);
unsigned short unicode = script_h.enc.getUTF16(buf);
if (n == 1){
buf2[c++] = unicode;
}
else{
unsigned short sjis = convUTF162SJIS(unicode);
buf2[c++] = sjis >> 8;
buf2[c++] = sjis & 0xff;
}
buf += n;
}
buf2[c] = 0;
}
else{
strcpy(buf2, buf);
}
DirectReader::convertFromSJISToEUC(buf2);
#endif
#else
strcpy(buf2, buf);
#endif
setStr( &wm_title_string, buf2 );
setStr( &wm_icon_string, buf2 );
delete[] buf2;
SDL_WM_SetCaption( wm_title_string, wm_icon_string );
return RET_CONTINUE;
}
int ONScripter::btnwaitCommand()
{
bool del_flag=false, textbtn_flag=false;
bool bexec_int_flag=false;
bexec_flag = false;
if ( script_h.isName( "btnwait2" ) ){
leaveTextDisplayMode();
}
else if ( script_h.isName( "btnwait" ) ){
del_flag = true;
leaveTextDisplayMode();
}
else if ( script_h.isName( "textbtnwait" ) ){
textbtn_flag = true;
}
else if ( script_h.isName( "bexec" ) ){
bexec_flag = true;
}
if (bexec_flag){
script_h.readStr();
script_h.pushVariable();
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
bexec_int_flag = true;
script_h.readInt();
}
getpageup_flag = true;
getpagedown_flag = true;
getmclick_flag = true;
getfunction_flag = true;
}
else{
script_h.readInt();
}
ButtonLink *bl = root_button_link.next;
while( bl ){
bl->show_flag = 0;
if ( bl->button_type == ButtonLink::SPRITE_BUTTON ){
if ( bl->exbtn_ctl[0] ){
SDL_Rect check_src_rect = bl->image_rect;
SDL_Rect check_dst_rect = {0, 0, 0, 0};
decodeExbtnControl( bl->exbtn_ctl[0], &check_src_rect, &check_dst_rect );
}
else{
sprite_info[ bl->sprite_no ].visible = true;
sprite_info[ bl->sprite_no ].setCell(0);
}
}
else if ( bl->button_type == ButtonLink::TMP_SPRITE_BUTTON ){
bl->show_flag = 1;
sprite_info[ bl->sprite_no ].visible = true;
sprite_info[ bl->sprite_no ].setCell(0);
}
else if ( bl->anim[1] != NULL ){
bl->show_flag = 2;
}
dirty_rect.add( bl->image_rect );
bl = bl->next;
}
if (is_exbtn_enabled && exbtn_d_button_link.exbtn_ctl[1]){
SDL_Rect check_src_rect = screen_rect;
if (is_exbtn_enabled) decodeExbtnControl( exbtn_d_button_link.exbtn_ctl[1], &check_src_rect );
}
if ((textbtn_flag || bexec_flag) &&
(skip_mode & SKIP_NORMAL ||
(skip_mode & SKIP_TO_EOP && (textgosub_clickstr_state & 0x03) == CLICK_WAIT) ||
ctrl_pressed_status) ){
waitEventSub(0); // for checking keyup event
current_button_state.button = 0;
if (bexec_flag) current_button_state.button = -1;
if (skip_mode & SKIP_NORMAL ||
(skip_mode & SKIP_TO_EOP && (textgosub_clickstr_state & 0x03) == CLICK_WAIT))
sprintf(current_button_state.str, "SKIP");
else
sprintf(current_button_state.str, "CTRL");
}
else{
shortcut_mouse_line = 0;
skip_mode &= ~SKIP_NORMAL;
flush( refreshMode() );
event_mode = WAIT_BUTTON_MODE;
refreshMouseOverButton();
int t = -1;
if ( btntime_value >= 0 ){
if ( btntime2_flag )
event_mode |= WAIT_VOICE_MODE;
t = btntime_value;
//if ( usewheel_flag ) current_button_state.button = -5;
//else current_button_state.button = -2;
}
internal_button_timer = SDL_GetTicks();
if ( textbtn_flag ){
event_mode |= WAIT_INPUT_MODE;
if ( btntime_value == -1 ){
if ( automode_flag ){
event_mode |= WAIT_VOICE_MODE;
if ( automode_time < 0 ){
if (t == -1 || t > -automode_time * num_chars_in_sentence)
t = -automode_time * num_chars_in_sentence;
}
else{
if (t == -1 || t > automode_time)
t = automode_time;
}
//current_button_state.button = 0;
}
else if (autoclick_time > 0 &&
(t == -1 || t > autoclick_time))
t = autoclick_time;
}
}
event_mode |= WAIT_TIMER_MODE;
waitEvent(t);
skip_mode &= ~SKIP_TO_EOL;
}
btnwait_time = SDL_GetTicks() - internal_button_timer;
num_chars_in_sentence = 0;
if (bexec_flag){
setStr( &script_h.getVariableData(script_h.pushed_variable.var_no).str, current_button_state.str );
if (bexec_int_flag){
if (current_button_state.button >= 0)
script_h.setInt( &script_h.current_variable, current_button_state.button );
else
script_h.setInt( &script_h.current_variable, -1);
}
}
else{
script_h.setInt( &script_h.current_variable, current_button_state.button );
}
if ( current_button_state.button >= 1 && del_flag ){
deleteButtonLink();
}
event_mode = IDLE_EVENT_MODE;
disableGetButtonFlag();
bl = root_button_link.next;
while( bl ){
bl->show_flag = 0;
bl = bl->next;
}
return RET_CONTINUE;
}
int ONScripter::btntimeCommand()
{
bool btime_flag = false;
if ( script_h.isName( "btime" )){
btime_flag = true;
btntime2_flag = false;
}
else if ( script_h.isName( "btntime2" ) )
btntime2_flag = true;
else
btntime2_flag = false;
btntime_value = script_h.readInt();
if ( btime_flag && script_h.getEndStatus() & ScriptHandler::END_COMMA )
if (script_h.readInt() == 1) btntime2_flag = true;
return RET_CONTINUE;
}
int ONScripter::btndownCommand()
{
btndown_flag = (script_h.readInt()==1)?true:false;
return RET_CONTINUE;
}
int ONScripter::btndefCommand()
{
if (script_h.isName( "bclear" )){
}
else if (script_h.compareString("clear")){
script_h.readLabel();
}
else{
const char *buf = script_h.readStr();
btndef_info.remove();
if ( buf[0] != '\0' ){
btndef_info.setImageName( buf );
parseTaggedString( &btndef_info );
btndef_info.trans_mode = AnimationInfo::TRANS_COPY;
setupAnimationInfo( &btndef_info );
SDL_SetAlpha( btndef_info.image_surface, DEFAULT_BLIT_FLAG, SDL_ALPHA_OPAQUE );
}
}
btntime_value = -1;
transbtn_flag = false;
deleteButtonLink();
disableGetButtonFlag();
return RET_CONTINUE;
}
int ONScripter::btnCommand()
{
SDL_Rect src_rect;
ButtonLink *button = new ButtonLink();
button->no = script_h.readInt();
button->image_rect.x = script_h.readInt() * screen_ratio1 / screen_ratio2;
button->image_rect.y = script_h.readInt() * screen_ratio1 / screen_ratio2;
button->image_rect.w = script_h.readInt() * screen_ratio1 / screen_ratio2;
button->image_rect.h = script_h.readInt() * screen_ratio1 / screen_ratio2;
button->select_rect = button->image_rect;
src_rect.x = script_h.readInt() * screen_ratio1 / screen_ratio2;
src_rect.y = script_h.readInt() * screen_ratio1 / screen_ratio2;
if (btndef_info.image_surface &&
src_rect.x + button->image_rect.w > btndef_info.image_surface->w){
button->image_rect.w = btndef_info.image_surface->w - src_rect.x;
}
if (btndef_info.image_surface &&
src_rect.y + button->image_rect.h > btndef_info.image_surface->h){
button->image_rect.h = btndef_info.image_surface->h - src_rect.y;
}
src_rect.w = button->image_rect.w;
src_rect.h = button->image_rect.h;
AnimationInfo *ai = button->anim[0] = new AnimationInfo();
ai->num_of_cells = 1;
ai->trans_mode = AnimationInfo::TRANS_COPY;
ai->pos.x = button->image_rect.x;
ai->pos.y = button->image_rect.y;
ai->allocImage( button->image_rect.w, button->image_rect.h, texture_format );
ai->fill( 0, 0, 0, 0 );
ai->copySurface( btndef_info.image_surface, &src_rect );
root_button_link.insert( button );
return RET_CONTINUE;
}
int ONScripter::bspCommand()
{
int no = script_h.readInt();
if (no < 0 || no >= MAX_SPRITE_NUM ||
sprite_info[no].image_surface == NULL){
for (int i=0 ; i<3 ; i++)
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
script_h.readStr();
return RET_CONTINUE;
}
ButtonLink *bl = new ButtonLink();
root_button_link.insert( bl );
bl->button_type = ButtonLink::SPRITE_BUTTON;
bl->sprite_no = no;
bl->no = no;
if ( sprite_info[no].image_surface ||
sprite_info[no].trans_mode == AnimationInfo::TRANS_STRING )
bl->image_rect = bl->select_rect = sprite_info[no].pos;
for (int i=0 ; i<3 ; i++)
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
setStr( &bl->exbtn_ctl[i], script_h.readStr() );
return RET_CONTINUE;
}
int ONScripter::brCommand()
{
enterTextDisplayMode();
sentence_font.newLine();
current_page->add( 0x0a );
return RET_CONTINUE;
}
int ONScripter::bltCommand()
{
Sint16 dx,dy,sx,sy;
Sint16 dw,dh,sw,sh;
dx = script_h.readInt() * screen_ratio1 / screen_ratio2;
dy = script_h.readInt() * screen_ratio1 / screen_ratio2;
dw = script_h.readInt() * screen_ratio1 / screen_ratio2;
dh = script_h.readInt() * screen_ratio1 / screen_ratio2;
sx = script_h.readInt() * screen_ratio1 / screen_ratio2;
sy = script_h.readInt() * screen_ratio1 / screen_ratio2;
sw = script_h.readInt() * screen_ratio1 / screen_ratio2;
sh = script_h.readInt() * screen_ratio1 / screen_ratio2;
if (btndef_info.image_surface == NULL) return RET_CONTINUE;
if (dw == 0 || dh == 0 || sw == 0 || sh == 0) return RET_CONTINUE;
if ( sw == dw && sw > 0 && sh == dh && sh > 0 ){
SDL_Rect src_rect = {sx,sy,(Uint16)sw,(Uint16)sh};
SDL_Rect dst_rect = {dx,dy,(Uint16)dw,(Uint16)dh};
#ifdef USE_SDL_RENDERER
dst_rect.x = dst_rect.x * screen_device_width / screen_width + (device_width -screen_device_width )/2;
dst_rect.y = dst_rect.y * screen_device_width / screen_width + (device_height-screen_device_height)/2;
dst_rect.w = dst_rect.w * screen_device_width / screen_width;
dst_rect.h = dst_rect.h * screen_device_width / screen_width;
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, btndef_info.image_surface);
SDL_RenderCopy(renderer, texture, &src_rect, &dst_rect);
SDL_RenderPresent(renderer);
SDL_DestroyTexture(texture);
#else
SDL_BlitSurface( btndef_info.image_surface, &src_rect, screen_surface, &dst_rect );
SDL_UpdateRect( screen_surface, dst_rect.x, dst_rect.y, dst_rect.w, dst_rect.h );
#endif
dirty_rect.clear();
}
else{
SDL_LockSurface(accumulation_surface);
SDL_LockSurface(btndef_info.image_surface);
ONSBuf *dst_buf = (ONSBuf*)accumulation_surface->pixels;
ONSBuf *src_buf = (ONSBuf*)btndef_info.image_surface->pixels;
#if defined(BPP16)
int dst_width = accumulation_surface->pitch / 2;
int src_width = btndef_info.image_surface->pitch / 2;
#else
int dst_width = accumulation_surface->pitch / 4;
int src_width = btndef_info.image_surface->pitch / 4;
#endif
int step_y = 1;
if (dh < 0) step_y = -1;
int step_x = 1;
if (dw < 0) step_x = -1;
dst_buf += dst_width*dy;
for (int i=dy ; i!=dy+dh ; i+=step_y){
if (i < 0 || i >= screen_height) continue;
int y = sy+sh*(i-dy)/dh;
for (int j=dx ; j!=dx+dw ; j+=step_x){
if (j < 0 || j >= screen_width) continue;
int x = sx+sw*(j-dx)/dw;
if (x<0 || x>=btndef_info.image_surface->w ||
y<0 || y>=btndef_info.image_surface->h)
*(dst_buf+j) = 0;
else
*(dst_buf+j) = *(src_buf+y*src_width+x);
}
dst_buf += dst_width*step_y;
}
SDL_UnlockSurface(btndef_info.image_surface);
SDL_UnlockSurface(accumulation_surface);
SDL_Rect dst_rect;
if (dw >= 0){
dst_rect.x = dx;
dst_rect.w = dw;
}
else{
dst_rect.x = dx+dw+1;
dst_rect.w = -dw;
}
if (dh >= 0){
dst_rect.y = dy;
dst_rect.h = dh;
}
else{
dst_rect.y = dy+dh+1;
dst_rect.h = -dh;
}
flushDirect( dst_rect, REFRESH_NONE_MODE );
}
return RET_CONTINUE;
}
int ONScripter::bgcopyCommand()
{
ofscopyCommand();
setStr( &bg_info.file_name, "*bgcpy" );
bg_info.num_of_cells = 1;
bg_info.trans_mode = AnimationInfo::TRANS_COPY;
bg_info.pos.x = 0;
bg_info.pos.y = 0;
bg_info.copySurface( accumulation_surface, NULL );
return RET_CONTINUE;
}
int ONScripter::bgCommand()
{
leaveTextDisplayMode();
const char *buf;
if (script_h.compareString("white")){
buf = "white";
script_h.readLabel();
}
else if (script_h.compareString("black")){
buf = "black";
script_h.readLabel();
}
else{
buf = script_h.readStr();
}
for ( int i=0 ; i<3 ; i++ )
tachi_info[i].remove();
bg_info.remove();
setStr( &bg_info.file_name, buf );
createBackground();
dirty_rect.fill( screen_width, screen_height );
EffectLink *el = parseEffect(true);
if (setEffect(el)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripter::bdownCommand()
{
btndown_flag = true;
return RET_CONTINUE;
}
int ONScripter::barclearCommand()
{
for ( int i=0 ; i<MAX_PARAM_NUM ; i++ ) {
if ( bar_info[i] ) {
dirty_rect.add( bar_info[i]->pos );
delete bar_info[i];
bar_info[i] = NULL;
}
}
return RET_CONTINUE;
}
int ONScripter::barCommand()
{
int no = script_h.readInt();
AnimationInfo *ai = bar_info[no];
if ( ai ){
dirty_rect.add( ai->pos );
ai->remove();
}
else{
ai = bar_info[no] = new AnimationInfo();
}
ai->trans_mode = AnimationInfo::TRANS_COPY;
ai->num_of_cells = 1;
ai->setCell(0);
ai->param = script_h.readInt();
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->max_width = script_h.readInt();
ai->orig_pos.w = 0;
ai->orig_pos.h = script_h.readInt();
ai->max_param = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
const char *buf = script_h.readStr();
readColor( &ai->color, buf );
int w = 0;
if (ai->max_param != 0) w = ai->max_width * ai->param / ai->max_param;
if (ai->max_width > 0 && w > 0) ai->orig_pos.w = w;
ai->scalePosWH( screen_ratio1, screen_ratio2 );
ai->allocImage( ai->pos.w, ai->pos.h, texture_format );
ai->fill( ai->color[0], ai->color[1], ai->color[2], 0xff );
dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripter::aviCommand()
{
script_h.readStr();
const char *save_buf = script_h.saveStringBuffer();
bool click_flag = (script_h.readInt()==1)?true:false;
stopBGM( false );
if (playAVI( save_buf, click_flag )) endCommand();
// should be commented out
//repaintCommand();
return RET_CONTINUE;
}
int ONScripter::automode_timeCommand()
{
automode_time = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::autoclickCommand()
{
autoclick_time = script_h.readInt();
return RET_CONTINUE;
}
int ONScripter::amspCommand()
{
leaveTextDisplayMode();
bool amsp2_flag = false;
if (script_h.isName("amsp2")) amsp2_flag = true;
int no = script_h.readInt();
AnimationInfo *ai = NULL;
if (amsp2_flag){
ai = &sprite2_info[no];
dirty_rect.add( ai->bounding_rect );
}
else{
ai = &sprite_info[no];
dirty_rect.add( ai->pos );
}
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
ai->scalePosXY( screen_ratio1, screen_ratio2 );
if (amsp2_flag){
ai->scale_x = script_h.readInt();
ai->scale_y = script_h.readInt();
ai->rot = script_h.readInt();
ai->calcAffineMatrix();
dirty_rect.add( ai->bounding_rect );
}
else{
dirty_rect.add( ai->pos );
}
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
ai->trans = script_h.readInt();
if (ai->trans < 0) ai->trans = 0;
else if (ai->trans > 255) ai->trans = 255;
}
return RET_CONTINUE;
}
int ONScripter::allsp2resumeCommand()
{
all_sprite2_hide_flag = false;
for ( int i=0 ; i<MAX_SPRITE2_NUM ; i++ ){
AnimationInfo &ai = sprite2_info[i];
if (ai.image_surface && ai.visible)
dirty_rect.add( ai.bounding_rect );
}
return RET_CONTINUE;
}
int ONScripter::allspresumeCommand()
{
all_sprite_hide_flag = false;
for ( int i=0 ; i<3 ; i++ ){
AnimationInfo &ai = tachi_info[i];
if (ai.image_surface && ai.visible)
dirty_rect.add( ai.pos );
}
for ( int i=0 ; i<MAX_SPRITE_NUM ; i++ ){
AnimationInfo &ai = sprite_info[i];
if (ai.image_surface && ai.visible)
dirty_rect.add( ai.pos );
}
return RET_CONTINUE;
}
int ONScripter::allsp2hideCommand()
{
all_sprite2_hide_flag = true;
for ( int i=0 ; i<MAX_SPRITE2_NUM ; i++ ){
AnimationInfo *ai = &sprite2_info[i];
if (ai->image_surface && ai->visible)
dirty_rect.add( ai->bounding_rect );
}
return RET_CONTINUE;
}
int ONScripter::allsphideCommand()
{
all_sprite_hide_flag = true;
for ( int i=0 ; i<3 ; i++ ){
AnimationInfo &ai = tachi_info[i];
if (ai.image_surface && ai.visible)
dirty_rect.add( ai.pos );
}
for ( int i=0 ; i<MAX_SPRITE_NUM ; i++ ){
AnimationInfo &ai = sprite_info[i];
if (ai.image_surface && ai.visible)
dirty_rect.add( ai.pos );
}
return RET_CONTINUE;
}
void ONScripter::NSDCallCommand(int texnum, const char *str1, int proc, const char *str2)
{
if (texnum < 0 || texnum >= MAX_TEXTURE_NUM) return;
NSDLoadCommand(texnum, str1);
if (proc == 1){ // deffontd.dll, Font
FontInfo f_info = sentence_font;
f_info.rubyon_flag = false;
f_info.setTateyokoMode(0);
f_info.top_xy[0] = f_info.top_xy[1] = 0;
f_info.clear();
f_info.ttf_font[0] = NULL;
f_info.ttf_font[1] = NULL;
RubyStruct rs_old = ruby_struct;
ruby_struct.font_name = NULL;
const char *start[8];
start[0] = str2;
int i=0, num_param=1;
while(str2[i] && num_param<8) if (str2[i++]==',') start[num_param++] = str2+i;
switch(num_param){
case 8: case 7:
for (i=0 ; i<2 ; i++){
int j=0;
ruby_struct.font_size_xy[i] = 0;
while(start[4+i][j]>='0' && start[4+i][j]<='9')
ruby_struct.font_size_xy[i] = ruby_struct.font_size_xy[i]*10 + start[4+i][j++] - '0';
}
case 5:
i=0;
while(start[3][i] != ',' && start[3][i] != 0){
if (start[3][i++] == 'r'){
f_info.rubyon_flag = true;
break;
}
}
case 4: case 3:
for (i=0 ; i<2 ; i++){
int j=0;
f_info.font_size_xy[i] = 0;
while(start[i][j]>='0' && start[i][j]<='9')
f_info.font_size_xy[i] = f_info.font_size_xy[i]*10 + start[i][j++] - '0';
}
f_info.font_size_xy[0] *= 2;
f_info.pitch_xy[0] = f_info.font_size_xy[0];
f_info.pitch_xy[1] = f_info.font_size_xy[1];
}
uchar3 color = {0xff, 0xff, 0xff};
char *p = (char*)start[num_param-1], *p2 = (char*)start[num_param-1];
while(*p){
int n = script_h.enc.getBytes(*p);
if (n >= 2){
for (int i=0; i<n; i++)
*p2++ = *p++;
}
else if (*p == '%'){
p++;
if (*p == '%' || *p == '(' || *p == ')') // fix me later
*p2++ = *p++;
else if (*p == '#'){
readColor( &color, p );
p += 7;
}
}
else{
*p2++ = *p++;
}
}
*p2 = 0;
drawString(start[num_param-1], color, &f_info, false, NULL, NULL, &texture_info[texnum], false);
ruby_struct = rs_old;
}
}
void ONScripter::NSDDeleteCommand(int texnum)
{
if (texnum < 0 || texnum >= MAX_TEXTURE_NUM) return;
texture_info[texnum].remove();
}
void ONScripter::NSDLoadCommand(int texnum, const char *str)
{
if (texnum < 0 || texnum >= MAX_TEXTURE_NUM) return;
AnimationInfo *ai = &texture_info[texnum];
if (str[0] != '*'){
ai->setImageName( str );
ai->trans = -1;
}
else{
int c=1, n=0, val[6]={0}; // val[6] = {width, height, R, G, B, alpha}
while(str[c] != 0 && n<6){
if (str[c] >= '0' && str[c] <= '9')
val[n] = val[n]*10 + str[c] - '0';
if (str[c] == ',') n++;
c++;
}
char buf[32];
sprintf(buf, ">%d,%d,#%02x%02x%02x", val[0], val[1], val[2], val[3], val[4]);
ai->setImageName( buf );
ai->default_alpha = val[5];
}
ai->visible = true;
parseTaggedString( ai );
ai->trans_mode = AnimationInfo::TRANS_ALPHA;
setupAnimationInfo( ai );
}
void ONScripter::NSDPresentRectCommand(int x1, int y1, int x2, int y2)
{
SDL_Rect clip_src;
clip_src.x = x1;
clip_src.y = y1;
clip_src.w = x2-x1+1;
clip_src.h = y2-y1+1;
SDL_Rect clip;
clip.x = clip.y = 0;
clip.w = accumulation_surface->w;
clip.h = accumulation_surface->h;
if ( AnimationInfo::doClipping( &clip, &clip_src ) ) return;
for (int i=MAX_TEXTURE_NUM-1 ; i>0 ; i--)
if (texture_info[i].image_surface && texture_info[i].visible)
drawTaggedSurface( accumulation_surface, &texture_info[i], clip );
flushDirect(clip, REFRESH_NONE_MODE);
}
void ONScripter::NSDSp2Command(int texnum, int dcx, int dcy, int sx, int sy, int w, int h,
int xs, int ys, int rot, int alpha)
{
if (texnum < 0 || texnum >= MAX_TEXTURE_NUM) return;
AnimationInfo *ai = &texture_info[texnum];
ai->orig_pos.x = dcx;
ai->orig_pos.y = dcy;
ai->scalePosXY( screen_ratio1, screen_ratio2 );
ai->scale_x = xs;
ai->scale_y = ys;
ai->rot = rot;
ai->trans = alpha;
ai->affine_pos.x = sx*screen_ratio1/screen_ratio2;
ai->affine_pos.y = sy*screen_ratio1/screen_ratio2;
ai->affine_pos.w = w*screen_ratio1/screen_ratio2;
ai->affine_pos.h = h*screen_ratio1/screen_ratio2;
ai->calcAffineMatrix();
ai->affine_flag = true;
}
void ONScripter::NSDSetSpriteCommand(int spnum, int texnum, const char *tag)
{
if (spnum < 0 || spnum >= MAX_SPRITE_NUM) return;
if (texnum < 0 || texnum >= MAX_TEXTURE_NUM) return;
AnimationInfo *ais = &sprite_info[spnum];
AnimationInfo *ait = &texture_info[texnum];
*ais = *ait;
ais->visible = true;
char buf[256];
if (tag)
sprintf(buf, "%s%s", tag, ait->file_name);
else
sprintf(buf, ":a;%s", ait->file_name);
ais->setImageName(buf);
parseTaggedString(ais);
if (ais->affine_flag){
ais->orig_pos.x = ait->orig_pos.x;
if (ait->num_of_cells > 0)
ais->orig_pos.x -= ait->orig_pos.w/ait->num_of_cells/2;
else
ais->orig_pos.x -= ait->orig_pos.w/2;
ais->orig_pos.y = ait->orig_pos.y - ait->orig_pos.h/2;
ais->scalePosXY( screen_ratio1, screen_ratio2 );
ais->affine_flag = false;
}
}
void ONScripter::stopSMPEG()
{
#if defined(USE_SMPEG)
if (layer_smpeg_sample){
SMPEG_stop( layer_smpeg_sample );
SMPEG_delete( layer_smpeg_sample );
layer_smpeg_sample = NULL;
}
if (layer_smpeg_buffer){
delete[] layer_smpeg_buffer;
layer_smpeg_buffer = NULL;
}
#endif
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/weimingtom/Onscripter-Official.git
git@gitee.com:weimingtom/Onscripter-Official.git
weimingtom
Onscripter-Official
Onscripter-Official
master

搜索帮助