script.c 180 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973
  1. // $Id: script.c 148 2004-09-30 14:05:37Z MouseJstr $
  2. //#define DEBUG_FUNCIN
  3. //#define DEBUG_DISP
  4. //#define DEBUG_RUN
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #ifndef _WIN32
  10. #include <sys/time.h>
  11. #endif
  12. #include <time.h>
  13. #include "socket.h"
  14. #include "timer.h"
  15. #include "malloc.h"
  16. #include "lock.h"
  17. #include "map.h"
  18. #include "clif.h"
  19. #include "chrif.h"
  20. #include "itemdb.h"
  21. #include "pc.h"
  22. #include "script.h"
  23. #include "storage.h"
  24. #include "mob.h"
  25. #include "npc.h"
  26. #include "pet.h"
  27. #include "intif.h"
  28. #include "db.h"
  29. #include "skill.h"
  30. #include "chat.h"
  31. #include "battle.h"
  32. #include "party.h"
  33. #include "guild.h"
  34. #include "lock.h"
  35. #include "atcommand.h"
  36. #include "log.h"
  37. #ifdef MEMWATCH
  38. #include "memwatch.h"
  39. #endif
  40. #define SCRIPT_BLOCK_SIZE 256
  41. enum { LABEL_NEXTLINE=1,LABEL_START };
  42. static unsigned char * script_buf;
  43. static int script_pos,script_size;
  44. char *str_buf;
  45. int str_pos,str_size;
  46. static struct {
  47. int type;
  48. int str;
  49. int backpatch;
  50. int label;
  51. int (*func)();
  52. int val;
  53. int next;
  54. } *str_data;
  55. int str_num=LABEL_START,str_data_size;
  56. int str_hash[16];
  57. static struct dbt *mapreg_db=NULL;
  58. static struct dbt *mapregstr_db=NULL;
  59. static int mapreg_dirty=-1;
  60. char mapreg_txt[256]="save/mapreg.txt";
  61. #define MAPREG_AUTOSAVE_INTERVAL (10*1000)
  62. static struct dbt *scriptlabel_db=NULL;
  63. static struct dbt *userfunc_db=NULL;
  64. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  65. struct dbt* script_get_userfunc_db(){ if(!userfunc_db) userfunc_db=strdb_init(50); return userfunc_db; }
  66. int scriptlabel_final(void *k,void *d,va_list ap){ return 0; }
  67. static char pos[11][100] = {"頭","体","左手","右手","ローブ","靴","アクセサリー1","アクセサリー2","頭2","頭3","装着していない"};
  68. static struct Script_Config {
  69. int warn_func_no_comma;
  70. int warn_cmd_no_comma;
  71. int warn_func_mismatch_paramnum;
  72. int warn_cmd_mismatch_paramnum;
  73. int check_cmdcount;
  74. int check_gotocount;
  75. } script_config;
  76. static int parse_cmd_if=0;
  77. static int parse_cmd;
  78. /*==========================================
  79. * ローカルプロトタイプ宣言 (必要な物のみ)
  80. *------------------------------------------
  81. */
  82. unsigned char* parse_subexpr(unsigned char *,int);
  83. int buildin_mes(struct script_state *st);
  84. int buildin_goto(struct script_state *st);
  85. int buildin_callsub(struct script_state *st);
  86. int buildin_callfunc(struct script_state *st);
  87. int buildin_return(struct script_state *st);
  88. int buildin_getarg(struct script_state *st);
  89. int buildin_next(struct script_state *st);
  90. int buildin_close(struct script_state *st);
  91. int buildin_close2(struct script_state *st);
  92. int buildin_menu(struct script_state *st);
  93. int buildin_rand(struct script_state *st);
  94. int buildin_warp(struct script_state *st);
  95. int buildin_areawarp(struct script_state *st);
  96. int buildin_heal(struct script_state *st);
  97. int buildin_itemheal(struct script_state *st);
  98. int buildin_percentheal(struct script_state *st);
  99. int buildin_jobchange(struct script_state *st);
  100. int buildin_input(struct script_state *st);
  101. int buildin_setlook(struct script_state *st);
  102. int buildin_set(struct script_state *st);
  103. int buildin_setarray(struct script_state *st);
  104. int buildin_cleararray(struct script_state *st);
  105. int buildin_copyarray(struct script_state *st);
  106. int buildin_getarraysize(struct script_state *st);
  107. int buildin_deletearray(struct script_state *st);
  108. int buildin_getelementofarray(struct script_state *st);
  109. int buildin_if(struct script_state *st);
  110. int buildin_getitem(struct script_state *st);
  111. int buildin_getitem2(struct script_state *st);
  112. int buildin_makeitem(struct script_state *st);
  113. int buildin_delitem(struct script_state *st);
  114. int buildin_viewpoint(struct script_state *st);
  115. int buildin_countitem(struct script_state *st);
  116. int buildin_checkweight(struct script_state *st);
  117. int buildin_readparam(struct script_state *st);
  118. int buildin_getcharid(struct script_state *st);
  119. int buildin_getpartyname(struct script_state *st);
  120. int buildin_getpartymember(struct script_state *st);
  121. int buildin_getguildname(struct script_state *st);
  122. int buildin_getguildmaster(struct script_state *st);
  123. int buildin_getguildmasterid(struct script_state *st);
  124. int buildin_strcharinfo(struct script_state *st);
  125. int buildin_getequipid(struct script_state *st);
  126. int buildin_getequipname(struct script_state *st);
  127. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  128. int buildin_repair(struct script_state *st); // [Valaris]
  129. int buildin_getequipisequiped(struct script_state *st);
  130. int buildin_getequipisenableref(struct script_state *st);
  131. int buildin_getequipisidentify(struct script_state *st);
  132. int buildin_getequiprefinerycnt(struct script_state *st);
  133. int buildin_getequipweaponlv(struct script_state *st);
  134. int buildin_getequippercentrefinery(struct script_state *st);
  135. int buildin_successrefitem(struct script_state *st);
  136. int buildin_failedrefitem(struct script_state *st);
  137. int buildin_cutin(struct script_state *st);
  138. int buildin_cutincard(struct script_state *st);
  139. int buildin_statusup(struct script_state *st);
  140. int buildin_statusup2(struct script_state *st);
  141. int buildin_bonus(struct script_state *st);
  142. int buildin_bonus2(struct script_state *st);
  143. int buildin_bonus3(struct script_state *st);
  144. int buildin_skill(struct script_state *st);
  145. int buildin_addtoskill(struct script_state *st); // [Valaris]
  146. int buildin_guildskill(struct script_state *st);
  147. int buildin_getskilllv(struct script_state *st);
  148. int buildin_getgdskilllv(struct script_state *st);
  149. int buildin_basicskillcheck(struct script_state *st);
  150. int buildin_getgmlevel(struct script_state *st);
  151. int buildin_end(struct script_state *st);
  152. int buildin_checkoption(struct script_state *st);
  153. int buildin_setoption(struct script_state *st);
  154. int buildin_setcart(struct script_state *st);
  155. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  156. int buildin_setfalcon(struct script_state *st);
  157. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  158. int buildin_setriding(struct script_state *st);
  159. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  160. int buildin_savepoint(struct script_state *st);
  161. int buildin_gettimetick(struct script_state *st);
  162. int buildin_gettime(struct script_state *st);
  163. int buildin_gettimestr(struct script_state *st);
  164. int buildin_openstorage(struct script_state *st);
  165. int buildin_guildopenstorage(struct script_state *st);
  166. int buildin_itemskill(struct script_state *st);
  167. int buildin_produce(struct script_state *st);
  168. int buildin_monster(struct script_state *st);
  169. int buildin_areamonster(struct script_state *st);
  170. int buildin_killmonster(struct script_state *st);
  171. int buildin_killmonsterall(struct script_state *st);
  172. int buildin_doevent(struct script_state *st);
  173. int buildin_donpcevent(struct script_state *st);
  174. int buildin_addtimer(struct script_state *st);
  175. int buildin_deltimer(struct script_state *st);
  176. int buildin_addtimercount(struct script_state *st);
  177. int buildin_initnpctimer(struct script_state *st);
  178. int buildin_stopnpctimer(struct script_state *st);
  179. int buildin_startnpctimer(struct script_state *st);
  180. int buildin_setnpctimer(struct script_state *st);
  181. int buildin_getnpctimer(struct script_state *st);
  182. int buildin_announce(struct script_state *st);
  183. int buildin_mapannounce(struct script_state *st);
  184. int buildin_areaannounce(struct script_state *st);
  185. int buildin_getusers(struct script_state *st);
  186. int buildin_getmapusers(struct script_state *st);
  187. int buildin_getareausers(struct script_state *st);
  188. int buildin_getareadropitem(struct script_state *st);
  189. int buildin_enablenpc(struct script_state *st);
  190. int buildin_disablenpc(struct script_state *st);
  191. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  192. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  193. int buildin_hideoffnpc(struct script_state *st);
  194. int buildin_hideonnpc(struct script_state *st);
  195. int buildin_sc_start(struct script_state *st);
  196. int buildin_sc_start2(struct script_state *st);
  197. int buildin_sc_end(struct script_state *st);
  198. int buildin_getscrate(struct script_state *st);
  199. int buildin_debugmes(struct script_state *st);
  200. int buildin_catchpet(struct script_state *st);
  201. int buildin_birthpet(struct script_state *st);
  202. int buildin_resetlvl(struct script_state *st);
  203. int buildin_resetstatus(struct script_state *st);
  204. int buildin_resetskill(struct script_state *st);
  205. int buildin_changebase(struct script_state *st);
  206. int buildin_changesex(struct script_state *st);
  207. int buildin_waitingroom(struct script_state *st);
  208. int buildin_delwaitingroom(struct script_state *st);
  209. int buildin_enablewaitingroomevent(struct script_state *st);
  210. int buildin_disablewaitingroomevent(struct script_state *st);
  211. int buildin_getwaitingroomstate(struct script_state *st);
  212. int buildin_warpwaitingpc(struct script_state *st);
  213. int buildin_attachrid(struct script_state *st);
  214. int buildin_detachrid(struct script_state *st);
  215. int buildin_isloggedin(struct script_state *st);
  216. int buildin_setmapflagnosave(struct script_state *st);
  217. int buildin_setmapflag(struct script_state *st);
  218. int buildin_removemapflag(struct script_state *st);
  219. int buildin_pvpon(struct script_state *st);
  220. int buildin_pvpoff(struct script_state *st);
  221. int buildin_gvgon(struct script_state *st);
  222. int buildin_gvgoff(struct script_state *st);
  223. int buildin_emotion(struct script_state *st);
  224. int buildin_maprespawnguildid(struct script_state *st);
  225. int buildin_agitstart(struct script_state *st); // <Agit>
  226. int buildin_agitend(struct script_state *st);
  227. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  228. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  229. int buildin_getcastlename(struct script_state *st);
  230. int buildin_getcastledata(struct script_state *st);
  231. int buildin_setcastledata(struct script_state *st);
  232. int buildin_requestguildinfo(struct script_state *st);
  233. int buildin_getequipcardcnt(struct script_state *st);
  234. int buildin_successremovecards(struct script_state *st);
  235. int buildin_failedremovecards(struct script_state *st);
  236. int buildin_marriage(struct script_state *st);
  237. int buildin_wedding_effect(struct script_state *st);
  238. int buildin_divorce(struct script_state *st);
  239. int buildin_getitemname(struct script_state *st);
  240. int buildin_makepet(struct script_state *st);
  241. int buildin_getexp(struct script_state *st);
  242. int buildin_getinventorylist(struct script_state *st);
  243. int buildin_getskilllist(struct script_state *st);
  244. int buildin_clearitem(struct script_state *st);
  245. int buildin_classchange(struct script_state *st);
  246. int buildin_misceffect(struct script_state *st);
  247. int buildin_soundeffect(struct script_state *st);
  248. int buildin_setcastledata(struct script_state *st);
  249. int buildin_mapwarp(struct script_state *st);
  250. int buildin_inittimer(struct script_state *st);
  251. int buildin_stoptimer(struct script_state *st);
  252. int buildin_cmdothernpc(struct script_state *st);
  253. int buildin_mobcount(struct script_state *st);
  254. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  255. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  256. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  257. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  258. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  259. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  260. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  261. int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  262. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Valaris]
  263. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  264. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  265. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  266. int buildin_nude(struct script_state *st); // nude [Valaris]
  267. int buildin_gmcommand(struct script_state *st); // [MouseJstr]
  268. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  269. int buildin_message(struct script_state *st); // [MouseJstr]
  270. int buildin_npctalk(struct script_state *st); // [Valaris]
  271. int buildin_hasitems(struct script_state *st); // [Valaris]
  272. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  273. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  274. int buildin_npcspeed(struct script_state *st); // [Valaris]
  275. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  276. int buildin_npcstop(struct script_state *st); // [Valaris]
  277. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  278. void push_val(struct script_stack *stack,int type,int val);
  279. int run_func(struct script_state *st);
  280. int mapreg_setreg(int num,int val);
  281. int mapreg_setregstr(int num,const char *str);
  282. struct {
  283. int (*func)();
  284. char *name;
  285. char *arg;
  286. } buildin_func[]={
  287. {buildin_mes,"mes","s"},
  288. {buildin_next,"next",""},
  289. {buildin_close,"close",""},
  290. {buildin_close2,"close2",""},
  291. {buildin_menu,"menu","*"},
  292. {buildin_goto,"goto","l"},
  293. {buildin_callsub,"callsub","i*"},
  294. {buildin_callfunc,"callfunc","s*"},
  295. {buildin_return,"return","*"},
  296. {buildin_getarg,"getarg","i"},
  297. {buildin_jobchange,"jobchange","i*"},
  298. {buildin_input,"input","*"},
  299. {buildin_warp,"warp","sii"},
  300. {buildin_areawarp,"areawarp","siiiisii"},
  301. {buildin_setlook,"setlook","ii"},
  302. {buildin_set,"set","ii"},
  303. {buildin_setarray,"setarray","ii*"},
  304. {buildin_cleararray,"cleararray","iii"},
  305. {buildin_copyarray,"copyarray","iii"},
  306. {buildin_getarraysize,"getarraysize","i"},
  307. {buildin_deletearray,"deletearray","ii"},
  308. {buildin_getelementofarray,"getelementofarray","ii"},
  309. {buildin_if,"if","i*"},
  310. {buildin_getitem,"getitem","ii**"},
  311. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  312. {buildin_makeitem,"makeitem","iisii"},
  313. {buildin_delitem,"delitem","ii"},
  314. {buildin_cutin,"cutin","si"},
  315. {buildin_cutincard,"cutincard","i"},
  316. {buildin_viewpoint,"viewpoint","iiiii"},
  317. {buildin_heal,"heal","ii"},
  318. {buildin_itemheal,"itemheal","ii"},
  319. {buildin_percentheal,"percentheal","ii"},
  320. {buildin_rand,"rand","i*"},
  321. {buildin_countitem,"countitem","i"},
  322. {buildin_checkweight,"checkweight","ii"},
  323. {buildin_readparam,"readparam","i*"},
  324. {buildin_getcharid,"getcharid","i*"},
  325. {buildin_getpartyname,"getpartyname","i"},
  326. {buildin_getpartymember,"getpartymember","i"},
  327. {buildin_getguildname,"getguildname","i"},
  328. {buildin_getguildmaster,"getguildmaster","i"},
  329. {buildin_getguildmasterid,"getguildmasterid","i"},
  330. {buildin_strcharinfo,"strcharinfo","i"},
  331. {buildin_getequipid,"getequipid","i"},
  332. {buildin_getequipname,"getequipname","i"},
  333. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  334. {buildin_repair,"repair","i"}, // [Valaris]
  335. {buildin_getequipisequiped,"getequipisequiped","i"},
  336. {buildin_getequipisenableref,"getequipisenableref","i"},
  337. {buildin_getequipisidentify,"getequipisidentify","i"},
  338. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  339. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  340. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  341. {buildin_successrefitem,"successrefitem","i"},
  342. {buildin_failedrefitem,"failedrefitem","i"},
  343. {buildin_statusup,"statusup","i"},
  344. {buildin_statusup2,"statusup2","ii"},
  345. {buildin_bonus,"bonus","ii"},
  346. {buildin_bonus2,"bonus2","iii"},
  347. {buildin_bonus3,"bonus3","iiii"},
  348. {buildin_skill,"skill","ii*"},
  349. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  350. {buildin_guildskill,"guildskill","ii"},
  351. {buildin_getskilllv,"getskilllv","i"},
  352. {buildin_getgdskilllv,"getgdskilllv","ii"},
  353. {buildin_basicskillcheck,"basicskillcheck","*"},
  354. {buildin_getgmlevel,"getgmlevel","*"},
  355. {buildin_end,"end",""},
  356. {buildin_end,"break",""},
  357. {buildin_checkoption,"checkoption","i"},
  358. {buildin_setoption,"setoption","i"},
  359. {buildin_setcart,"setcart",""},
  360. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  361. {buildin_setfalcon,"setfalcon",""},
  362. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  363. {buildin_setriding,"setriding",""},
  364. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  365. {buildin_savepoint,"save","sii"},
  366. {buildin_savepoint,"savepoint","sii"},
  367. {buildin_gettimetick,"gettimetick","i"},
  368. {buildin_gettime,"gettime","i"},
  369. {buildin_gettimestr,"gettimestr","si"},
  370. {buildin_openstorage,"openstorage",""},
  371. {buildin_guildopenstorage,"guildopenstorage","*"},
  372. {buildin_itemskill,"itemskill","iis"},
  373. {buildin_produce,"produce","i"},
  374. {buildin_monster,"monster","siisii*"},
  375. {buildin_areamonster,"areamonster","siiiisii*"},
  376. {buildin_killmonster,"killmonster","ss"},
  377. {buildin_killmonsterall,"killmonsterall","s"},
  378. {buildin_doevent,"doevent","s"},
  379. {buildin_donpcevent,"donpcevent","s"},
  380. {buildin_addtimer,"addtimer","is"},
  381. {buildin_deltimer,"deltimer","s"},
  382. {buildin_addtimercount,"addtimercount","si"},
  383. {buildin_initnpctimer,"initnpctimer","*"},
  384. {buildin_stopnpctimer,"stopnpctimer","*"},
  385. {buildin_startnpctimer,"startnpctimer","*"},
  386. {buildin_setnpctimer,"setnpctimer","*"},
  387. {buildin_getnpctimer,"getnpctimer","i*"},
  388. {buildin_announce,"announce","si"},
  389. {buildin_mapannounce,"mapannounce","ssi"},
  390. {buildin_areaannounce,"areaannounce","siiiisi"},
  391. {buildin_getusers,"getusers","i"},
  392. {buildin_getmapusers,"getmapusers","s"},
  393. {buildin_getareausers,"getareausers","siiii"},
  394. {buildin_getareadropitem,"getareadropitem","siiiii"},
  395. {buildin_enablenpc,"enablenpc","s"},
  396. {buildin_disablenpc,"disablenpc","s"},
  397. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  398. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  399. {buildin_hideoffnpc,"hideoffnpc","s"},
  400. {buildin_hideonnpc,"hideonnpc","s"},
  401. {buildin_sc_start,"sc_start","iii*"},
  402. {buildin_sc_start2,"sc_start2","iiii*"},
  403. {buildin_sc_end,"sc_end","i"},
  404. {buildin_getscrate,"getscrate","ii*"},
  405. {buildin_debugmes,"debugmes","s"},
  406. {buildin_catchpet,"pet","i"},
  407. {buildin_birthpet,"bpet",""},
  408. {buildin_resetlvl,"resetlvl","i"},
  409. {buildin_resetstatus,"resetstatus",""},
  410. {buildin_resetskill,"resetskill",""},
  411. {buildin_changebase,"changebase","i"},
  412. {buildin_changesex,"changesex",""},
  413. {buildin_waitingroom,"waitingroom","si*"},
  414. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  415. {buildin_delwaitingroom,"delwaitingroom","*"},
  416. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  417. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  418. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  419. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  420. {buildin_attachrid,"attachrid","i"},
  421. {buildin_detachrid,"detachrid",""},
  422. {buildin_isloggedin,"isloggedin","i"},
  423. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  424. {buildin_setmapflag,"setmapflag","si"},
  425. {buildin_removemapflag,"removemapflag","si"},
  426. {buildin_pvpon,"pvpon","s"},
  427. {buildin_pvpoff,"pvpoff","s"},
  428. {buildin_gvgon,"gvgon","s"},
  429. {buildin_gvgoff,"gvgoff","s"},
  430. {buildin_emotion,"emotion","i"},
  431. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  432. {buildin_agitstart,"agitstart",""}, // <Agit>
  433. {buildin_agitend,"agitend",""},
  434. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  435. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  436. {buildin_getcastlename,"getcastlename","s"},
  437. {buildin_getcastledata,"getcastledata","si*"},
  438. {buildin_setcastledata,"setcastledata","sii"},
  439. {buildin_requestguildinfo,"requestguildinfo","i*"},
  440. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  441. {buildin_successremovecards,"successremovecards","i"},
  442. {buildin_failedremovecards,"failedremovecards","ii"},
  443. {buildin_marriage,"marriage","s"},
  444. {buildin_wedding_effect,"wedding",""},
  445. {buildin_divorce,"divorce",""},
  446. {buildin_getitemname,"getitemname","i"},
  447. {buildin_makepet,"makepet","i"},
  448. {buildin_getexp,"getexp","ii"},
  449. {buildin_getinventorylist,"getinventorylist",""},
  450. {buildin_getskilllist,"getskilllist",""},
  451. {buildin_clearitem,"clearitem",""},
  452. {buildin_classchange,"classchange","ii"},
  453. {buildin_misceffect,"misceffect","i"},
  454. {buildin_soundeffect,"soundeffect","si"},
  455. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  456. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  457. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  458. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  459. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  460. {buildin_petloot,"petloot","i"}, // [Valaris]
  461. {buildin_petheal,"petheal","iii"}, // [Valaris]
  462. {buildin_petmag,"petmag","iiii"}, // [Valaris]
  463. {buildin_petskillattack,"petskillattack","iiii"}, // [Valaris]
  464. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  465. {buildin_specialeffect,"specialeffect","i"}, // npc skill effect [Valaris]
  466. {buildin_specialeffect2,"specialeffect2","i"}, // skill effect on players[Valaris]
  467. {buildin_nude,"nude",""}, // nude command [Valaris]
  468. {buildin_mapwarp,"mapwarp","ssii"}, // Added by RoVeRT
  469. {buildin_inittimer,"inittimer",""},
  470. {buildin_stoptimer,"stoptimer",""},
  471. {buildin_cmdothernpc,"cmdothernpc","ss"},
  472. {buildin_gmcommand,"gmcommand","*"}, // [MouseJstr]
  473. // {buildin_movenpc,"movenpc","siis"}, // [MouseJstr]
  474. {buildin_message,"message","s*"}, // [MouseJstr]
  475. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  476. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  477. {buildin_mobcount,"mobcount","ss"},
  478. {buildin_getlook,"getlook","i"},
  479. {buildin_getsavepoint,"getsavepoint","i"},
  480. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  481. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  482. {buildin_npcstop,"npcstop",""}, // [Valaris]
  483. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  484. {NULL,NULL,NULL},
  485. };
  486. int buildin_message(struct script_state *st); // [MouseJstr]
  487. enum {
  488. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  489. C_NAME,C_EOL, C_RETINFO,
  490. C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  491. C_XOR,C_OR,C_AND,C_ADD,C_SUB,C_MUL,C_DIV,C_MOD,C_NEG,C_LNOT,C_NOT,C_R_SHIFT,C_L_SHIFT
  492. };
  493. /*==========================================
  494. * 文字列のハッシュを計算
  495. *------------------------------------------
  496. */
  497. static int calc_hash(const unsigned char *p)
  498. {
  499. int h=0;
  500. while(*p){
  501. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  502. h+=*p++;
  503. }
  504. return h&15;
  505. }
  506. /*==========================================
  507. * str_dataの中に名前があるか検索する
  508. *------------------------------------------
  509. */
  510. // 既存のであれば番号、無ければ-1
  511. static int search_str(const unsigned char *p)
  512. {
  513. int i;
  514. i=str_hash[calc_hash(p)];
  515. while(i){
  516. if(strcmp(str_buf+str_data[i].str,p)==0){
  517. return i;
  518. }
  519. i=str_data[i].next;
  520. }
  521. return -1;
  522. }
  523. /*==========================================
  524. * str_dataに名前を登録
  525. *------------------------------------------
  526. */
  527. // 既存のであれば番号、無ければ登録して新規番号
  528. static int add_str(const unsigned char *p)
  529. {
  530. int i;
  531. char *lowcase;
  532. lowcase=strdup(p);
  533. for(i=0;lowcase[i];i++)
  534. lowcase[i]=tolower(lowcase[i]);
  535. if((i=search_str(lowcase))>=0){
  536. free(lowcase);
  537. return i;
  538. }
  539. free(lowcase);
  540. i=calc_hash(p);
  541. if(str_hash[i]==0){
  542. str_hash[i]=str_num;
  543. } else {
  544. i=str_hash[i];
  545. for(;;){
  546. if(strcmp(str_buf+str_data[i].str,p)==0){
  547. return i;
  548. }
  549. if(str_data[i].next==0)
  550. break;
  551. i=str_data[i].next;
  552. }
  553. str_data[i].next=str_num;
  554. }
  555. if(str_num>=str_data_size){
  556. str_data_size+=128;
  557. str_data=aRealloc(str_data,sizeof(str_data[0])*str_data_size);
  558. memset(str_data + (str_data_size - 128), '\0', 128);
  559. }
  560. while(str_pos+strlen(p)+1>=str_size){
  561. str_size+=256;
  562. str_buf=(char *)aRealloc(str_buf,str_size);
  563. memset(str_buf + (str_size - 256), '\0', 256);
  564. }
  565. strcpy(str_buf+str_pos,p);
  566. str_data[str_num].type=C_NOP;
  567. str_data[str_num].str=str_pos;
  568. str_data[str_num].next=0;
  569. str_data[str_num].func=NULL;
  570. str_data[str_num].backpatch=-1;
  571. str_data[str_num].label=-1;
  572. str_pos+=strlen(p)+1;
  573. return str_num++;
  574. }
  575. /*==========================================
  576. * スクリプトバッファサイズの確認と拡張
  577. *------------------------------------------
  578. */
  579. static void check_script_buf(int size)
  580. {
  581. if(script_pos+size>=script_size){
  582. script_size+=SCRIPT_BLOCK_SIZE;
  583. script_buf=(char *)aRealloc(script_buf,script_size);
  584. memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  585. SCRIPT_BLOCK_SIZE);
  586. }
  587. }
  588. /*==========================================
  589. * スクリプトバッファに1バイト書き込む
  590. *------------------------------------------
  591. */
  592. static void add_scriptb(int a)
  593. {
  594. check_script_buf(1);
  595. script_buf[script_pos++]=a;
  596. }
  597. /*==========================================
  598. * スクリプトバッファにデータタイプを書き込む
  599. *------------------------------------------
  600. */
  601. static void add_scriptc(int a)
  602. {
  603. while(a>=0x40){
  604. add_scriptb((a&0x3f)|0x40);
  605. a=(a-0x40)>>6;
  606. }
  607. add_scriptb(a&0x3f);
  608. }
  609. /*==========================================
  610. * スクリプトバッファに整数を書き込む
  611. *------------------------------------------
  612. */
  613. static void add_scripti(int a)
  614. {
  615. while(a>=0x40){
  616. add_scriptb(a|0xc0);
  617. a=(a-0x40)>>6;
  618. }
  619. add_scriptb(a|0x80);
  620. }
  621. /*==========================================
  622. * スクリプトバッファにラベル/変数/関数を書き込む
  623. *------------------------------------------
  624. */
  625. // 最大16Mまで
  626. static void add_scriptl(int l)
  627. {
  628. int backpatch = str_data[l].backpatch;
  629. switch(str_data[l].type){
  630. case C_POS:
  631. add_scriptc(C_POS);
  632. add_scriptb(str_data[l].label);
  633. add_scriptb(str_data[l].label>>8);
  634. add_scriptb(str_data[l].label>>16);
  635. break;
  636. case C_NOP:
  637. // ラベルの可能性があるのでbackpatch用データ埋め込み
  638. add_scriptc(C_NAME);
  639. str_data[l].backpatch=script_pos;
  640. add_scriptb(backpatch);
  641. add_scriptb(backpatch>>8);
  642. add_scriptb(backpatch>>16);
  643. break;
  644. case C_INT:
  645. add_scripti(str_data[l].val);
  646. break;
  647. default:
  648. // もう他の用途と確定してるので数字をそのまま
  649. add_scriptc(C_NAME);
  650. add_scriptb(l);
  651. add_scriptb(l>>8);
  652. add_scriptb(l>>16);
  653. break;
  654. }
  655. }
  656. /*==========================================
  657. * ラベルを解決する
  658. *------------------------------------------
  659. */
  660. void set_label(int l,int pos)
  661. {
  662. int i,next;
  663. str_data[l].type=C_POS;
  664. str_data[l].label=pos;
  665. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  666. next=(*(int*)(script_buf+i)) & 0x00ffffff;
  667. script_buf[i-1]=C_POS;
  668. script_buf[i]=pos;
  669. script_buf[i+1]=pos>>8;
  670. script_buf[i+2]=pos>>16;
  671. i=next;
  672. }
  673. }
  674. /*==========================================
  675. * スペース/コメント読み飛ばし
  676. *------------------------------------------
  677. */
  678. static unsigned char *skip_space(unsigned char *p)
  679. {
  680. while(1){
  681. while(isspace(*p))
  682. p++;
  683. if(p[0]=='/' && p[1]=='/'){
  684. while(*p && *p!='\n')
  685. p++;
  686. } else if(p[0]=='/' && p[1]=='*'){
  687. p++;
  688. while(*p && (p[-1]!='*' || p[0]!='/'))
  689. p++;
  690. if(*p) p++;
  691. } else
  692. break;
  693. }
  694. return p;
  695. }
  696. /*==========================================
  697. * 1単語スキップ
  698. *------------------------------------------
  699. */
  700. static unsigned char *skip_word(unsigned char *p)
  701. {
  702. // prefix
  703. if(*p=='$') p++; // MAP鯖内共有変数用
  704. if(*p=='@') p++; // 一時的変数用(like weiss)
  705. if(*p=='#') p++; // account変数用
  706. if(*p=='#') p++; // ワールドaccount変数用
  707. if(*p=='l') p++; // 一時的変数用(like weiss)
  708. while(isalnum(*p)||*p=='_'|| *p>=0x81)
  709. if(*p>=0x81 && p[1]){
  710. p+=2;
  711. } else
  712. p++;
  713. // postfix
  714. if(*p=='$') p++; // 文字列変数
  715. return p;
  716. }
  717. static unsigned char *startptr;
  718. static int startline;
  719. /*==========================================
  720. * エラーメッセージ出力
  721. *------------------------------------------
  722. */
  723. static void disp_error_message(const char *mes,const unsigned char *pos)
  724. {
  725. int line,c=0,i;
  726. unsigned char *p,*linestart,*lineend;
  727. for(line=startline,p=startptr;p && *p;line++){
  728. linestart=p;
  729. lineend=strchr(p,'\n');
  730. if(lineend){
  731. c=*lineend;
  732. *lineend=0;
  733. }
  734. if(lineend==NULL || pos<lineend){
  735. printf("%s line %d : ",mes,line);
  736. for(i=0;(linestart[i]!='\r') && (linestart[i]!='\n') && linestart[i];i++){
  737. if(linestart+i!=pos)
  738. printf("%c",linestart[i]);
  739. else
  740. printf("\'%c\'",linestart[i]);
  741. }
  742. printf("\a\n");
  743. if(lineend)
  744. *lineend=c;
  745. return;
  746. }
  747. *lineend=c;
  748. p=lineend+1;
  749. }
  750. }
  751. /*==========================================
  752. * 項の解析
  753. *------------------------------------------
  754. */
  755. unsigned char* parse_simpleexpr(unsigned char *p)
  756. {
  757. int i;
  758. p=skip_space(p);
  759. #ifdef DEBUG_FUNCIN
  760. if(battle_config.etc_log)
  761. printf("parse_simpleexpr %s\n",p);
  762. #endif
  763. if(*p==';' || *p==','){
  764. disp_error_message("unexpected expr end",p);
  765. exit(1);
  766. }
  767. if(*p=='('){
  768. p=parse_subexpr(p+1,-1);
  769. p=skip_space(p);
  770. if((*p++)!=')'){
  771. disp_error_message("unmatch ')'",p);
  772. exit(1);
  773. }
  774. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  775. char *np;
  776. i=strtoul(p,&np,0);
  777. add_scripti(i);
  778. p=np;
  779. } else if(*p=='"'){
  780. add_scriptc(C_STR);
  781. p++;
  782. while(*p && *p!='"'){
  783. if(p[-1]<=0x7e && *p=='\\')
  784. p++;
  785. else if(*p=='\n'){
  786. disp_error_message("unexpected newline @ string",p);
  787. exit(1);
  788. }
  789. add_scriptb(*p++);
  790. }
  791. if(!*p){
  792. disp_error_message("unexpected eof @ string",p);
  793. exit(1);
  794. }
  795. add_scriptb(0);
  796. p++; //'"'
  797. } else {
  798. int c,l;
  799. char *p2;
  800. // label , register , function etc
  801. if(skip_word(p)==p){
  802. disp_error_message("unexpected character",p);
  803. exit(1);
  804. }
  805. p2=skip_word(p);
  806. c=*p2; *p2=0; // 名前をadd_strする
  807. l=add_str(p);
  808. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  809. if(l==search_str("if")) // warn_cmd_no_commaのために必要
  810. parse_cmd_if++;
  811. /*
  812. // 廃止予定のl14/l15,およびプレフィックスlの警告
  813. if( strcmp(str_buf+str_data[l].str,"l14")==0 ||
  814. strcmp(str_buf+str_data[l].str,"l15")==0 ){
  815. disp_error_message("l14 and l15 is DEPRECATED. use @menu instead of l15.",p);
  816. }else if(str_buf[str_data[l].str]=='l'){
  817. disp_error_message("prefix 'l' is DEPRECATED. use prefix '@' instead.",p2);
  818. }
  819. */
  820. *p2=c; p=p2;
  821. if(str_data[l].type!=C_FUNC && c=='['){
  822. // array(name[i] => getelementofarray(name,i) )
  823. add_scriptl(search_str("getelementofarray"));
  824. add_scriptc(C_ARG);
  825. add_scriptl(l);
  826. p=parse_subexpr(p+1,-1);
  827. p=skip_space(p);
  828. if((*p++)!=']'){
  829. disp_error_message("unmatch ']'",p);
  830. exit(1);
  831. }
  832. add_scriptc(C_FUNC);
  833. }else
  834. add_scriptl(l);
  835. }
  836. #ifdef DEBUG_FUNCIN
  837. if(battle_config.etc_log)
  838. printf("parse_simpleexpr end %s\n",p);
  839. #endif
  840. return p;
  841. }
  842. /*==========================================
  843. * 式の解析
  844. *------------------------------------------
  845. */
  846. unsigned char* parse_subexpr(unsigned char *p,int limit)
  847. {
  848. int op,opl,len;
  849. char *tmpp;
  850. #ifdef DEBUG_FUNCIN
  851. if(battle_config.etc_log)
  852. printf("parse_subexpr %s\n",p);
  853. #endif
  854. p=skip_space(p);
  855. if(*p=='-'){
  856. tmpp=skip_space(p+1);
  857. if(*tmpp==';' || *tmpp==','){
  858. add_scriptl(LABEL_NEXTLINE);
  859. p++;
  860. return p;
  861. }
  862. }
  863. tmpp=p;
  864. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  865. p=parse_subexpr(p+1,100);
  866. add_scriptc(op);
  867. } else
  868. p=parse_simpleexpr(p);
  869. p=skip_space(p);
  870. while(((op=C_ADD,opl=6,len=1,*p=='+') ||
  871. (op=C_SUB,opl=6,len=1,*p=='-') ||
  872. (op=C_MUL,opl=7,len=1,*p=='*') ||
  873. (op=C_DIV,opl=7,len=1,*p=='/') ||
  874. (op=C_MOD,opl=7,len=1,*p=='%') ||
  875. (op=C_FUNC,opl=8,len=1,*p=='(') ||
  876. (op=C_LAND,opl=1,len=2,*p=='&' && p[1]=='&') ||
  877. (op=C_AND,opl=5,len=1,*p=='&') ||
  878. (op=C_LOR,opl=0,len=2,*p=='|' && p[1]=='|') ||
  879. (op=C_OR,opl=4,len=1,*p=='|') ||
  880. (op=C_XOR,opl=3,len=1,*p=='^') ||
  881. (op=C_EQ,opl=2,len=2,*p=='=' && p[1]=='=') ||
  882. (op=C_NE,opl=2,len=2,*p=='!' && p[1]=='=') ||
  883. (op=C_R_SHIFT,opl=5,len=2,*p=='>' && p[1]=='>') ||
  884. (op=C_GE,opl=2,len=2,*p=='>' && p[1]=='=') ||
  885. (op=C_GT,opl=2,len=1,*p=='>') ||
  886. (op=C_L_SHIFT,opl=5,len=2,*p=='<' && p[1]=='<') ||
  887. (op=C_LE,opl=2,len=2,*p=='<' && p[1]=='=') ||
  888. (op=C_LT,opl=2,len=1,*p=='<')) && opl>limit){
  889. p+=len;
  890. if(op==C_FUNC){
  891. int i=0,func=parse_cmd;
  892. const char *plist[128];
  893. if( str_data[func].type!=C_FUNC ){
  894. disp_error_message("expect function",tmpp);
  895. exit(0);
  896. }
  897. add_scriptc(C_ARG);
  898. do {
  899. plist[i]=p;
  900. p=parse_subexpr(p,-1);
  901. p=skip_space(p);
  902. if(*p==',') p++;
  903. else if(*p!=')' && script_config.warn_func_no_comma){
  904. disp_error_message("expect ',' or ')' at func params",p);
  905. }
  906. p=skip_space(p);
  907. i++;
  908. } while(*p && *p!=')' && i<128);
  909. plist[i]=p;
  910. if(*(p++)!=')'){
  911. disp_error_message("func request '(' ')'",p);
  912. exit(1);
  913. }
  914. if( str_data[func].type==C_FUNC && script_config.warn_func_mismatch_paramnum){
  915. const char *arg=buildin_func[str_data[func].val].arg;
  916. int j=0;
  917. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  918. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  919. disp_error_message("illegal number of parameters",plist[(i<j)?i:j]);
  920. }
  921. }
  922. } else {
  923. p=parse_subexpr(p,opl);
  924. }
  925. add_scriptc(op);
  926. p=skip_space(p);
  927. }
  928. #ifdef DEBUG_FUNCIN
  929. if(battle_config.etc_log)
  930. printf("parse_subexpr end %s\n",p);
  931. #endif
  932. return p; /* return first untreated operator */
  933. }
  934. /*==========================================
  935. * 式の評価
  936. *------------------------------------------
  937. */
  938. unsigned char* parse_expr(unsigned char *p)
  939. {
  940. #ifdef DEBUG_FUNCIN
  941. if(battle_config.etc_log)
  942. printf("parse_expr %s\n",p);
  943. #endif
  944. switch(*p){
  945. case ')': case ';': case ':': case '[': case ']':
  946. case '}':
  947. disp_error_message("unexpected char",p);
  948. exit(1);
  949. }
  950. p=parse_subexpr(p,-1);
  951. #ifdef DEBUG_FUNCIN
  952. if(battle_config.etc_log)
  953. printf("parse_expr end %s\n",p);
  954. #endif
  955. return p;
  956. }
  957. /*==========================================
  958. * 行の解析
  959. *------------------------------------------
  960. */
  961. unsigned char* parse_line(unsigned char *p)
  962. {
  963. int i=0,cmd;
  964. const char *plist[128];
  965. char *p2;
  966. p=skip_space(p);
  967. if(*p==';')
  968. return p;
  969. parse_cmd_if=0; // warn_cmd_no_commaのために必要
  970. // 最初は関数名
  971. p2=p;
  972. p=parse_simpleexpr(p);
  973. p=skip_space(p);
  974. cmd=parse_cmd;
  975. if( str_data[cmd].type!=C_FUNC ){
  976. disp_error_message("expect command",p2);
  977. // exit(0);
  978. }
  979. add_scriptc(C_ARG);
  980. while(p && *p && *p!=';' && i<128){
  981. plist[i]=p;
  982. p=parse_expr(p);
  983. p=skip_space(p);
  984. // 引数区切りの,処理
  985. if(*p==',') p++;
  986. else if(*p!=';' && script_config.warn_cmd_no_comma && parse_cmd_if*2<=i ){
  987. disp_error_message("expect ',' or ';' at cmd params",p);
  988. }
  989. p=skip_space(p);
  990. i++;
  991. }
  992. plist[i]=p;
  993. if(!p || *(p++)!=';'){
  994. disp_error_message("need ';'",p);
  995. exit(1);
  996. }
  997. add_scriptc(C_FUNC);
  998. if( str_data[cmd].type==C_FUNC && script_config.warn_cmd_mismatch_paramnum){
  999. const char *arg=buildin_func[str_data[cmd].val].arg;
  1000. int j=0;
  1001. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  1002. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  1003. disp_error_message("illegal number of parameters",plist[(i<j)?i:j]);
  1004. }
  1005. }
  1006. return p;
  1007. }
  1008. /*==========================================
  1009. * 組み込み関数の追加
  1010. *------------------------------------------
  1011. */
  1012. static void add_buildin_func(void)
  1013. {
  1014. int i,n;
  1015. for(i=0;buildin_func[i].func;i++){
  1016. n=add_str(buildin_func[i].name);
  1017. str_data[n].type=C_FUNC;
  1018. str_data[n].val=i;
  1019. str_data[n].func=buildin_func[i].func;
  1020. }
  1021. }
  1022. /*==========================================
  1023. * 定数データベースの読み込み
  1024. *------------------------------------------
  1025. */
  1026. static void read_constdb(void)
  1027. {
  1028. FILE *fp;
  1029. char line[1024],name[1024];
  1030. int val,n,i,type;
  1031. fp=fopen("db/const.txt","r");
  1032. if(fp==NULL){
  1033. printf("can't read db/const.txt\n");
  1034. return ;
  1035. }
  1036. while(fgets(line,1020,fp)){
  1037. if(line[0]=='/' && line[1]=='/')
  1038. continue;
  1039. type=0;
  1040. if(sscanf(line,"%[A-Za-z0-9_],%d,%d",name,&val,&type)>=2 ||
  1041. sscanf(line,"%[A-Za-z0-9_] %d %d",name,&val,&type)>=2){
  1042. for(i=0;name[i];i++)
  1043. name[i]=tolower(name[i]);
  1044. n=add_str(name);
  1045. if(type==0)
  1046. str_data[n].type=C_INT;
  1047. else
  1048. str_data[n].type=C_PARAM;
  1049. str_data[n].val=val;
  1050. }
  1051. }
  1052. fclose(fp);
  1053. }
  1054. /*==========================================
  1055. * スクリプトの解析
  1056. *------------------------------------------
  1057. */
  1058. unsigned char* parse_script(unsigned char *src,int line)
  1059. {
  1060. unsigned char *p,*tmpp;
  1061. int i;
  1062. static int first=1;
  1063. if(first){
  1064. add_buildin_func();
  1065. read_constdb();
  1066. }
  1067. first=0;
  1068. script_buf=(unsigned char *)aCalloc(SCRIPT_BLOCK_SIZE,sizeof(unsigned char));
  1069. script_pos=0;
  1070. script_size=SCRIPT_BLOCK_SIZE;
  1071. str_data[LABEL_NEXTLINE].type=C_NOP;
  1072. str_data[LABEL_NEXTLINE].backpatch=-1;
  1073. str_data[LABEL_NEXTLINE].label=-1;
  1074. for(i=LABEL_START;i<str_num;i++){
  1075. if(str_data[i].type==C_POS || str_data[i].type==C_NAME){
  1076. str_data[i].type=C_NOP;
  1077. str_data[i].backpatch=-1;
  1078. str_data[i].label=-1;
  1079. }
  1080. }
  1081. // 外部用label dbの初期化
  1082. if(scriptlabel_db!=NULL)
  1083. strdb_final(scriptlabel_db,scriptlabel_final);
  1084. scriptlabel_db=strdb_init(50);
  1085. // for error message
  1086. startptr = src;
  1087. startline = line;
  1088. p=src;
  1089. p=skip_space(p);
  1090. if(*p!='{'){
  1091. disp_error_message("not found '{'",p);
  1092. return NULL;
  1093. }
  1094. for(p++;p && *p && *p!='}';){
  1095. p=skip_space(p);
  1096. // labelだけ特殊処理
  1097. tmpp=skip_space(skip_word(p));
  1098. if(*tmpp==':'){
  1099. int l,c;
  1100. c=*skip_word(p);
  1101. *skip_word(p)=0;
  1102. l=add_str(p);
  1103. if(str_data[l].label!=-1){
  1104. *skip_word(p)=c;
  1105. disp_error_message("dup label ",p);
  1106. exit(1);
  1107. }
  1108. set_label(l,script_pos);
  1109. strdb_insert(scriptlabel_db,p,script_pos); // 外部用label db登録
  1110. *skip_word(p)=c;
  1111. p=tmpp+1;
  1112. continue;
  1113. }
  1114. // 他は全部一緒くた
  1115. p=parse_line(p);
  1116. p=skip_space(p);
  1117. add_scriptc(C_EOL);
  1118. set_label(LABEL_NEXTLINE,script_pos);
  1119. str_data[LABEL_NEXTLINE].type=C_NOP;
  1120. str_data[LABEL_NEXTLINE].backpatch=-1;
  1121. str_data[LABEL_NEXTLINE].label=-1;
  1122. }
  1123. add_scriptc(C_NOP);
  1124. script_size = script_pos;
  1125. script_buf=(char *)aRealloc(script_buf,script_pos + 1);
  1126. // 未解決のラベルを解決
  1127. for(i=LABEL_START;i<str_num;i++){
  1128. if(str_data[i].type==C_NOP){
  1129. int j,next;
  1130. str_data[i].type=C_NAME;
  1131. str_data[i].label=i;
  1132. for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
  1133. next=(*(int*)(script_buf+j)) & 0x00ffffff;
  1134. script_buf[j]=i;
  1135. script_buf[j+1]=i>>8;
  1136. script_buf[j+2]=i>>16;
  1137. j=next;
  1138. }
  1139. }
  1140. }
  1141. #ifdef DEBUG_DISP
  1142. for(i=0;i<script_pos;i++){
  1143. if((i&15)==0) printf("%04x : ",i);
  1144. printf("%02x ",script_buf[i]);
  1145. if((i&15)==15) printf("\n");
  1146. }
  1147. printf("\n");
  1148. #endif
  1149. return script_buf;
  1150. }
  1151. //
  1152. // 実行系
  1153. //
  1154. enum {STOP=1,END,RERUNLINE,GOTO,RETFUNC};
  1155. /*==========================================
  1156. * ridからsdへの解決
  1157. *------------------------------------------
  1158. */
  1159. struct map_session_data *script_rid2sd(struct script_state *st)
  1160. {
  1161. struct map_session_data *sd=map_id2sd(st->rid);
  1162. if(!sd){
  1163. printf("script_rid2sd: fatal error ! player not attached!\n");
  1164. }
  1165. return sd;
  1166. }
  1167. /*==========================================
  1168. * 変数の読み取り
  1169. *------------------------------------------
  1170. */
  1171. int get_val(struct script_state*st,struct script_data* data)
  1172. {
  1173. struct map_session_data *sd=NULL;
  1174. if(data->type==C_NAME){
  1175. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  1176. char prefix=*name;
  1177. char postfix=name[strlen(name)-1];
  1178. if(prefix!='$'){
  1179. if((sd=script_rid2sd(st))==NULL)
  1180. printf("get_val error name?:%s\n",name);
  1181. }
  1182. if(postfix=='$'){
  1183. data->type=C_CONSTSTR;
  1184. if( prefix=='@' || prefix=='l' ){
  1185. if(sd)
  1186. data->u.str = pc_readregstr(sd,data->u.num);
  1187. }else if(prefix=='$'){
  1188. data->u.str = (char *)numdb_search(mapregstr_db,data->u.num);
  1189. }else{
  1190. printf("script: get_val: illegal scope string variable.\n");
  1191. data->u.str = "!!ERROR!!";
  1192. }
  1193. if( data->u.str == NULL )
  1194. data->u.str ="";
  1195. }else{
  1196. data->type=C_INT;
  1197. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  1198. data->u.num = str_data[data->u.num&0x00ffffff].val;
  1199. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  1200. if(sd)
  1201. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  1202. }else if(prefix=='@' || prefix=='l'){
  1203. if(sd)
  1204. data->u.num = pc_readreg(sd,data->u.num);
  1205. }else if(prefix=='$'){
  1206. data->u.num = (int)numdb_search(mapreg_db,data->u.num);
  1207. }else if(prefix=='#'){
  1208. if( name[1]=='#'){
  1209. if(sd)
  1210. data->u.num = pc_readaccountreg2(sd,name);
  1211. }else{
  1212. if(sd)
  1213. data->u.num = pc_readaccountreg(sd,name);
  1214. }
  1215. }else{
  1216. if(sd)
  1217. data->u.num = pc_readglobalreg(sd,name);
  1218. }
  1219. }
  1220. }
  1221. return 0;
  1222. }
  1223. /*==========================================
  1224. * 変数の読み取り2
  1225. *------------------------------------------
  1226. */
  1227. void* get_val2(struct script_state*st,int num)
  1228. {
  1229. struct script_data dat;
  1230. dat.type=C_NAME;
  1231. dat.u.num=num;
  1232. get_val(st,&dat);
  1233. if( dat.type==C_INT ) return (void*)dat.u.num;
  1234. else return (void*)dat.u.str;
  1235. }
  1236. /*==========================================
  1237. * 変数設定用
  1238. *------------------------------------------
  1239. */
  1240. static int set_reg(struct map_session_data *sd,int num,char *name,void *v)
  1241. {
  1242. char prefix=*name;
  1243. char postfix=name[strlen(name)-1];
  1244. if( postfix=='$' ){
  1245. char *str=(char*)v;
  1246. if( prefix=='@' || prefix=='l'){
  1247. pc_setregstr(sd,num,str);
  1248. }else if(prefix=='$') {
  1249. mapreg_setregstr(num,str);
  1250. }else{
  1251. printf("script: set_reg: illegal scope string variable !");
  1252. }
  1253. }else{
  1254. // 数値
  1255. int val = (int)v;
  1256. if(str_data[num&0x00ffffff].type==C_PARAM){
  1257. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  1258. }else if(prefix=='@' || prefix=='l') {
  1259. pc_setreg(sd,num,val);
  1260. }else if(prefix=='$') {
  1261. mapreg_setreg(num,val);
  1262. }else if(prefix=='#') {
  1263. if( name[1]=='#' )
  1264. pc_setaccountreg2(sd,name,val);
  1265. else
  1266. pc_setaccountreg(sd,name,val);
  1267. }else{
  1268. pc_setglobalreg(sd,name,val);
  1269. }
  1270. }
  1271. return 0;
  1272. }
  1273. /*==========================================
  1274. * 文字列への変換
  1275. *------------------------------------------
  1276. */
  1277. char* conv_str(struct script_state *st,struct script_data *data)
  1278. {
  1279. get_val(st,data);
  1280. if(data->type==C_INT){
  1281. char *buf;
  1282. buf=(char *)aCalloc(16,sizeof(char));
  1283. sprintf(buf,"%d",data->u.num);
  1284. data->type=C_STR;
  1285. data->u.str=buf;
  1286. #if 1
  1287. } else if(data->type==C_NAME){
  1288. // テンポラリ。本来無いはず
  1289. data->type=C_CONSTSTR;
  1290. data->u.str=str_buf+str_data[data->u.num].str;
  1291. #endif
  1292. }
  1293. return data->u.str;
  1294. }
  1295. /*==========================================
  1296. * 数値へ変換
  1297. *------------------------------------------
  1298. */
  1299. int conv_num(struct script_state *st,struct script_data *data)
  1300. {
  1301. char *p;
  1302. get_val(st,data);
  1303. if(data->type==C_STR || data->type==C_CONSTSTR){
  1304. p=data->u.str;
  1305. data->u.num = atoi(p);
  1306. if(data->type==C_STR)
  1307. free(p);
  1308. data->type=C_INT;
  1309. }
  1310. return data->u.num;
  1311. }
  1312. /*==========================================
  1313. * スタックへ数値をプッシュ
  1314. *------------------------------------------
  1315. */
  1316. void push_val(struct script_stack *stack,int type,int val)
  1317. {
  1318. if(stack->sp >= stack->sp_max){
  1319. stack->sp_max += 64;
  1320. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1321. sizeof(stack->stack_data[0]) * stack->sp_max);
  1322. memset(stack->stack_data + (stack->sp_max - 64), 0,
  1323. 64 * sizeof(*(stack->stack_data)));
  1324. }
  1325. // if(battle_config.etc_log)
  1326. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  1327. stack->stack_data[stack->sp].type=type;
  1328. stack->stack_data[stack->sp].u.num=val;
  1329. stack->sp++;
  1330. }
  1331. /*==========================================
  1332. * スタックへ文字列をプッシュ
  1333. *------------------------------------------
  1334. */
  1335. void push_str(struct script_stack *stack,int type,unsigned char *str)
  1336. {
  1337. if(stack->sp>=stack->sp_max){
  1338. stack->sp_max += 64;
  1339. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1340. sizeof(stack->stack_data[0]) * stack->sp_max);
  1341. memset(stack->stack_data + (stack->sp_max - 64), '\0',
  1342. 64 * sizeof(*(stack->stack_data)));
  1343. }
  1344. // if(battle_config.etc_log)
  1345. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  1346. stack->stack_data[stack->sp].type=type;
  1347. stack->stack_data[stack->sp].u.str=str;
  1348. stack->sp++;
  1349. }
  1350. /*==========================================
  1351. * スタックへ複製をプッシュ
  1352. *------------------------------------------
  1353. */
  1354. void push_copy(struct script_stack *stack,int pos)
  1355. {
  1356. switch(stack->stack_data[pos].type){
  1357. case C_CONSTSTR:
  1358. push_str(stack,C_CONSTSTR,stack->stack_data[pos].u.str);
  1359. break;
  1360. case C_STR:
  1361. push_str(stack,C_STR,strdup(stack->stack_data[pos].u.str));
  1362. break;
  1363. default:
  1364. push_val(stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num);
  1365. break;
  1366. }
  1367. }
  1368. /*==========================================
  1369. * スタックからポップ
  1370. *------------------------------------------
  1371. */
  1372. void pop_stack(struct script_stack* stack,int start,int end)
  1373. {
  1374. int i;
  1375. for(i=start;i<end;i++){
  1376. if(stack->stack_data[i].type==C_STR){
  1377. free(stack->stack_data[i].u.str);
  1378. }
  1379. }
  1380. if(stack->sp>end){
  1381. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  1382. }
  1383. stack->sp-=end-start;
  1384. }
  1385. //
  1386. // 埋め込み関数
  1387. //
  1388. /*==========================================
  1389. *
  1390. *------------------------------------------
  1391. */
  1392. int buildin_mes(struct script_state *st)
  1393. {
  1394. conv_str(st,& (st->stack->stack_data[st->start+2]));
  1395. clif_scriptmes(script_rid2sd(st),st->oid,st->stack->stack_data[st->start+2].u.str);
  1396. return 0;
  1397. }
  1398. /*==========================================
  1399. *
  1400. *------------------------------------------
  1401. */
  1402. int buildin_goto(struct script_state *st)
  1403. {
  1404. int pos;
  1405. if( st->stack->stack_data[st->start+2].type!=C_POS ){
  1406. printf("script: goto: not label !\n");
  1407. st->state=END;
  1408. return 0;
  1409. }
  1410. pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1411. st->pos=pos;
  1412. st->state=GOTO;
  1413. return 0;
  1414. }
  1415. /*==========================================
  1416. * ユーザー定義関数の呼び出し
  1417. *------------------------------------------
  1418. */
  1419. int buildin_callfunc(struct script_state *st)
  1420. {
  1421. char *scr;
  1422. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  1423. if( (scr=strdb_search(script_get_userfunc_db(),str)) ){
  1424. int i,j;
  1425. for(i=st->start+3,j=0;i<st->end;i++,j++)
  1426. push_copy(st->stack,i);
  1427. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  1428. push_val(st->stack,C_INT,st->defsp); // 現在の基準スタックポインタをプッシュ
  1429. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  1430. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  1431. st->pos=0;
  1432. st->script=scr;
  1433. st->defsp=st->start+4+j;
  1434. st->state=GOTO;
  1435. }else{
  1436. printf("script:callfunc: function not found! [%s]\n",str);
  1437. st->state=END;
  1438. }
  1439. return 0;
  1440. }
  1441. /*==========================================
  1442. * サブルーティンの呼び出し
  1443. *------------------------------------------
  1444. */
  1445. int buildin_callsub(struct script_state *st)
  1446. {
  1447. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1448. int i,j;
  1449. for(i=st->start+3,j=0;i<st->end;i++,j++)
  1450. push_copy(st->stack,i);
  1451. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  1452. push_val(st->stack,C_INT,st->defsp); // 現在の基準スタックポインタをプッシュ
  1453. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  1454. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  1455. st->pos=pos;
  1456. st->defsp=st->start+4+j;
  1457. st->state=GOTO;
  1458. return 0;
  1459. }
  1460. /*==========================================
  1461. * 引数の所得
  1462. *------------------------------------------
  1463. */
  1464. int buildin_getarg(struct script_state *st)
  1465. {
  1466. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1467. int max,stsp;
  1468. if( st->defsp<4 || st->stack->stack_data[st->defsp-1].type!=C_RETINFO ){
  1469. printf("script:getarg without callfunc or callsub!\n");
  1470. st->state=END;
  1471. return 0;
  1472. }
  1473. max=conv_num(st,& (st->stack->stack_data[st->defsp-4]));
  1474. stsp=st->defsp - max -4;
  1475. if( num >= max ){
  1476. printf("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  1477. st->state=END;
  1478. return 0;
  1479. }
  1480. push_copy(st->stack,stsp+num);
  1481. return 0;
  1482. }
  1483. /*==========================================
  1484. * サブルーチン/ユーザー定義関数の終了
  1485. *------------------------------------------
  1486. */
  1487. int buildin_return(struct script_state *st)
  1488. {
  1489. if(st->end>st->start+2){ // 戻り値有り
  1490. push_copy(st->stack,st->start+2);
  1491. }
  1492. st->state=RETFUNC;
  1493. return 0;
  1494. }
  1495. /*==========================================
  1496. *
  1497. *------------------------------------------
  1498. */
  1499. int buildin_next(struct script_state *st)
  1500. {
  1501. st->state=STOP;
  1502. clif_scriptnext(script_rid2sd(st),st->oid);
  1503. return 0;
  1504. }
  1505. /*==========================================
  1506. *
  1507. *------------------------------------------
  1508. */
  1509. int buildin_close(struct script_state *st)
  1510. {
  1511. st->state=END;
  1512. clif_scriptclose(script_rid2sd(st),st->oid);
  1513. return 0;
  1514. }
  1515. int buildin_close2(struct script_state *st)
  1516. {
  1517. st->state=STOP;
  1518. clif_scriptclose(script_rid2sd(st),st->oid);
  1519. return 0;
  1520. }
  1521. /*==========================================
  1522. *
  1523. *------------------------------------------
  1524. */
  1525. int buildin_menu(struct script_state *st)
  1526. {
  1527. char *buf;
  1528. int len,i;
  1529. struct map_session_data *sd;
  1530. sd=script_rid2sd(st);
  1531. if(sd->state.menu_or_input==0){
  1532. st->state=RERUNLINE;
  1533. sd->state.menu_or_input=1;
  1534. for(i=st->start+2,len=16;i<st->end;i+=2){
  1535. conv_str(st,& (st->stack->stack_data[i]));
  1536. len+=strlen(st->stack->stack_data[i].u.str)+1;
  1537. }
  1538. buf=(char *)aCalloc(len,sizeof(char));
  1539. buf[0]=0;
  1540. for(i=st->start+2,len=0;i<st->end;i+=2){
  1541. strcat(buf,st->stack->stack_data[i].u.str);
  1542. strcat(buf,":");
  1543. }
  1544. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  1545. free(buf);
  1546. } else if(sd->npc_menu==0xff){ // cansel
  1547. sd->state.menu_or_input=0;
  1548. st->state=END;
  1549. } else { // goto動作
  1550. // ragemu互換のため
  1551. pc_setreg(sd,add_str("l15"),sd->npc_menu);
  1552. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  1553. sd->state.menu_or_input=0;
  1554. if(sd->npc_menu>0 && sd->npc_menu<(st->end-st->start)/2){
  1555. int pos;
  1556. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  1557. printf("script: menu: not label !\n");
  1558. st->state=END;
  1559. return 0;
  1560. }
  1561. pos=conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  1562. st->pos=pos;
  1563. st->state=GOTO;
  1564. }
  1565. }
  1566. return 0;
  1567. }
  1568. /*==========================================
  1569. *
  1570. *------------------------------------------
  1571. */
  1572. int buildin_rand(struct script_state *st)
  1573. {
  1574. int range,min,max;
  1575. if(st->end>st->start+3){
  1576. min=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1577. max=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1578. if(max<min){
  1579. int tmp;
  1580. tmp=min;
  1581. min=max;
  1582. max=tmp;
  1583. }
  1584. range=max-min+1;
  1585. push_val(st->stack,C_INT,rand()%range+min);
  1586. } else {
  1587. range=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1588. push_val(st->stack,C_INT,rand()%range);
  1589. }
  1590. return 0;
  1591. }
  1592. /*==========================================
  1593. *
  1594. *------------------------------------------
  1595. */
  1596. int buildin_warp(struct script_state *st)
  1597. {
  1598. int x,y;
  1599. char *str;
  1600. struct map_session_data *sd=script_rid2sd(st);
  1601. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  1602. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1603. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1604. if(strcmp(str,"Random")==0)
  1605. pc_randomwarp(sd,3);
  1606. else if(strcmp(str,"SavePoint")==0){
  1607. if(map[sd->bl.m].flag.noreturn) // 蝶禁止
  1608. return 0;
  1609. pc_setpos(sd,sd->status.save_point.map,
  1610. sd->status.save_point.x,sd->status.save_point.y,3);
  1611. }else if(strcmp(str,"Save")==0){
  1612. if(map[sd->bl.m].flag.noreturn) // 蝶禁止
  1613. return 0;
  1614. pc_setpos(sd,sd->status.save_point.map,
  1615. sd->status.save_point.x,sd->status.save_point.y,3);
  1616. }else
  1617. pc_setpos(sd,str,x,y,0);
  1618. return 0;
  1619. }
  1620. /*==========================================
  1621. * エリア指定ワープ
  1622. *------------------------------------------
  1623. */
  1624. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  1625. {
  1626. int x,y;
  1627. char *map;
  1628. map=va_arg(ap, char *);
  1629. x=va_arg(ap,int);
  1630. y=va_arg(ap,int);
  1631. if(strcmp(map,"Random")==0)
  1632. pc_randomwarp((struct map_session_data *)bl,3);
  1633. else
  1634. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  1635. return 0;
  1636. }
  1637. int buildin_areawarp(struct script_state *st)
  1638. {
  1639. int x,y,m;
  1640. char *str;
  1641. char *mapname;
  1642. int x0,y0,x1,y1;
  1643. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  1644. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1645. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1646. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  1647. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  1648. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  1649. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  1650. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  1651. if( (m=map_mapname2mapid(mapname))< 0)
  1652. return 0;
  1653. map_foreachinarea(buildin_areawarp_sub,
  1654. m,x0,y0,x1,y1,BL_PC, str,x,y );
  1655. return 0;
  1656. }
  1657. /*==========================================
  1658. *
  1659. *------------------------------------------
  1660. */
  1661. int buildin_heal(struct script_state *st)
  1662. {
  1663. int hp,sp;
  1664. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1665. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1666. pc_heal(script_rid2sd(st),hp,sp);
  1667. return 0;
  1668. }
  1669. /*==========================================
  1670. *
  1671. *------------------------------------------
  1672. */
  1673. int buildin_itemheal(struct script_state *st)
  1674. {
  1675. int hp,sp;
  1676. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1677. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1678. pc_itemheal(script_rid2sd(st),hp,sp);
  1679. return 0;
  1680. }
  1681. /*==========================================
  1682. *
  1683. *------------------------------------------
  1684. */
  1685. int buildin_percentheal(struct script_state *st)
  1686. {
  1687. int hp,sp;
  1688. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1689. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1690. pc_percentheal(script_rid2sd(st),hp,sp);
  1691. return 0;
  1692. }
  1693. /*==========================================
  1694. *
  1695. *------------------------------------------
  1696. */
  1697. int buildin_jobchange(struct script_state *st)
  1698. {
  1699. int job, upper=-1;
  1700. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1701. if( st->end>st->start+3 )
  1702. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1703. if ((job >= 0 && job < MAX_PC_CLASS))
  1704. pc_jobchange(script_rid2sd(st),job, upper);
  1705. return 0;
  1706. }
  1707. /*==========================================
  1708. *
  1709. *------------------------------------------
  1710. */
  1711. int buildin_input(struct script_state *st)
  1712. {
  1713. struct map_session_data *sd=NULL;
  1714. int num=(st->end>st->start+2)?st->stack->stack_data[st->start+2].u.num:0;
  1715. char *name=(st->end>st->start+2)?str_buf+str_data[num&0x00ffffff].str:"";
  1716. // char prefix=*name;
  1717. char postfix=name[strlen(name)-1];
  1718. sd=script_rid2sd(st);
  1719. if(sd->state.menu_or_input){
  1720. sd->state.menu_or_input=0;
  1721. if( postfix=='$' ){
  1722. // 文字列
  1723. if(st->end>st->start+2){ // 引数1個
  1724. set_reg(sd,num,name,(void*)sd->npc_str);
  1725. }else{
  1726. printf("buildin_input: string discarded !!\n");
  1727. }
  1728. }else{
  1729. // commented by Lupus (check Value Number Input fix in clif.c)
  1730. // readded by Yor: set ammount to 0 instead of cancel trade.
  1731. // ** Fix by fritz :X keeps people from abusing old input bugs
  1732. if (sd->npc_amount < 0) { //** If input amount is less then 0
  1733. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  1734. // buildin_close(st); // ** close
  1735. sd->npc_amount = 0;
  1736. } else if (sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  1737. sd->npc_amount = battle_config.vending_max_value;
  1738. // 数値
  1739. if(st->end>st->start+2){ // 引数1個
  1740. set_reg(sd,num,name,(void*)sd->npc_amount);
  1741. } else {
  1742. // ragemu互換のため
  1743. pc_setreg(sd,add_str("l14"),sd->npc_amount);
  1744. }
  1745. }
  1746. } else {
  1747. st->state=RERUNLINE;
  1748. if(postfix=='$')clif_scriptinputstr(sd,st->oid);
  1749. else clif_scriptinput(sd,st->oid);
  1750. sd->state.menu_or_input=1;
  1751. }
  1752. return 0;
  1753. }
  1754. /*==========================================
  1755. *
  1756. *------------------------------------------
  1757. */
  1758. int buildin_if(struct script_state *st)
  1759. {
  1760. int sel,i;
  1761. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1762. if(!sel)
  1763. return 0;
  1764. // 関数名をコピー
  1765. push_copy(st->stack,st->start+3);
  1766. // 間に引数マーカを入れて
  1767. push_val(st->stack,C_ARG,0);
  1768. // 残りの引数をコピー
  1769. for(i=st->start+4;i<st->end;i++){
  1770. push_copy(st->stack,i);
  1771. }
  1772. run_func(st);
  1773. return 0;
  1774. }
  1775. /*==========================================
  1776. * 変数設定
  1777. *------------------------------------------
  1778. */
  1779. int buildin_set(struct script_state *st)
  1780. {
  1781. struct map_session_data *sd=NULL;
  1782. int num=st->stack->stack_data[st->start+2].u.num;
  1783. char *name=str_buf+str_data[num&0x00ffffff].str;
  1784. char prefix=*name;
  1785. char postfix=name[strlen(name)-1];
  1786. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  1787. printf("script: buildin_set: not name\n");
  1788. return 0;
  1789. }
  1790. if( prefix!='$' )
  1791. sd=script_rid2sd(st);
  1792. if( postfix=='$' ){
  1793. // 文字列
  1794. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  1795. set_reg(sd,num,name,(void*)str);
  1796. }else{
  1797. // 数値
  1798. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  1799. set_reg(sd,num,name,(void*)val);
  1800. }
  1801. return 0;
  1802. }
  1803. /*==========================================
  1804. * 配列変数設定
  1805. *------------------------------------------
  1806. */
  1807. int buildin_setarray(struct script_state *st)
  1808. {
  1809. struct map_session_data *sd=NULL;
  1810. int num=st->stack->stack_data[st->start+2].u.num;
  1811. char *name=str_buf+str_data[num&0x00ffffff].str;
  1812. char prefix=*name;
  1813. char postfix=name[strlen(name)-1];
  1814. int i,j;
  1815. if( prefix!='$' && prefix!='@' ){
  1816. printf("buildin_setarray: illegal scope !\n");
  1817. return 0;
  1818. }
  1819. if( prefix!='$' )
  1820. sd=script_rid2sd(st);
  1821. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  1822. void *v;
  1823. if( postfix=='$' )
  1824. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  1825. else
  1826. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  1827. set_reg( sd, num+(j<<24), name, v);
  1828. }
  1829. return 0;
  1830. }
  1831. /*==========================================
  1832. * 配列変数クリア
  1833. *------------------------------------------
  1834. */
  1835. int buildin_cleararray(struct script_state *st)
  1836. {
  1837. struct map_session_data *sd=NULL;
  1838. int num=st->stack->stack_data[st->start+2].u.num;
  1839. char *name=str_buf+str_data[num&0x00ffffff].str;
  1840. char prefix=*name;
  1841. char postfix=name[strlen(name)-1];
  1842. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1843. int i;
  1844. void *v;
  1845. if( prefix!='$' && prefix!='@' ){
  1846. printf("buildin_cleararray: illegal scope !\n");
  1847. return 0;
  1848. }
  1849. if( prefix!='$' )
  1850. sd=script_rid2sd(st);
  1851. if( postfix=='$' )
  1852. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  1853. else
  1854. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  1855. for(i=0;i<sz;i++)
  1856. set_reg(sd,num+(i<<24),name,v);
  1857. return 0;
  1858. }
  1859. /*==========================================
  1860. * 配列変数コピー
  1861. *------------------------------------------
  1862. */
  1863. int buildin_copyarray(struct script_state *st)
  1864. {
  1865. struct map_session_data *sd=NULL;
  1866. int num=st->stack->stack_data[st->start+2].u.num;
  1867. char *name=str_buf+str_data[num&0x00ffffff].str;
  1868. char prefix=*name;
  1869. char postfix=name[strlen(name)-1];
  1870. int num2=st->stack->stack_data[st->start+3].u.num;
  1871. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  1872. char prefix2=*name2;
  1873. char postfix2=name2[strlen(name2)-1];
  1874. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  1875. int i;
  1876. if( prefix!='$' && prefix!='@' && prefix2!='$' && prefix2!='@' ){
  1877. printf("buildin_copyarray: illegal scope !\n");
  1878. return 0;
  1879. }
  1880. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  1881. printf("buildin_copyarray: type mismatch !\n");
  1882. return 0;
  1883. }
  1884. if( prefix!='$' || prefix2!='$' )
  1885. sd=script_rid2sd(st);
  1886. for(i=0;i<sz;i++)
  1887. set_reg(sd,num+(i<<24),name, get_val2(st,num2+(i<<24)) );
  1888. return 0;
  1889. }
  1890. /*==========================================
  1891. * 配列変数のサイズ所得
  1892. *------------------------------------------
  1893. */
  1894. static int getarraysize(struct script_state *st,int num,int postfix)
  1895. {
  1896. int i=(num>>24),c=i;
  1897. for(;i<128;i++){
  1898. void *v=get_val2(st,num+(i<<24));
  1899. if(postfix=='$' && *((char*)v) ) c=i;
  1900. if(postfix!='$' && (int)v )c=i;
  1901. }
  1902. return c+1;
  1903. }
  1904. int buildin_getarraysize(struct script_state *st)
  1905. {
  1906. int num=st->stack->stack_data[st->start+2].u.num;
  1907. char *name=str_buf+str_data[num&0x00ffffff].str;
  1908. char prefix=*name;
  1909. char postfix=name[strlen(name)-1];
  1910. if( prefix!='$' && prefix!='@' ){
  1911. printf("buildin_copyarray: illegal scope !\n");
  1912. return 0;
  1913. }
  1914. push_val(st->stack,C_INT,getarraysize(st,num,postfix) );
  1915. return 0;
  1916. }
  1917. /*==========================================
  1918. * 配列変数から要素削除
  1919. *------------------------------------------
  1920. */
  1921. int buildin_deletearray(struct script_state *st)
  1922. {
  1923. struct map_session_data *sd=NULL;
  1924. int num=st->stack->stack_data[st->start+2].u.num;
  1925. char *name=str_buf+str_data[num&0x00ffffff].str;
  1926. char prefix=*name;
  1927. char postfix=name[strlen(name)-1];
  1928. int count=1;
  1929. int i,sz=getarraysize(st,num,postfix)-(num>>24)-count+1;
  1930. if( (st->end > st->start+3) )
  1931. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1932. if( prefix!='$' && prefix!='@' ){
  1933. printf("buildin_deletearray: illegal scope !\n");
  1934. return 0;
  1935. }
  1936. if( prefix!='$' )
  1937. sd=script_rid2sd(st);
  1938. for(i=0;i<sz;i++){
  1939. set_reg(sd,num+(i<<24),name, get_val2(st,num+((i+count)<<24) ) );
  1940. }
  1941. for(;i<(128-(num>>24));i++){
  1942. if( postfix!='$' ) set_reg(sd,num+(i<<24),name, 0);
  1943. if( postfix=='$' ) set_reg(sd,num+(i<<24),name, "");
  1944. }
  1945. return 0;
  1946. }
  1947. /*==========================================
  1948. * 指定要素を表す値(キー)を所得する
  1949. *------------------------------------------
  1950. */
  1951. int buildin_getelementofarray(struct script_state *st)
  1952. {
  1953. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  1954. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1955. if(i>127 || i<0){
  1956. printf("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  1957. push_val(st->stack,C_INT,0);
  1958. }else{
  1959. push_val(st->stack,C_NAME,
  1960. (i<<24) | st->stack->stack_data[st->start+2].u.num );
  1961. }
  1962. }else{
  1963. printf("script: getelementofarray (operator[]): param1 not name !\n");
  1964. push_val(st->stack,C_INT,0);
  1965. }
  1966. return 0;
  1967. }
  1968. /*==========================================
  1969. *
  1970. *------------------------------------------
  1971. */
  1972. int buildin_setlook(struct script_state *st)
  1973. {
  1974. int type,val;
  1975. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  1976. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1977. pc_changelook(script_rid2sd(st),type,val);
  1978. return 0;
  1979. }
  1980. /*==========================================
  1981. *
  1982. *------------------------------------------
  1983. */
  1984. int buildin_cutin(struct script_state *st)
  1985. {
  1986. int type;
  1987. conv_str(st,& (st->stack->stack_data[st->start+2]));
  1988. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  1989. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  1990. return 0;
  1991. }
  1992. /*==========================================
  1993. * カードのイラストを表示する
  1994. *------------------------------------------
  1995. */
  1996. int buildin_cutincard(struct script_state *st)
  1997. {
  1998. int itemid;
  1999. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2000. clif_cutin(script_rid2sd(st),itemdb_search(itemid)->cardillustname,4);
  2001. return 0;
  2002. }
  2003. /*==========================================
  2004. *
  2005. *------------------------------------------
  2006. */
  2007. int buildin_viewpoint(struct script_state *st)
  2008. {
  2009. int type,x,y,id,color;
  2010. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2011. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2012. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2013. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2014. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  2015. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  2016. return 0;
  2017. }
  2018. /*==========================================
  2019. *
  2020. *------------------------------------------
  2021. */
  2022. int buildin_countitem(struct script_state *st)
  2023. {
  2024. int nameid=0,count=0,i;
  2025. struct map_session_data *sd;
  2026. struct script_data *data;
  2027. sd = script_rid2sd(st);
  2028. data=&(st->stack->stack_data[st->start+2]);
  2029. get_val(st,data);
  2030. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2031. const char *name=conv_str(st,data);
  2032. struct item_data *item_data;
  2033. if( (item_data = itemdb_searchname(name)) != NULL)
  2034. nameid=item_data->nameid;
  2035. }else
  2036. nameid=conv_num(st,data);
  2037. if (nameid>=500) //if no such ID then skip this iteration
  2038. for(i=0;i<MAX_INVENTORY;i++){
  2039. if(sd->status.inventory[i].nameid==nameid)
  2040. count+=sd->status.inventory[i].amount;
  2041. }
  2042. else{
  2043. if(battle_config.error_log)
  2044. printf("wrong item ID : countitem(%i)\n",nameid);
  2045. }
  2046. push_val(st->stack,C_INT,count);
  2047. return 0;
  2048. }
  2049. /*==========================================
  2050. * 重量チェック
  2051. *------------------------------------------
  2052. */
  2053. int buildin_checkweight(struct script_state *st)
  2054. {
  2055. int nameid=0,amount;
  2056. struct map_session_data *sd;
  2057. struct script_data *data;
  2058. sd = script_rid2sd(st);
  2059. data=&(st->stack->stack_data[st->start+2]);
  2060. get_val(st,data);
  2061. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2062. const char *name=conv_str(st,data);
  2063. struct item_data *item_data = itemdb_searchname(name);
  2064. if( item_data )
  2065. nameid=item_data->nameid;
  2066. }else
  2067. nameid=conv_num(st,data);
  2068. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2069. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  2070. push_val(st->stack,C_INT,0);
  2071. }
  2072. sd=script_rid2sd(st);
  2073. if(itemdb_weight(nameid)*amount + sd->weight > sd->max_weight){
  2074. push_val(st->stack,C_INT,0);
  2075. } else {
  2076. push_val(st->stack,C_INT,1);
  2077. }
  2078. return 0;
  2079. }
  2080. /*==========================================
  2081. *
  2082. *------------------------------------------
  2083. */
  2084. int buildin_getitem(struct script_state *st)
  2085. {
  2086. int nameid,amount,flag = 0;
  2087. struct item item_tmp;
  2088. struct map_session_data *sd;
  2089. struct script_data *data;
  2090. sd = script_rid2sd(st);
  2091. data=&(st->stack->stack_data[st->start+2]);
  2092. get_val(st,data);
  2093. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2094. const char *name=conv_str(st,data);
  2095. struct item_data *item_data = itemdb_searchname(name);
  2096. nameid=512; //Apple item ID
  2097. if( item_data != NULL)
  2098. nameid=item_data->nameid;
  2099. }else
  2100. nameid=conv_num(st,data);
  2101. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0) {
  2102. return 0; //return if amount <=0, skip the useles iteration
  2103. }
  2104. //Violet Box, Blue Box, etc - random item pick
  2105. if(nameid<0) { // ランダム
  2106. nameid=itemdb_searchrandomid(-nameid);
  2107. #ifndef TXT_ONLY
  2108. if(log_config.present > 0)
  2109. log_present(sd, -nameid, nameid);
  2110. #endif //USE_SQL
  2111. flag = 1;
  2112. }
  2113. if(nameid > 0) {
  2114. memset(&item_tmp,0,sizeof(item_tmp));
  2115. item_tmp.nameid=nameid;
  2116. if(!flag)
  2117. item_tmp.identify=1;
  2118. else
  2119. item_tmp.identify=!itemdb_isequip3(nameid);
  2120. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  2121. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  2122. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  2123. return 0;
  2124. if((flag = pc_additem(sd,&item_tmp,amount))) {
  2125. clif_additem(sd,0,0,flag);
  2126. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  2127. }
  2128. }
  2129. return 0;
  2130. }
  2131. /*==========================================
  2132. *
  2133. *------------------------------------------
  2134. */
  2135. int buildin_getitem2(struct script_state *st)
  2136. {
  2137. int nameid,amount,flag = 0;
  2138. int iden,ref,attr,c1,c2,c3,c4;
  2139. struct item_data *item_data;
  2140. struct item item_tmp;
  2141. struct map_session_data *sd;
  2142. struct script_data *data;
  2143. sd = script_rid2sd(st);
  2144. data=&(st->stack->stack_data[st->start+2]);
  2145. get_val(st,data);
  2146. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2147. const char *name=conv_str(st,data);
  2148. struct item_data *item_data = itemdb_searchname(name);
  2149. nameid=512; //Apple item ID
  2150. if( item_data )
  2151. nameid=item_data->nameid;
  2152. }else
  2153. nameid=conv_num(st,data);
  2154. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2155. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2156. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2157. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  2158. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  2159. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  2160. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  2161. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  2162. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  2163. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  2164. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  2165. return 0;
  2166. if(nameid<0) { // ランダム
  2167. nameid=itemdb_searchrandomid(-nameid);
  2168. flag = 1;
  2169. }
  2170. if(nameid > 0) {
  2171. memset(&item_tmp,0,sizeof(item_tmp));
  2172. item_data=itemdb_search(nameid);
  2173. if(item_data->type==4 || item_data->type==5){
  2174. if(ref > 10) ref = 10;
  2175. }
  2176. else if(item_data->type==7) {
  2177. iden = 1;
  2178. ref = 0;
  2179. }
  2180. else {
  2181. iden = 1;
  2182. ref = attr = 0;
  2183. }
  2184. item_tmp.nameid=nameid;
  2185. if(!flag)
  2186. item_tmp.identify=iden;
  2187. else if(item_data->type==4 || item_data->type==5)
  2188. item_tmp.identify=0;
  2189. item_tmp.refine=ref;
  2190. item_tmp.attribute=attr;
  2191. item_tmp.card[0]=c1;
  2192. item_tmp.card[1]=c2;
  2193. item_tmp.card[2]=c3;
  2194. item_tmp.card[3]=c4;
  2195. if((flag = pc_additem(sd,&item_tmp,amount))) {
  2196. clif_additem(sd,0,0,flag);
  2197. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  2198. }
  2199. }
  2200. return 0;
  2201. }
  2202. /*==========================================
  2203. *
  2204. *------------------------------------------
  2205. */
  2206. int buildin_makeitem(struct script_state *st)
  2207. {
  2208. int nameid,amount,flag = 0;
  2209. int x,y,m;
  2210. char *mapname;
  2211. struct item item_tmp;
  2212. struct map_session_data *sd;
  2213. struct script_data *data;
  2214. sd = script_rid2sd(st);
  2215. data=&(st->stack->stack_data[st->start+2]);
  2216. get_val(st,data);
  2217. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2218. const char *name=conv_str(st,data);
  2219. struct item_data *item_data = itemdb_searchname(name);
  2220. nameid=512; //Apple Item ID
  2221. if( item_data )
  2222. nameid=item_data->nameid;
  2223. }else
  2224. nameid=conv_num(st,data);
  2225. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2226. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  2227. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  2228. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  2229. if( sd && strcmp(mapname,"this")==0)
  2230. m=sd->bl.m;
  2231. else
  2232. m=map_mapname2mapid(mapname);
  2233. if(nameid<0) { // ランダム
  2234. nameid=itemdb_searchrandomid(-nameid);
  2235. flag = 1;
  2236. }
  2237. if(nameid > 0) {
  2238. memset(&item_tmp,0,sizeof(item_tmp));
  2239. item_tmp.nameid=nameid;
  2240. if(!flag)
  2241. item_tmp.identify=1;
  2242. else
  2243. item_tmp.identify=!itemdb_isequip3(nameid);
  2244. // clif_additem(sd,0,0,flag);
  2245. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  2246. }
  2247. return 0;
  2248. }
  2249. /*==========================================
  2250. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  2251. *------------------------------------------
  2252. */
  2253. int buildin_delitem(struct script_state *st)
  2254. {
  2255. int nameid=0,amount,i,important_item=0;
  2256. struct map_session_data *sd;
  2257. struct script_data *data;
  2258. sd = script_rid2sd(st);
  2259. data=&(st->stack->stack_data[st->start+2]);
  2260. get_val(st,data);
  2261. if( data->type==C_STR || data->type==C_CONSTSTR ){
  2262. const char *name=conv_str(st,data);
  2263. struct item_data *item_data = itemdb_searchname(name);
  2264. //nameid=512;
  2265. if( item_data )
  2266. nameid=item_data->nameid;
  2267. }else
  2268. nameid=conv_num(st,data);
  2269. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2270. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  2271. //printf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  2272. return 0;
  2273. }
  2274. sd=script_rid2sd(st);
  2275. //1st pass
  2276. //here we won't delete items with CARDS, named items but we count them
  2277. for(i=0;i<MAX_INVENTORY;i++){
  2278. //we don't delete wrong item or equipped item
  2279. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  2280. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  2281. continue;
  2282. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  2283. if(sd->inventory_data[i]->type==7 && sd->status.inventory[i].card[0] == (short)0xff00 && search_petDB_index(nameid, PET_EGG) >= 0 ){
  2284. intif_delete_petdata(*((long *)(&sd->status.inventory[i].card[1])));
  2285. //clear egg flag. so it won't be put in IMPORTANT items (eggs look like item with 2 cards ^_^)
  2286. sd->status.inventory[i].card[1] = sd->status.inventory[i].card[0] = 0;
  2287. //now this egg'll be deleted as a common unimportant item
  2288. }
  2289. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  2290. if( sd->status.inventory[i].card[0] || sd->status.inventory[i].card[1] ||
  2291. sd->status.inventory[i].card[2] || sd->status.inventory[i].card[3] || sd->status.inventory[i].refine) {
  2292. //this is important item, count it
  2293. important_item++;
  2294. continue;
  2295. }
  2296. if(sd->status.inventory[i].amount>=amount){
  2297. pc_delitem(sd,i,amount,0);
  2298. return 0; //we deleted exact amount of items. now exit
  2299. } else {
  2300. amount-=sd->status.inventory[i].amount;
  2301. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  2302. }
  2303. }
  2304. //2nd pass
  2305. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  2306. if (important_item>0 && amount>0)
  2307. for(i=0;i<MAX_INVENTORY;i++){
  2308. //we don't delete wrong item
  2309. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  2310. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  2311. continue;
  2312. if(sd->status.inventory[i].amount>=amount){
  2313. pc_delitem(sd,i,amount,0);
  2314. return 0; //we deleted exact amount of items. now exit
  2315. } else {
  2316. amount-=sd->status.inventory[i].amount;
  2317. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  2318. }
  2319. }
  2320. return 0;
  2321. }
  2322. /*==========================================
  2323. *キャラ関係のパラメータ取得
  2324. *------------------------------------------
  2325. */
  2326. int buildin_readparam(struct script_state *st)
  2327. {
  2328. int type;
  2329. struct map_session_data *sd;
  2330. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2331. if( st->end>st->start+3 )
  2332. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  2333. else
  2334. sd=script_rid2sd(st);
  2335. if(sd==NULL){
  2336. push_val(st->stack,C_INT,-1);
  2337. return 0;
  2338. }
  2339. push_val(st->stack,C_INT,pc_readparam(sd,type));
  2340. return 0;
  2341. }
  2342. /*==========================================
  2343. *キャラ関係のID取得
  2344. *------------------------------------------
  2345. */
  2346. int buildin_getcharid(struct script_state *st)
  2347. {
  2348. int num;
  2349. struct map_session_data *sd;
  2350. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2351. if( st->end>st->start+3 )
  2352. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  2353. else
  2354. sd=script_rid2sd(st);
  2355. if(sd==NULL){
  2356. push_val(st->stack,C_INT,-1);
  2357. return 0;
  2358. }
  2359. if(num==0)
  2360. push_val(st->stack,C_INT,sd->status.char_id);
  2361. if(num==1)
  2362. push_val(st->stack,C_INT,sd->status.party_id);
  2363. if(num==2)
  2364. push_val(st->stack,C_INT,sd->status.guild_id);
  2365. if(num==3)
  2366. push_val(st->stack,C_INT,sd->status.account_id);
  2367. return 0;
  2368. }
  2369. /*==========================================
  2370. *指定IDのPT名取得
  2371. *------------------------------------------
  2372. */
  2373. char *buildin_getpartyname_sub(int party_id)
  2374. {
  2375. struct party *p;
  2376. p=NULL;
  2377. p=party_search(party_id);
  2378. if(p!=NULL){
  2379. char *buf;
  2380. buf=(char *)aCalloc(24,sizeof(char));
  2381. strcpy(buf,p->name);
  2382. return buf;
  2383. }
  2384. return 0;
  2385. }
  2386. int buildin_getpartyname(struct script_state *st)
  2387. {
  2388. char *name;
  2389. int party_id;
  2390. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2391. name=buildin_getpartyname_sub(party_id);
  2392. if(name!=0)
  2393. push_str(st->stack,C_STR,name);
  2394. else
  2395. push_str(st->stack,C_CONSTSTR,"null");
  2396. return 0;
  2397. }
  2398. /*==========================================
  2399. *指定IDのPT人数とメンバーID取得
  2400. *------------------------------------------
  2401. */
  2402. int buildin_getpartymember(struct script_state *st)
  2403. {
  2404. struct party *p;
  2405. int i,j=0;
  2406. p=NULL;
  2407. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  2408. if(p!=NULL){
  2409. for(i=0;i<MAX_PARTY;i++){
  2410. if(p->member[i].account_id){
  2411. // printf("name:%s %d\n",p->member[i].name,i);
  2412. mapreg_setregstr(add_str("$@partymembername$")+(i<<24),p->member[i].name);
  2413. j++;
  2414. }
  2415. }
  2416. }
  2417. mapreg_setreg(add_str("$@partymembercount"),j);
  2418. return 0;
  2419. }
  2420. /*==========================================
  2421. *指定IDのギルド名取得
  2422. *------------------------------------------
  2423. */
  2424. char *buildin_getguildname_sub(int guild_id)
  2425. {
  2426. struct guild *g=NULL;
  2427. g=guild_search(guild_id);
  2428. if(g!=NULL){
  2429. char *buf;
  2430. buf=(char *)aCalloc(24,sizeof(char));
  2431. strcpy(buf,g->name);
  2432. return buf;
  2433. }
  2434. return 0;
  2435. }
  2436. int buildin_getguildname(struct script_state *st)
  2437. {
  2438. char *name;
  2439. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2440. name=buildin_getguildname_sub(guild_id);
  2441. if(name!=0)
  2442. push_str(st->stack,C_STR,name);
  2443. else
  2444. push_str(st->stack,C_CONSTSTR,"null");
  2445. return 0;
  2446. }
  2447. /*==========================================
  2448. *指定IDのGuildMaster名取得
  2449. *------------------------------------------
  2450. */
  2451. char *buildin_getguildmaster_sub(int guild_id)
  2452. {
  2453. struct guild *g=NULL;
  2454. g=guild_search(guild_id);
  2455. if(g!=NULL){
  2456. char *buf;
  2457. buf=(char *)aCalloc(24,sizeof(char));
  2458. strncpy(buf,g->master, 23);
  2459. return buf;
  2460. }
  2461. return 0;
  2462. }
  2463. int buildin_getguildmaster(struct script_state *st)
  2464. {
  2465. char *master;
  2466. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2467. master=buildin_getguildmaster_sub(guild_id);
  2468. if(master!=0)
  2469. push_str(st->stack,C_STR,master);
  2470. else
  2471. push_str(st->stack,C_CONSTSTR,"null");
  2472. return 0;
  2473. }
  2474. int buildin_getguildmasterid(struct script_state *st)
  2475. {
  2476. char *master;
  2477. struct map_session_data *sd=NULL;
  2478. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2479. master=buildin_getguildmaster_sub(guild_id);
  2480. if(master!=0){
  2481. if((sd=map_nick2sd(master)) == NULL){
  2482. push_val(st->stack,C_INT,0);
  2483. return 0;
  2484. }
  2485. push_val(st->stack,C_INT,sd->status.char_id);
  2486. }else{
  2487. push_val(st->stack,C_INT,0);
  2488. }
  2489. return 0;
  2490. }
  2491. /*==========================================
  2492. * キャラクタの名前
  2493. *------------------------------------------
  2494. */
  2495. int buildin_strcharinfo(struct script_state *st)
  2496. {
  2497. struct map_session_data *sd;
  2498. int num;
  2499. sd=script_rid2sd(st);
  2500. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2501. if(num==0){
  2502. char *buf;
  2503. buf=(char *)aCalloc(24,sizeof(char));
  2504. strncpy(buf,sd->status.name, 23);
  2505. push_str(st->stack,C_STR,buf);
  2506. }
  2507. if(num==1){
  2508. char *buf;
  2509. buf=buildin_getpartyname_sub(sd->status.party_id);
  2510. if(buf!=0)
  2511. push_str(st->stack,C_STR,buf);
  2512. else
  2513. push_str(st->stack,C_CONSTSTR,"");
  2514. }
  2515. if(num==2){
  2516. char *buf;
  2517. buf=buildin_getguildname_sub(sd->status.guild_id);
  2518. if(buf!=0)
  2519. push_str(st->stack,C_STR,buf);
  2520. else
  2521. push_str(st->stack,C_CONSTSTR,"");
  2522. }
  2523. return 0;
  2524. }
  2525. unsigned int equip[10]={0x0100,0x0010,0x0020,0x0002,0x0004,0x0040,0x0008,0x0080,0x0200,0x0001};
  2526. /*==========================================
  2527. * GetEquipID(Pos); Pos: 1-10
  2528. *------------------------------------------
  2529. */
  2530. int buildin_getequipid(struct script_state *st)
  2531. {
  2532. int i,num;
  2533. struct map_session_data *sd;
  2534. struct item_data* item;
  2535. sd=script_rid2sd(st);
  2536. if(sd == NULL)
  2537. {
  2538. printf("getequipid: sd == NULL\n");
  2539. return 0;
  2540. }
  2541. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2542. i=pc_checkequip(sd,equip[num-1]);
  2543. if(i >= 0){
  2544. item=sd->inventory_data[i];
  2545. if(item)
  2546. push_val(st->stack,C_INT,item->nameid);
  2547. else
  2548. push_val(st->stack,C_INT,0);
  2549. }else{
  2550. push_val(st->stack,C_INT,-1);
  2551. }
  2552. return 0;
  2553. }
  2554. /*==========================================
  2555. * 装備名文字列(精錬メニュー用)
  2556. *------------------------------------------
  2557. */
  2558. int buildin_getequipname(struct script_state *st)
  2559. {
  2560. int i,num;
  2561. struct map_session_data *sd;
  2562. struct item_data* item;
  2563. char *buf;
  2564. buf=(char *)aCalloc(64,sizeof(char));
  2565. sd=script_rid2sd(st);
  2566. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2567. i=pc_checkequip(sd,equip[num-1]);
  2568. if(i >= 0){
  2569. item=sd->inventory_data[i];
  2570. if(item)
  2571. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  2572. else
  2573. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  2574. }else{
  2575. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  2576. }
  2577. push_str(st->stack,C_STR,buf);
  2578. return 0;
  2579. }
  2580. /*==========================================
  2581. * getbrokenid [Valaris]
  2582. *------------------------------------------
  2583. */
  2584. int buildin_getbrokenid(struct script_state *st)
  2585. {
  2586. int i,num,id=0,brokencounter=0;
  2587. struct map_session_data *sd;
  2588. sd=script_rid2sd(st);
  2589. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2590. for(i=0; i<MAX_INVENTORY; i++) {
  2591. if(sd->status.inventory[i].attribute==1){
  2592. brokencounter++;
  2593. if(num==brokencounter){
  2594. id=sd->status.inventory[i].nameid;
  2595. break;
  2596. }
  2597. }
  2598. }
  2599. push_val(st->stack,C_INT,id);
  2600. return 0;
  2601. }
  2602. /*==========================================
  2603. * repair [Valaris]
  2604. *------------------------------------------
  2605. */
  2606. int buildin_repair(struct script_state *st)
  2607. {
  2608. int i,num;
  2609. int repaircounter=0;
  2610. struct map_session_data *sd;
  2611. sd=script_rid2sd(st);
  2612. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2613. for(i=0; i<MAX_INVENTORY; i++) {
  2614. if(sd->status.inventory[i].attribute==1){
  2615. repaircounter++;
  2616. if(num==repaircounter){
  2617. sd->status.inventory[i].attribute=0;
  2618. clif_equiplist(sd);
  2619. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  2620. clif_misceffect(&sd->bl, 3);
  2621. clif_displaymessage(sd->fd,"Item has been repaired.");
  2622. break;
  2623. }
  2624. }
  2625. }
  2626. return 0;
  2627. }
  2628. /*==========================================
  2629. * 装備チェック
  2630. *------------------------------------------
  2631. */
  2632. int buildin_getequipisequiped(struct script_state *st)
  2633. {
  2634. int i,num;
  2635. struct map_session_data *sd;
  2636. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2637. sd=script_rid2sd(st);
  2638. i=pc_checkequip(sd,equip[num-1]);
  2639. if(i >= 0){
  2640. push_val(st->stack,C_INT,1);
  2641. }else{
  2642. push_val(st->stack,C_INT,0);
  2643. }
  2644. return 0;
  2645. }
  2646. /*==========================================
  2647. * 装備品精錬可能チェック
  2648. *------------------------------------------
  2649. */
  2650. int buildin_getequipisenableref(struct script_state *st)
  2651. {
  2652. int i,num;
  2653. struct map_session_data *sd;
  2654. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2655. sd=script_rid2sd(st);
  2656. i=pc_checkequip(sd,equip[num-1]);
  2657. if(i >= 0 && num<7 && sd->inventory_data[i] && (num!=1 || sd->inventory_data[i]->def > 1
  2658. || (sd->inventory_data[i]->def==1 && sd->inventory_data[i]->equip_script==NULL)
  2659. || (sd->inventory_data[i]->def<=0 && sd->inventory_data[i]->equip_script!=NULL))
  2660. ){
  2661. push_val(st->stack,C_INT,1);
  2662. }else{
  2663. push_val(st->stack,C_INT,0);
  2664. }
  2665. return 0;
  2666. }
  2667. /*==========================================
  2668. * 装備品鑑定チェック
  2669. *------------------------------------------
  2670. */
  2671. int buildin_getequipisidentify(struct script_state *st)
  2672. {
  2673. int i,num;
  2674. struct map_session_data *sd;
  2675. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2676. sd=script_rid2sd(st);
  2677. i=pc_checkequip(sd,equip[num-1]);
  2678. if(i >= 0)
  2679. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  2680. else
  2681. push_val(st->stack,C_INT,0);
  2682. return 0;
  2683. }
  2684. /*==========================================
  2685. * 装備品精錬度
  2686. *------------------------------------------
  2687. */
  2688. int buildin_getequiprefinerycnt(struct script_state *st)
  2689. {
  2690. int i,num;
  2691. struct map_session_data *sd;
  2692. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2693. sd=script_rid2sd(st);
  2694. i=pc_checkequip(sd,equip[num-1]);
  2695. if(i >= 0)
  2696. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  2697. else
  2698. push_val(st->stack,C_INT,0);
  2699. return 0;
  2700. }
  2701. /*==========================================
  2702. * 装備品武器LV
  2703. *------------------------------------------
  2704. */
  2705. int buildin_getequipweaponlv(struct script_state *st)
  2706. {
  2707. int i,num;
  2708. struct map_session_data *sd;
  2709. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2710. sd=script_rid2sd(st);
  2711. i=pc_checkequip(sd,equip[num-1]);
  2712. if(i >= 0 && sd->inventory_data[i])
  2713. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  2714. else
  2715. push_val(st->stack,C_INT,0);
  2716. return 0;
  2717. }
  2718. /*==========================================
  2719. * 装備品精錬成功率
  2720. *------------------------------------------
  2721. */
  2722. int buildin_getequippercentrefinery(struct script_state *st)
  2723. {
  2724. int i,num;
  2725. struct map_session_data *sd;
  2726. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2727. sd=script_rid2sd(st);
  2728. i=pc_checkequip(sd,equip[num-1]);
  2729. if(i >= 0)
  2730. push_val(st->stack,C_INT,pc_percentrefinery(sd,&sd->status.inventory[i]));
  2731. else
  2732. push_val(st->stack,C_INT,0);
  2733. return 0;
  2734. }
  2735. /*==========================================
  2736. * 精錬成功
  2737. *------------------------------------------
  2738. */
  2739. int buildin_successrefitem(struct script_state *st)
  2740. {
  2741. int i,num,ep;
  2742. struct map_session_data *sd;
  2743. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2744. sd=script_rid2sd(st);
  2745. i=pc_checkequip(sd,equip[num-1]);
  2746. if(i >= 0) {
  2747. ep=sd->status.inventory[i].equip;
  2748. #ifndef TXT_ONLY
  2749. if(log_config.refine > 0)
  2750. log_refine(sd, i, 1);
  2751. #endif //USE_SQL
  2752. sd->status.inventory[i].refine++;
  2753. pc_unequipitem(sd,i,0);
  2754. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  2755. clif_delitem(sd,i,1);
  2756. clif_additem(sd,i,1,0);
  2757. pc_equipitem(sd,i,ep);
  2758. clif_misceffect(&sd->bl,3);
  2759. }
  2760. return 0;
  2761. }
  2762. /*==========================================
  2763. * 精錬失敗
  2764. *------------------------------------------
  2765. */
  2766. int buildin_failedrefitem(struct script_state *st)
  2767. {
  2768. int i,num;
  2769. struct map_session_data *sd;
  2770. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2771. sd=script_rid2sd(st);
  2772. i=pc_checkequip(sd,equip[num-1]);
  2773. if(i >= 0) {
  2774. #ifndef TXT_ONLY
  2775. if(log_config.refine > 0)
  2776. log_refine(sd, i, 0);
  2777. #endif //USE_SQL
  2778. sd->status.inventory[i].refine = 0;
  2779. pc_unequipitem(sd,i,0);
  2780. // 精錬失敗エフェクトのパケット
  2781. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  2782. pc_delitem(sd,i,1,0);
  2783. // 他の人にも失敗を通知
  2784. clif_misceffect(&sd->bl,2);
  2785. }
  2786. return 0;
  2787. }
  2788. /*==========================================
  2789. *
  2790. *------------------------------------------
  2791. */
  2792. int buildin_statusup(struct script_state *st)
  2793. {
  2794. int type;
  2795. struct map_session_data *sd;
  2796. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2797. sd=script_rid2sd(st);
  2798. pc_statusup(sd,type);
  2799. return 0;
  2800. }
  2801. /*==========================================
  2802. *
  2803. *------------------------------------------
  2804. */
  2805. int buildin_statusup2(struct script_state *st)
  2806. {
  2807. int type,val;
  2808. struct map_session_data *sd;
  2809. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2810. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2811. sd=script_rid2sd(st);
  2812. pc_statusup2(sd,type,val);
  2813. return 0;
  2814. }
  2815. /*==========================================
  2816. * 装備品による能力値ボーナス
  2817. *------------------------------------------
  2818. */
  2819. int buildin_bonus(struct script_state *st)
  2820. {
  2821. int type,val;
  2822. struct map_session_data *sd;
  2823. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2824. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2825. sd=script_rid2sd(st);
  2826. pc_bonus(sd,type,val);
  2827. return 0;
  2828. }
  2829. /*==========================================
  2830. * 装備品による能力値ボーナス
  2831. *------------------------------------------
  2832. */
  2833. int buildin_bonus2(struct script_state *st)
  2834. {
  2835. int type,type2,val;
  2836. struct map_session_data *sd;
  2837. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2838. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2839. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2840. sd=script_rid2sd(st);
  2841. pc_bonus2(sd,type,type2,val);
  2842. return 0;
  2843. }
  2844. /*==========================================
  2845. * 装備品による能力値ボーナス
  2846. *------------------------------------------
  2847. */
  2848. int buildin_bonus3(struct script_state *st)
  2849. {
  2850. int type,type2,type3,val;
  2851. struct map_session_data *sd;
  2852. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2853. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2854. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2855. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2856. sd=script_rid2sd(st);
  2857. pc_bonus3(sd,type,type2,type3,val);
  2858. return 0;
  2859. }
  2860. /*==========================================
  2861. * スキル所得
  2862. *------------------------------------------
  2863. */
  2864. int buildin_skill(struct script_state *st)
  2865. {
  2866. int id,level,flag=1;
  2867. struct map_session_data *sd;
  2868. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2869. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2870. if( st->end>st->start+4 )
  2871. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  2872. sd=script_rid2sd(st);
  2873. pc_skill(sd,id,level,flag);
  2874. return 0;
  2875. }
  2876. // add x levels of skill (stackable) [Valaris]
  2877. int buildin_addtoskill(struct script_state *st)
  2878. {
  2879. int id,level,flag=2;
  2880. struct map_session_data *sd;
  2881. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2882. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2883. if( st->end>st->start+4 )
  2884. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  2885. sd=script_rid2sd(st);
  2886. pc_skill(sd,id,level,flag);
  2887. return 0;
  2888. }
  2889. /*==========================================
  2890. * ギルドスキル取得
  2891. *------------------------------------------
  2892. */
  2893. int buildin_guildskill(struct script_state *st)
  2894. {
  2895. int id,level,flag=0;
  2896. struct map_session_data *sd;
  2897. int i=0;
  2898. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2899. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2900. if( st->end>st->start+4 )
  2901. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  2902. sd=script_rid2sd(st);
  2903. for(i=0;i<level;i++)
  2904. guild_skillup(sd,id,flag);
  2905. return 0;
  2906. }
  2907. /*==========================================
  2908. * スキルレベル所得
  2909. *------------------------------------------
  2910. */
  2911. int buildin_getskilllv(struct script_state *st)
  2912. {
  2913. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2914. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  2915. return 0;
  2916. }
  2917. /*==========================================
  2918. * getgdskilllv(Guild_ID, Skill_ID);
  2919. * skill_id = 10000 : GD_APPROVAL
  2920. * 10001 : GD_KAFRACONTACT
  2921. * 10002 : GD_GUARDIANRESEARCH
  2922. * 10003 : GD_GUARDUP
  2923. * 10004 : GD_EXTENSION
  2924. *------------------------------------------
  2925. */
  2926. int buildin_getgdskilllv(struct script_state *st)
  2927. {
  2928. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2929. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2930. struct guild *g=guild_search(guild_id);
  2931. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  2932. return 0;
  2933. /*
  2934. struct map_session_data *sd=NULL;
  2935. struct guild *g=NULL;
  2936. int skill_id;
  2937. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2938. sd=script_rid2sd(st);
  2939. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  2940. if(sd && g) {
  2941. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  2942. } else {
  2943. push_val(st->stack,C_INT,-1);
  2944. }
  2945. return 0;
  2946. */
  2947. }
  2948. /*==========================================
  2949. *
  2950. *------------------------------------------
  2951. */
  2952. int buildin_basicskillcheck(struct script_state *st)
  2953. {
  2954. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  2955. return 0;
  2956. }
  2957. /*==========================================
  2958. *
  2959. *------------------------------------------
  2960. */
  2961. int buildin_getgmlevel(struct script_state *st)
  2962. {
  2963. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  2964. return 0;
  2965. }
  2966. /*==========================================
  2967. *
  2968. *------------------------------------------
  2969. */
  2970. int buildin_end(struct script_state *st)
  2971. {
  2972. st->state = END;
  2973. return 0;
  2974. }
  2975. /*==========================================
  2976. *
  2977. *------------------------------------------
  2978. */
  2979. int buildin_checkoption(struct script_state *st)
  2980. {
  2981. int type;
  2982. struct map_session_data *sd;
  2983. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2984. sd=script_rid2sd(st);
  2985. if(sd->status.option & type){
  2986. push_val(st->stack,C_INT,1);
  2987. } else {
  2988. push_val(st->stack,C_INT,0);
  2989. }
  2990. return 0;
  2991. }
  2992. /*==========================================
  2993. *
  2994. *------------------------------------------
  2995. */
  2996. int buildin_setoption(struct script_state *st)
  2997. {
  2998. int type;
  2999. struct map_session_data *sd;
  3000. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3001. sd=script_rid2sd(st);
  3002. pc_setoption(sd,type);
  3003. return 0;
  3004. }
  3005. /*==========================================
  3006. * Checkcart [Valaris]
  3007. *------------------------------------------
  3008. */
  3009. int buildin_checkcart(struct script_state *st)
  3010. {
  3011. struct map_session_data *sd;
  3012. sd=script_rid2sd(st);
  3013. if(pc_iscarton(sd)){
  3014. push_val(st->stack,C_INT,1);
  3015. } else {
  3016. push_val(st->stack,C_INT,0);
  3017. }
  3018. return 0;
  3019. }
  3020. /*==========================================
  3021. * カートを付ける
  3022. *------------------------------------------
  3023. */
  3024. int buildin_setcart(struct script_state *st)
  3025. {
  3026. struct map_session_data *sd;
  3027. sd=script_rid2sd(st);
  3028. pc_setcart(sd,1);
  3029. return 0;
  3030. }
  3031. /*==========================================
  3032. * checkfalcon [Valaris]
  3033. *------------------------------------------
  3034. */
  3035. int buildin_checkfalcon(struct script_state *st)
  3036. {
  3037. struct map_session_data *sd;
  3038. sd=script_rid2sd(st);
  3039. if(pc_isfalcon(sd)){
  3040. push_val(st->stack,C_INT,1);
  3041. } else {
  3042. push_val(st->stack,C_INT,0);
  3043. }
  3044. return 0;
  3045. }
  3046. /*==========================================
  3047. * 鷹を付ける
  3048. *------------------------------------------
  3049. */
  3050. int buildin_setfalcon(struct script_state *st)
  3051. {
  3052. struct map_session_data *sd;
  3053. sd=script_rid2sd(st);
  3054. pc_setfalcon(sd);
  3055. return 0;
  3056. }
  3057. /*==========================================
  3058. * Checkcart [Valaris]
  3059. *------------------------------------------
  3060. */
  3061. int buildin_checkriding(struct script_state *st)
  3062. {
  3063. struct map_session_data *sd;
  3064. sd=script_rid2sd(st);
  3065. if(pc_isriding(sd)){
  3066. push_val(st->stack,C_INT,1);
  3067. } else {
  3068. push_val(st->stack,C_INT,0);
  3069. }
  3070. return 0;
  3071. }
  3072. /*==========================================
  3073. * ペコペコ乗り
  3074. *------------------------------------------
  3075. */
  3076. int buildin_setriding(struct script_state *st)
  3077. {
  3078. struct map_session_data *sd;
  3079. sd=script_rid2sd(st);
  3080. pc_setriding(sd);
  3081. return 0;
  3082. }
  3083. /*==========================================
  3084. * セーブポイントの保存
  3085. *------------------------------------------
  3086. */
  3087. int buildin_savepoint(struct script_state *st)
  3088. {
  3089. int x,y;
  3090. char *str;
  3091. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3092. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3093. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3094. pc_setsavepoint(script_rid2sd(st),str,x,y);
  3095. return 0;
  3096. }
  3097. /*==========================================
  3098. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  3099. *------------------------------------------
  3100. */
  3101. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  3102. {
  3103. int type;
  3104. time_t timer;
  3105. struct tm *t;
  3106. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3107. switch(type){
  3108. case 1:
  3109. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  3110. time(&timer);
  3111. t=localtime(&timer);
  3112. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  3113. break;
  3114. case 0:
  3115. default:
  3116. //type 0:(System Ticks)
  3117. push_val(st->stack,C_INT,gettick());
  3118. break;
  3119. }
  3120. return 0;
  3121. }
  3122. /*==========================================
  3123. * GetTime(Type);
  3124. * 1: Sec 2: Min 3: Hour
  3125. * 4: WeekDay 5: MonthDay 6: Month
  3126. * 7: Year
  3127. *------------------------------------------
  3128. */
  3129. int buildin_gettime(struct script_state *st) /* Asgard Version */
  3130. {
  3131. int type;
  3132. time_t timer;
  3133. struct tm *t;
  3134. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3135. time(&timer);
  3136. t=localtime(&timer);
  3137. switch(type){
  3138. case 1://Sec(0~59)
  3139. push_val(st->stack,C_INT,t->tm_sec);
  3140. break;
  3141. case 2://Min(0~59)
  3142. push_val(st->stack,C_INT,t->tm_min);
  3143. break;
  3144. case 3://Hour(0~23)
  3145. push_val(st->stack,C_INT,t->tm_hour);
  3146. break;
  3147. case 4://WeekDay(0~6)
  3148. push_val(st->stack,C_INT,t->tm_wday);
  3149. break;
  3150. case 5://MonthDay(01~31)
  3151. push_val(st->stack,C_INT,t->tm_mday);
  3152. break;
  3153. case 6://Month(01~12)
  3154. push_val(st->stack,C_INT,t->tm_mon+1);
  3155. break;
  3156. case 7://Year(20xx)
  3157. push_val(st->stack,C_INT,t->tm_year+1900);
  3158. break;
  3159. default://(format error)
  3160. push_val(st->stack,C_INT,-1);
  3161. break;
  3162. }
  3163. return 0;
  3164. }
  3165. /*==========================================
  3166. * GetTimeStr("TimeFMT", Length);
  3167. *------------------------------------------
  3168. */
  3169. int buildin_gettimestr(struct script_state *st)
  3170. {
  3171. char *tmpstr;
  3172. char *fmtstr;
  3173. int maxlen;
  3174. time_t now = time(NULL);
  3175. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3176. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3177. tmpstr=(char *)aCalloc(maxlen+1,sizeof(char));
  3178. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  3179. tmpstr[maxlen]='\0';
  3180. push_str(st->stack,C_STR,tmpstr);
  3181. return 0;
  3182. }
  3183. /*==========================================
  3184. * カプラ倉庫を開く
  3185. *------------------------------------------
  3186. */
  3187. int buildin_openstorage(struct script_state *st)
  3188. {
  3189. storage_storageopen(script_rid2sd(st));
  3190. return 0;
  3191. }
  3192. int buildin_guildopenstorage(struct script_state *st)
  3193. {
  3194. struct map_session_data *sd=script_rid2sd(st);
  3195. int ret;
  3196. ret = storage_guild_storageopen(sd);
  3197. push_val(st->stack,C_INT,ret);
  3198. return 0;
  3199. }
  3200. /*==========================================
  3201. * アイテムによるスキル発動
  3202. *------------------------------------------
  3203. */
  3204. int buildin_itemskill(struct script_state *st)
  3205. {
  3206. int id,lv;
  3207. char *str;
  3208. struct map_session_data *sd=script_rid2sd(st);
  3209. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3210. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3211. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  3212. // 詠唱中にスキルアイテムは使用できない
  3213. if(sd->skilltimer != -1)
  3214. return 0;
  3215. sd->skillitem=id;
  3216. sd->skillitemlv=lv;
  3217. clif_item_skill(sd,id,lv,str);
  3218. return 0;
  3219. }
  3220. /*==========================================
  3221. * アイテム作成
  3222. *------------------------------------------
  3223. */
  3224. int buildin_produce(struct script_state *st)
  3225. {
  3226. int trigger;
  3227. struct map_session_data *sd=script_rid2sd(st);
  3228. if( sd->state.produce_flag == 1) return 0;
  3229. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3230. clif_skill_produce_mix_list(sd,trigger);
  3231. return 0;
  3232. }
  3233. /*==========================================
  3234. * NPCでペット作る
  3235. *------------------------------------------
  3236. */
  3237. int buildin_makepet(struct script_state *st)
  3238. {
  3239. struct map_session_data *sd = script_rid2sd(st);
  3240. struct script_data *data;
  3241. int id,pet_id;
  3242. data=&(st->stack->stack_data[st->start+2]);
  3243. get_val(st,data);
  3244. id=conv_num(st,data);
  3245. pet_id = search_petDB_index(id, PET_CLASS);
  3246. if (pet_id < 0)
  3247. pet_id = search_petDB_index(id, PET_EGG);
  3248. if (pet_id >= 0 && sd) {
  3249. sd->catch_target_class = pet_db[pet_id].class;
  3250. intif_create_pet(
  3251. sd->status.account_id, sd->status.char_id,
  3252. pet_db[pet_id].class, mob_db[pet_db[pet_id].class].lv,
  3253. pet_db[pet_id].EggID, 0, pet_db[pet_id].intimate,
  3254. 100, 0, 1, pet_db[pet_id].jname);
  3255. }
  3256. return 0;
  3257. }
  3258. /*==========================================
  3259. * NPCで経験値上げる
  3260. *------------------------------------------
  3261. */
  3262. int buildin_getexp(struct script_state *st)
  3263. {
  3264. struct map_session_data *sd = script_rid2sd(st);
  3265. int base=0,job=0;
  3266. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3267. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  3268. if(base<0 || job<0)
  3269. return 0;
  3270. if(sd)
  3271. pc_gainexp(sd,base,job);
  3272. return 0;
  3273. }
  3274. /*==========================================
  3275. * モンスター発生
  3276. *------------------------------------------
  3277. */
  3278. int buildin_monster(struct script_state *st)
  3279. {
  3280. int class,amount,x,y;
  3281. char *str,*map,*event="";
  3282. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  3283. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  3284. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  3285. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  3286. class=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3287. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  3288. if( st->end>st->start+8 )
  3289. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  3290. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class,amount,event);
  3291. return 0;
  3292. }
  3293. /*==========================================
  3294. * モンスター発生
  3295. *------------------------------------------
  3296. */
  3297. int buildin_areamonster(struct script_state *st)
  3298. {
  3299. int class,amount,x0,y0,x1,y1;
  3300. char *str,*map,*event="";
  3301. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  3302. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  3303. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  3304. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  3305. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  3306. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  3307. class=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3308. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3309. if( st->end>st->start+10 )
  3310. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  3311. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class,amount,event);
  3312. return 0;
  3313. }
  3314. /*==========================================
  3315. * モンスター削除
  3316. *------------------------------------------
  3317. */
  3318. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  3319. {
  3320. char *event=va_arg(ap,char *);
  3321. int allflag=va_arg(ap,int);
  3322. if(!allflag){
  3323. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  3324. mob_delete((struct mob_data *)bl);
  3325. return 0;
  3326. }else if(allflag){
  3327. if(((struct mob_data *)bl)->spawndelay1==-1 && ((struct mob_data *)bl)->spawndelay2==-1)
  3328. mob_delete((struct mob_data *)bl);
  3329. return 0;
  3330. }
  3331. return 0;
  3332. }
  3333. int buildin_killmonster(struct script_state *st)
  3334. {
  3335. char *mapname,*event;
  3336. int m,allflag=0;
  3337. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3338. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  3339. if(strcmp(event,"All")==0)
  3340. allflag = 1;
  3341. if( (m=map_mapname2mapid(mapname))<0 )
  3342. return 0;
  3343. map_foreachinarea(buildin_killmonster_sub,
  3344. m,0,0,map[m].xs,map[m].ys,BL_MOB, event ,allflag);
  3345. return 0;
  3346. }
  3347. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  3348. {
  3349. mob_delete((struct mob_data *)bl);
  3350. return 0;
  3351. }
  3352. int buildin_killmonsterall(struct script_state *st)
  3353. {
  3354. char *mapname;
  3355. int m;
  3356. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3357. if( (m=map_mapname2mapid(mapname))<0 )
  3358. return 0;
  3359. map_foreachinarea(buildin_killmonsterall_sub,
  3360. m,0,0,map[m].xs,map[m].ys,BL_MOB);
  3361. return 0;
  3362. }
  3363. /*==========================================
  3364. * イベント実行
  3365. *------------------------------------------
  3366. */
  3367. int buildin_doevent(struct script_state *st)
  3368. {
  3369. char *event;
  3370. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3371. npc_event(map_id2sd(st->rid),event,0);
  3372. return 0;
  3373. }
  3374. /*==========================================
  3375. * NPC主体イベント実行
  3376. *------------------------------------------
  3377. */
  3378. int buildin_donpcevent(struct script_state *st)
  3379. {
  3380. char *event;
  3381. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3382. npc_event_do(event);
  3383. return 0;
  3384. }
  3385. /*==========================================
  3386. * イベントタイマー追加
  3387. *------------------------------------------
  3388. */
  3389. int buildin_addtimer(struct script_state *st)
  3390. {
  3391. char *event;
  3392. int tick;
  3393. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3394. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  3395. pc_addeventtimer(script_rid2sd(st),tick,event);
  3396. return 0;
  3397. }
  3398. /*==========================================
  3399. * イベントタイマー削除
  3400. *------------------------------------------
  3401. */
  3402. int buildin_deltimer(struct script_state *st)
  3403. {
  3404. char *event;
  3405. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3406. pc_deleventtimer(script_rid2sd(st),event);
  3407. return 0;
  3408. }
  3409. /*==========================================
  3410. * イベントタイマーのカウント値追加
  3411. *------------------------------------------
  3412. */
  3413. int buildin_addtimercount(struct script_state *st)
  3414. {
  3415. char *event;
  3416. int tick;
  3417. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3418. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3419. pc_addeventtimercount(script_rid2sd(st),event,tick);
  3420. return 0;
  3421. }
  3422. /*==========================================
  3423. * NPCタイマー初期化
  3424. *------------------------------------------
  3425. */
  3426. int buildin_initnpctimer(struct script_state *st)
  3427. {
  3428. struct npc_data *nd;
  3429. if( st->end > st->start+2 )
  3430. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3431. else
  3432. nd=(struct npc_data *)map_id2bl(st->oid);
  3433. npc_settimerevent_tick(nd,0);
  3434. npc_timerevent_start(nd);
  3435. return 0;
  3436. }
  3437. /*==========================================
  3438. * NPCタイマー開始
  3439. *------------------------------------------
  3440. */
  3441. int buildin_startnpctimer(struct script_state *st)
  3442. {
  3443. struct npc_data *nd;
  3444. if( st->end > st->start+2 )
  3445. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3446. else
  3447. nd=(struct npc_data *)map_id2bl(st->oid);
  3448. npc_timerevent_start(nd);
  3449. return 0;
  3450. }
  3451. /*==========================================
  3452. * NPCタイマー停止
  3453. *------------------------------------------
  3454. */
  3455. int buildin_stopnpctimer(struct script_state *st)
  3456. {
  3457. struct npc_data *nd;
  3458. if( st->end > st->start+2 )
  3459. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3460. else
  3461. nd=(struct npc_data *)map_id2bl(st->oid);
  3462. npc_timerevent_stop(nd);
  3463. return 0;
  3464. }
  3465. /*==========================================
  3466. * NPCタイマー情報所得
  3467. *------------------------------------------
  3468. */
  3469. int buildin_getnpctimer(struct script_state *st)
  3470. {
  3471. struct npc_data *nd;
  3472. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3473. int val=0;
  3474. if( st->end > st->start+3 )
  3475. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  3476. else
  3477. nd=(struct npc_data *)map_id2bl(st->oid);
  3478. switch(type){
  3479. case 0: val=npc_gettimerevent_tick(nd); break;
  3480. case 1: val= (nd->u.scr.nexttimer>=0); break;
  3481. case 2: val= nd->u.scr.timeramount; break;
  3482. }
  3483. push_val(st->stack,C_INT,val);
  3484. return 0;
  3485. }
  3486. /*==========================================
  3487. * NPCタイマー値設定
  3488. *------------------------------------------
  3489. */
  3490. int buildin_setnpctimer(struct script_state *st)
  3491. {
  3492. int tick;
  3493. struct npc_data *nd;
  3494. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3495. if( st->end > st->start+3 )
  3496. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  3497. else
  3498. nd=(struct npc_data *)map_id2bl(st->oid);
  3499. npc_settimerevent_tick(nd,tick);
  3500. return 0;
  3501. }
  3502. /*==========================================
  3503. * 天の声アナウンス
  3504. *------------------------------------------
  3505. */
  3506. int buildin_announce(struct script_state *st)
  3507. {
  3508. char *str;
  3509. int flag;
  3510. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3511. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3512. if(flag&0x0f){
  3513. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  3514. (struct block_list *)script_rid2sd(st);
  3515. clif_GMmessage(bl,str,strlen(str)+1,flag);
  3516. }else
  3517. intif_GMmessage(str,strlen(str)+1,flag);
  3518. return 0;
  3519. }
  3520. /*==========================================
  3521. * 天の声アナウンス(特定マップ)
  3522. *------------------------------------------
  3523. */
  3524. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  3525. {
  3526. char *str;
  3527. int len,flag;
  3528. str=va_arg(ap,char *);
  3529. len=va_arg(ap,int);
  3530. flag=va_arg(ap,int);
  3531. clif_GMmessage(bl,str,len,flag|3);
  3532. return 0;
  3533. }
  3534. int buildin_mapannounce(struct script_state *st)
  3535. {
  3536. char *mapname,*str;
  3537. int flag,m;
  3538. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3539. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  3540. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3541. if( (m=map_mapname2mapid(mapname))<0 )
  3542. return 0;
  3543. map_foreachinarea(buildin_mapannounce_sub,
  3544. m,0,0,map[m].xs,map[m].ys,BL_PC, str,strlen(str)+1,flag&0x10);
  3545. return 0;
  3546. }
  3547. /*==========================================
  3548. * 天の声アナウンス(特定エリア)
  3549. *------------------------------------------
  3550. */
  3551. int buildin_areaannounce(struct script_state *st)
  3552. {
  3553. char *map,*str;
  3554. int flag,m;
  3555. int x0,y0,x1,y1;
  3556. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3557. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3558. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3559. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3560. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3561. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  3562. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3563. if( (m=map_mapname2mapid(map))<0 )
  3564. return 0;
  3565. map_foreachinarea(buildin_mapannounce_sub,
  3566. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10 );
  3567. return 0;
  3568. }
  3569. /*==========================================
  3570. * ユーザー数所得
  3571. *------------------------------------------
  3572. */
  3573. int buildin_getusers(struct script_state *st)
  3574. {
  3575. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3576. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  3577. int val=0;
  3578. switch(flag&0x07){
  3579. case 0: val=map[bl->m].users; break;
  3580. case 1: val=map_getusers(); break;
  3581. }
  3582. push_val(st->stack,C_INT,val);
  3583. return 0;
  3584. }
  3585. /*==========================================
  3586. * マップ指定ユーザー数所得
  3587. *------------------------------------------
  3588. */
  3589. int buildin_getmapusers(struct script_state *st)
  3590. {
  3591. char *str;
  3592. int m;
  3593. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3594. if( (m=map_mapname2mapid(str))< 0){
  3595. push_val(st->stack,C_INT,-1);
  3596. return 0;
  3597. }
  3598. push_val(st->stack,C_INT,map[m].users);
  3599. return 0;
  3600. }
  3601. /*==========================================
  3602. * エリア指定ユーザー数所得
  3603. *------------------------------------------
  3604. */
  3605. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  3606. {
  3607. int *users=va_arg(ap,int *);
  3608. (*users)++;
  3609. return 0;
  3610. }
  3611. int buildin_getareausers(struct script_state *st)
  3612. {
  3613. char *str;
  3614. int m,x0,y0,x1,y1,users=0;
  3615. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3616. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3617. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3618. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3619. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3620. if( (m=map_mapname2mapid(str))< 0){
  3621. push_val(st->stack,C_INT,-1);
  3622. return 0;
  3623. }
  3624. map_foreachinarea(buildin_getareausers_sub,
  3625. m,x0,y0,x1,y1,BL_PC,&users);
  3626. push_val(st->stack,C_INT,users);
  3627. return 0;
  3628. }
  3629. /*==========================================
  3630. * エリア指定ドロップアイテム数所得
  3631. *------------------------------------------
  3632. */
  3633. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  3634. {
  3635. int item=va_arg(ap,int);
  3636. int *amount=va_arg(ap,int *);
  3637. struct flooritem_data *drop=(struct flooritem_data *)bl;
  3638. if(drop->item_data.nameid==item)
  3639. (*amount)+=drop->item_data.amount;
  3640. return 0;
  3641. }
  3642. int buildin_getareadropitem(struct script_state *st)
  3643. {
  3644. char *str;
  3645. int m,x0,y0,x1,y1,item,amount=0;
  3646. struct script_data *data;
  3647. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3648. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3649. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3650. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3651. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3652. data=&(st->stack->stack_data[st->start+7]);
  3653. get_val(st,data);
  3654. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3655. const char *name=conv_str(st,data);
  3656. struct item_data *item_data = itemdb_searchname(name);
  3657. item=512;
  3658. if( item_data )
  3659. item=item_data->nameid;
  3660. }else
  3661. item=conv_num(st,data);
  3662. if( (m=map_mapname2mapid(str))< 0){
  3663. push_val(st->stack,C_INT,-1);
  3664. return 0;
  3665. }
  3666. map_foreachinarea(buildin_getareadropitem_sub,
  3667. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  3668. push_val(st->stack,C_INT,amount);
  3669. return 0;
  3670. }
  3671. /*==========================================
  3672. * NPCの有効化
  3673. *------------------------------------------
  3674. */
  3675. int buildin_enablenpc(struct script_state *st)
  3676. {
  3677. char *str;
  3678. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3679. npc_enable(str,1);
  3680. return 0;
  3681. }
  3682. /*==========================================
  3683. * NPCの無効化
  3684. *------------------------------------------
  3685. */
  3686. int buildin_disablenpc(struct script_state *st)
  3687. {
  3688. char *str;
  3689. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3690. npc_enable(str,0);
  3691. return 0;
  3692. }
  3693. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  3694. {
  3695. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  3696. struct chat_data *cd;
  3697. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  3698. return 0;
  3699. npc_enable(nd->name,1);
  3700. nd->arenaflag=1;
  3701. if(cd->users>=cd->trigger && cd->npc_event[0])
  3702. npc_timer_event(cd->npc_event);
  3703. return 0;
  3704. }
  3705. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  3706. {
  3707. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  3708. nd->arenaflag=0;
  3709. return 0;
  3710. }
  3711. /*==========================================
  3712. * 隠れているNPCの表示
  3713. *------------------------------------------
  3714. */
  3715. int buildin_hideoffnpc(struct script_state *st)
  3716. {
  3717. char *str;
  3718. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3719. npc_enable(str,2);
  3720. return 0;
  3721. }
  3722. /*==========================================
  3723. * NPCをハイディング
  3724. *------------------------------------------
  3725. */
  3726. int buildin_hideonnpc(struct script_state *st)
  3727. {
  3728. char *str;
  3729. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3730. npc_enable(str,4);
  3731. return 0;
  3732. }
  3733. /*==========================================
  3734. * 状態異常にかかる
  3735. *------------------------------------------
  3736. */
  3737. int buildin_sc_start(struct script_state *st)
  3738. {
  3739. struct block_list *bl;
  3740. int type,tick,val1;
  3741. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3742. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3743. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3744. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  3745. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  3746. else
  3747. bl = map_id2bl(st->rid);
  3748. if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
  3749. bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
  3750. skill_status_change_start(bl,type,val1,0,0,0,tick,0);
  3751. return 0;
  3752. }
  3753. /*==========================================
  3754. * 状態異常にかかる(確率指定)
  3755. *------------------------------------------
  3756. */
  3757. int buildin_sc_start2(struct script_state *st)
  3758. {
  3759. struct block_list *bl;
  3760. int type,tick,val1,per;
  3761. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3762. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3763. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3764. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3765. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  3766. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  3767. else
  3768. bl = map_id2bl(st->rid);
  3769. if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
  3770. bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
  3771. if(rand()%10000 < per)
  3772. skill_status_change_start(bl,type,val1,0,0,0,tick,0);
  3773. return 0;
  3774. }
  3775. /*==========================================
  3776. * 状態異常が直る
  3777. *------------------------------------------
  3778. */
  3779. int buildin_sc_end(struct script_state *st)
  3780. {
  3781. struct block_list *bl;
  3782. int type;
  3783. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3784. bl = map_id2bl(st->rid);
  3785. if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
  3786. bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
  3787. skill_status_change_end(bl,type,-1);
  3788. // if(battle_config.etc_log)
  3789. // printf("sc_end : %d %d\n",st->rid,type);
  3790. return 0;
  3791. }
  3792. /*==========================================
  3793. * 状態異常耐性を計算した確率を返す
  3794. *------------------------------------------
  3795. */
  3796. int buildin_getscrate(struct script_state *st)
  3797. {
  3798. struct block_list *bl;
  3799. int sc_def=100,sc_def_mdef2,sc_def_vit2,sc_def_int2,sc_def_luk2;
  3800. int type,rate,luk;
  3801. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3802. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3803. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  3804. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  3805. else
  3806. bl = map_id2bl(st->rid);
  3807. luk = battle_get_luk(bl);
  3808. sc_def_mdef2=100 - (3 + battle_get_mdef(bl) + luk/3);
  3809. sc_def_vit2=100 - (3 + battle_get_vit(bl) + luk/3);
  3810. sc_def_int2=100 - (3 + battle_get_int(bl) + luk/3);
  3811. sc_def_luk2=100 - (3 + luk);
  3812. if(type==SC_STONE || type==SC_FREEZE)
  3813. sc_def=sc_def_mdef2;
  3814. else if(type==SC_STAN || type==SC_POISON || type==SC_SILENCE)
  3815. sc_def=sc_def_vit2;
  3816. else if(type==SC_SLEEP || type==SC_CONFUSION || type==SC_BLIND)
  3817. sc_def=sc_def_int2;
  3818. else if(type==SC_CURSE)
  3819. sc_def=sc_def_luk2;
  3820. rate=rate*sc_def/100;
  3821. push_val(st->stack,C_INT,rate);
  3822. return 0;
  3823. }
  3824. /*==========================================
  3825. *
  3826. *------------------------------------------
  3827. */
  3828. int buildin_debugmes(struct script_state *st)
  3829. {
  3830. conv_str(st,& (st->stack->stack_data[st->start+2]));
  3831. printf("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  3832. return 0;
  3833. }
  3834. /*==========================================
  3835. *捕獲アイテム使用
  3836. *------------------------------------------
  3837. */
  3838. int buildin_catchpet(struct script_state *st)
  3839. {
  3840. int pet_id;
  3841. struct map_session_data *sd;
  3842. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  3843. sd=script_rid2sd(st);
  3844. pet_catch_process1(sd,pet_id);
  3845. return 0;
  3846. }
  3847. /*==========================================
  3848. *携帯卵孵化機使用
  3849. *------------------------------------------
  3850. */
  3851. int buildin_birthpet(struct script_state *st)
  3852. {
  3853. struct map_session_data *sd;
  3854. sd=script_rid2sd(st);
  3855. clif_sendegg(sd);
  3856. return 0;
  3857. }
  3858. /*==========================================
  3859. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  3860. *------------------------------------------
  3861. */
  3862. int buildin_resetlvl(struct script_state *st)
  3863. {
  3864. struct map_session_data *sd;
  3865. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3866. sd=script_rid2sd(st);
  3867. pc_resetlvl(sd,type);
  3868. return 0;
  3869. }
  3870. /*==========================================
  3871. * ステータスリセット
  3872. *------------------------------------------
  3873. */
  3874. int buildin_resetstatus(struct script_state *st)
  3875. {
  3876. struct map_session_data *sd;
  3877. sd=script_rid2sd(st);
  3878. pc_resetstate(sd);
  3879. return 0;
  3880. }
  3881. /*==========================================
  3882. * スキルリセット
  3883. *------------------------------------------
  3884. */
  3885. int buildin_resetskill(struct script_state *st)
  3886. {
  3887. struct map_session_data *sd;
  3888. sd=script_rid2sd(st);
  3889. pc_resetskill(sd);
  3890. return 0;
  3891. }
  3892. /*==========================================
  3893. *
  3894. *------------------------------------------
  3895. */
  3896. int buildin_changebase(struct script_state *st)
  3897. {
  3898. struct map_session_data *sd=NULL;
  3899. int vclass;
  3900. if( st->end>st->start+3 )
  3901. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  3902. else
  3903. sd=script_rid2sd(st);
  3904. if(sd == NULL)
  3905. return 0;
  3906. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3907. if(vclass == 22 && !battle_config.wedding_modifydisplay)
  3908. return 0;
  3909. // if(vclass==22) {
  3910. // pc_unequipitem(sd,sd->equip_index[9],0); // 装備外
  3911. // }
  3912. sd->view_class = vclass;
  3913. return 0;
  3914. }
  3915. /*==========================================
  3916. * 性別変換
  3917. *------------------------------------------
  3918. */
  3919. int buildin_changesex(struct script_state *st) {
  3920. struct map_session_data *sd = NULL;
  3921. sd = script_rid2sd(st);
  3922. if (sd->status.sex == 0) {
  3923. sd->status.sex = 1;
  3924. sd->sex = 1;
  3925. if (sd->status.class == 20 || sd->status.class == 4021)
  3926. sd->status.class -= 1;
  3927. } else if (sd->status.sex == 1) {
  3928. sd->status.sex = 0;
  3929. sd->sex = 0;
  3930. if(sd->status.class == 19 || sd->status.class == 4020)
  3931. sd->status.class += 1;
  3932. }
  3933. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  3934. chrif_save(sd);
  3935. return 0;
  3936. }
  3937. /*==========================================
  3938. * npcチャット作成
  3939. *------------------------------------------
  3940. */
  3941. int buildin_waitingroom(struct script_state *st)
  3942. {
  3943. char *name,*ev="";
  3944. int limit, trigger = 0,pub=1;
  3945. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3946. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  3947. if(limit==0)
  3948. pub=3;
  3949. if( (st->end > st->start+5) ){
  3950. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  3951. get_val(st,data);
  3952. if(data->type==C_INT){
  3953. // 新Athena仕様(旧Athena仕様と互換性あり)
  3954. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  3955. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3956. }else{
  3957. // eathena仕様
  3958. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3959. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  3960. }
  3961. }else{
  3962. // 旧Athena仕様
  3963. if( st->end > st->start+4 )
  3964. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  3965. }
  3966. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  3967. limit,pub,trigger,name,strlen(name)+1,ev);
  3968. return 0;
  3969. }
  3970. /*==========================================
  3971. * npcチャット削除
  3972. *------------------------------------------
  3973. */
  3974. int buildin_delwaitingroom(struct script_state *st)
  3975. {
  3976. struct npc_data *nd;
  3977. if( st->end > st->start+2 )
  3978. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3979. else
  3980. nd=(struct npc_data *)map_id2bl(st->oid);
  3981. chat_deletenpcchat(nd);
  3982. return 0;
  3983. }
  3984. /*==========================================
  3985. * npcチャット全員蹴り出す
  3986. *------------------------------------------
  3987. */
  3988. int buildin_waitingroomkickall(struct script_state *st)
  3989. {
  3990. struct npc_data *nd;
  3991. struct chat_data *cd;
  3992. if( st->end > st->start+2 )
  3993. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  3994. else
  3995. nd=(struct npc_data *)map_id2bl(st->oid);
  3996. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  3997. return 0;
  3998. chat_npckickall(cd);
  3999. return 0;
  4000. }
  4001. /*==========================================
  4002. * npcチャットイベント有効化
  4003. *------------------------------------------
  4004. */
  4005. int buildin_enablewaitingroomevent(struct script_state *st)
  4006. {
  4007. struct npc_data *nd;
  4008. struct chat_data *cd;
  4009. if( st->end > st->start+2 )
  4010. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  4011. else
  4012. nd=(struct npc_data *)map_id2bl(st->oid);
  4013. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  4014. return 0;
  4015. chat_enableevent(cd);
  4016. return 0;
  4017. }
  4018. /*==========================================
  4019. * npcチャットイベント無効化
  4020. *------------------------------------------
  4021. */
  4022. int buildin_disablewaitingroomevent(struct script_state *st)
  4023. {
  4024. struct npc_data *nd;
  4025. struct chat_data *cd;
  4026. if( st->end > st->start+2 )
  4027. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  4028. else
  4029. nd=(struct npc_data *)map_id2bl(st->oid);
  4030. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  4031. return 0;
  4032. chat_disableevent(cd);
  4033. return 0;
  4034. }
  4035. /*==========================================
  4036. * npcチャット状態所得
  4037. *------------------------------------------
  4038. */
  4039. int buildin_getwaitingroomstate(struct script_state *st)
  4040. {
  4041. struct npc_data *nd;
  4042. struct chat_data *cd;
  4043. int val=0,type;
  4044. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4045. if( st->end > st->start+3 )
  4046. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  4047. else
  4048. nd=(struct npc_data *)map_id2bl(st->oid);
  4049. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  4050. push_val(st->stack,C_INT,-1);
  4051. return 0;
  4052. }
  4053. switch(type){
  4054. case 0: val=cd->users; break;
  4055. case 1: val=cd->limit; break;
  4056. case 2: val=cd->trigger&0x7f; break;
  4057. case 3: val=((cd->trigger&0x80)>0); break;
  4058. case 32: val=(cd->users >= cd->limit); break;
  4059. case 33: val=(cd->users >= cd->trigger); break;
  4060. case 4:
  4061. push_str(st->stack,C_CONSTSTR,cd->title);
  4062. return 0;
  4063. case 5:
  4064. push_str(st->stack,C_CONSTSTR,cd->pass);
  4065. return 0;
  4066. case 16:
  4067. push_str(st->stack,C_CONSTSTR,cd->npc_event);
  4068. return 0;
  4069. }
  4070. push_val(st->stack,C_INT,val);
  4071. return 0;
  4072. }
  4073. /*==========================================
  4074. * チャットメンバー(規定人数)ワープ
  4075. *------------------------------------------
  4076. */
  4077. int buildin_warpwaitingpc(struct script_state *st)
  4078. {
  4079. int x,y,i,n;
  4080. char *str;
  4081. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  4082. struct chat_data *cd;
  4083. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  4084. return 0;
  4085. n=cd->trigger&0x7f;
  4086. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4087. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4088. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4089. if( st->end > st->start+5 )
  4090. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4091. for(i=0;i<n;i++){
  4092. struct map_session_data *sd=cd->usersd[0]; // リスト先頭のPCを次々に。
  4093. mapreg_setreg(add_str("$@warpwaitingpc")+(i<<24),sd->bl.id);
  4094. if(strcmp(str,"Random")==0)
  4095. pc_randomwarp(sd,3);
  4096. else if(strcmp(str,"SavePoint")==0){
  4097. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  4098. return 0;
  4099. pc_setpos(sd,sd->status.save_point.map,
  4100. sd->status.save_point.x,sd->status.save_point.y,3);
  4101. }else
  4102. pc_setpos(sd,str,x,y,0);
  4103. }
  4104. mapreg_setreg(add_str("$@warpwaitingpcnum"),n);
  4105. return 0;
  4106. }
  4107. /*==========================================
  4108. * RIDのアタッチ
  4109. *------------------------------------------
  4110. */
  4111. int buildin_attachrid(struct script_state *st)
  4112. {
  4113. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4114. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  4115. return 0;
  4116. }
  4117. /*==========================================
  4118. * RIDのデタッチ
  4119. *------------------------------------------
  4120. */
  4121. int buildin_detachrid(struct script_state *st)
  4122. {
  4123. st->rid=0;
  4124. return 0;
  4125. }
  4126. /*==========================================
  4127. * 存在チェック
  4128. *------------------------------------------
  4129. */
  4130. int buildin_isloggedin(struct script_state *st)
  4131. {
  4132. push_val(st->stack,C_INT, map_id2sd(
  4133. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  4134. return 0;
  4135. }
  4136. /*==========================================
  4137. *
  4138. *------------------------------------------
  4139. */
  4140. enum { MF_NOMEMO,MF_NOTELEPORT,MF_NOSAVE,MF_NOBRANCH,MF_NOPENALTY,MF_NOZENYPENALTY,MF_PVP,MF_PVP_NOPARTY,MF_PVP_NOGUILD,MF_GVG,MF_GVG_NOPARTY,MF_NOTRADE,MF_NOSKILL, MF_NOWARP,MF_NOPVP,MF_NOICEWALL,
  4141. MF_SNOW, MF_FOG, MF_SAKURA, MF_LEAVES, MF_RAIN, MF_INDOORS };
  4142. int buildin_setmapflagnosave(struct script_state *st)
  4143. {
  4144. int m,x,y;
  4145. char *str,*str2;
  4146. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4147. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4148. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4149. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4150. m = map_mapname2mapid(str);
  4151. if(m >= 0) {
  4152. map[m].flag.nosave=1;
  4153. memcpy(map[m].save.map,str2,16);
  4154. map[m].save.x=x;
  4155. map[m].save.y=y;
  4156. }
  4157. return 0;
  4158. }
  4159. int buildin_setmapflag(struct script_state *st)
  4160. {
  4161. int m,i;
  4162. char *str;
  4163. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4164. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4165. m = map_mapname2mapid(str);
  4166. if(m >= 0) {
  4167. switch(i) {
  4168. case MF_NOMEMO:
  4169. map[m].flag.nomemo=1;
  4170. break;
  4171. case MF_NOTELEPORT:
  4172. map[m].flag.noteleport=1;
  4173. break;
  4174. case MF_NOBRANCH:
  4175. map[m].flag.nobranch=1;
  4176. break;
  4177. case MF_NOPENALTY:
  4178. map[m].flag.nopenalty=1;
  4179. break;
  4180. case MF_PVP_NOPARTY:
  4181. map[m].flag.pvp_noparty=1;
  4182. break;
  4183. case MF_PVP_NOGUILD:
  4184. map[m].flag.pvp_noguild=1;
  4185. break;
  4186. case MF_GVG_NOPARTY:
  4187. map[m].flag.gvg_noparty=1;
  4188. break;
  4189. case MF_NOZENYPENALTY:
  4190. map[m].flag.nozenypenalty=1;
  4191. break;
  4192. case MF_NOTRADE:
  4193. map[m].flag.notrade=1;
  4194. break;
  4195. case MF_NOSKILL:
  4196. map[m].flag.noskill=1;
  4197. break;
  4198. case MF_NOWARP:
  4199. map[m].flag.nowarp=1;
  4200. break;
  4201. case MF_NOPVP:
  4202. map[m].flag.nopvp=1;
  4203. break;
  4204. case MF_NOICEWALL: // [Valaris]
  4205. map[m].flag.noicewall=1;
  4206. break;
  4207. case MF_SNOW: // [Valaris]
  4208. map[m].flag.snow=1;
  4209. break;
  4210. case MF_FOG: // [Valaris]
  4211. map[m].flag.fog=1;
  4212. break;
  4213. case MF_SAKURA: // [Valaris]
  4214. map[m].flag.sakura=1;
  4215. break;
  4216. case MF_LEAVES: // [Valaris]
  4217. map[m].flag.leaves=1;
  4218. break;
  4219. case MF_RAIN: // [Valaris]
  4220. map[m].flag.rain=1;
  4221. break;
  4222. case MF_INDOORS: // celest
  4223. map[m].flag.indoors=1;
  4224. break;
  4225. }
  4226. }
  4227. return 0;
  4228. }
  4229. int buildin_removemapflag(struct script_state *st)
  4230. {
  4231. int m,i;
  4232. char *str;
  4233. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4234. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4235. m = map_mapname2mapid(str);
  4236. if(m >= 0) {
  4237. switch(i) {
  4238. case MF_NOMEMO:
  4239. map[m].flag.nomemo=0;
  4240. break;
  4241. case MF_NOTELEPORT:
  4242. map[m].flag.noteleport=0;
  4243. break;
  4244. case MF_NOSAVE:
  4245. map[m].flag.nosave=0;
  4246. break;
  4247. case MF_NOBRANCH:
  4248. map[m].flag.nobranch=0;
  4249. break;
  4250. case MF_NOPENALTY:
  4251. map[m].flag.nopenalty=0;
  4252. break;
  4253. case MF_PVP_NOPARTY:
  4254. map[m].flag.pvp_noparty=0;
  4255. break;
  4256. case MF_PVP_NOGUILD:
  4257. map[m].flag.pvp_noguild=0;
  4258. break;
  4259. case MF_GVG_NOPARTY:
  4260. map[m].flag.gvg_noparty=0;
  4261. break;
  4262. case MF_NOZENYPENALTY:
  4263. map[m].flag.nozenypenalty=0;
  4264. break;
  4265. case MF_NOSKILL:
  4266. map[m].flag.noskill=0;
  4267. break;
  4268. case MF_NOWARP:
  4269. map[m].flag.nowarp=0;
  4270. break;
  4271. case MF_NOPVP:
  4272. map[m].flag.nopvp=0;
  4273. break;
  4274. case MF_NOICEWALL: // [Valaris]
  4275. map[m].flag.noicewall=0;
  4276. break;
  4277. case MF_SNOW: // [Valaris]
  4278. map[m].flag.snow=0;
  4279. break;
  4280. case MF_FOG: // [Valaris]
  4281. map[m].flag.fog=0;
  4282. break;
  4283. case MF_SAKURA: // [Valaris]
  4284. map[m].flag.sakura=0;
  4285. break;
  4286. case MF_LEAVES: // [Valaris]
  4287. map[m].flag.leaves=0;
  4288. break;
  4289. case MF_RAIN: // [Valaris]
  4290. map[m].flag.rain=0;
  4291. break;
  4292. case MF_INDOORS: // celest
  4293. map[m].flag.indoors=0;
  4294. break;
  4295. }
  4296. }
  4297. return 0;
  4298. }
  4299. int buildin_pvpon(struct script_state *st)
  4300. {
  4301. int m,i;
  4302. char *str;
  4303. struct map_session_data *pl_sd=NULL;
  4304. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4305. m = map_mapname2mapid(str);
  4306. if(m >= 0 && !map[m].flag.pvp && !map[m].flag.nopvp) {
  4307. map[m].flag.pvp = 1;
  4308. clif_send0199(m,1);
  4309. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  4310. return 0;
  4311. for(i=0;i<fd_max;i++){ //人数分ループ
  4312. if(session[i] && (pl_sd=session[i]->session_data) && pl_sd->state.auth){
  4313. if(m == pl_sd->bl.m && pl_sd->pvp_timer == -1) {
  4314. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  4315. pl_sd->pvp_rank=0;
  4316. pl_sd->pvp_lastusers=0;
  4317. pl_sd->pvp_point=5;
  4318. }
  4319. }
  4320. }
  4321. }
  4322. return 0;
  4323. }
  4324. int buildin_pvpoff(struct script_state *st)
  4325. {
  4326. int m,i;
  4327. char *str;
  4328. struct map_session_data *pl_sd=NULL;
  4329. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4330. m = map_mapname2mapid(str);
  4331. if(m >= 0 && map[m].flag.pvp && map[m].flag.nopvp) {
  4332. map[m].flag.pvp = 0;
  4333. clif_send0199(m,0);
  4334. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  4335. return 0;
  4336. for(i=0;i<fd_max;i++){ //人数分ループ
  4337. if(session[i] && (pl_sd=session[i]->session_data) && pl_sd->state.auth){
  4338. if(m == pl_sd->bl.m) {
  4339. clif_pvpset(pl_sd,0,0,2);
  4340. if(pl_sd->pvp_timer != -1) {
  4341. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  4342. pl_sd->pvp_timer = -1;
  4343. }
  4344. }
  4345. }
  4346. }
  4347. }
  4348. return 0;
  4349. }
  4350. int buildin_gvgon(struct script_state *st)
  4351. {
  4352. int m;
  4353. char *str;
  4354. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4355. m = map_mapname2mapid(str);
  4356. if(m >= 0 && !map[m].flag.gvg) {
  4357. map[m].flag.gvg = 1;
  4358. clif_send0199(m,3);
  4359. }
  4360. return 0;
  4361. }
  4362. int buildin_gvgoff(struct script_state *st)
  4363. {
  4364. int m;
  4365. char *str;
  4366. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4367. m = map_mapname2mapid(str);
  4368. if(m >= 0 && map[m].flag.gvg) {
  4369. map[m].flag.gvg = 0;
  4370. clif_send0199(m,0);
  4371. }
  4372. return 0;
  4373. }
  4374. /*==========================================
  4375. * NPCエモーション
  4376. *------------------------------------------
  4377. */
  4378. int buildin_emotion(struct script_state *st)
  4379. {
  4380. int type;
  4381. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4382. if(type < 0 || type > 100)
  4383. return 0;
  4384. clif_emotion(map_id2bl(st->oid),type);
  4385. return 0;
  4386. }
  4387. int buildin_maprespawnguildid_sub(struct block_list *bl,va_list ap)
  4388. {
  4389. int g_id=va_arg(ap,int);
  4390. int flag=va_arg(ap,int);
  4391. struct map_session_data *sd=NULL;
  4392. struct mob_data *md=NULL;
  4393. if(bl->type == BL_PC)
  4394. sd=(struct map_session_data*)bl;
  4395. if(bl->type == BL_MOB)
  4396. md=(struct mob_data *)bl;
  4397. if(sd){
  4398. if((sd->status.guild_id == g_id) && (flag&1))
  4399. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  4400. else if((sd->status.guild_id != g_id) && (flag&2))
  4401. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  4402. else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  4403. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3); // end addition [Valaris]
  4404. }
  4405. if(md && flag&4){
  4406. if(md->class < 1285 || md->class > 1288)
  4407. mob_delete(md);
  4408. }
  4409. return 0;
  4410. }
  4411. int buildin_maprespawnguildid(struct script_state *st)
  4412. {
  4413. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4414. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4415. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4416. int m=map_mapname2mapid(mapname);
  4417. if(m) map_foreachinarea(buildin_maprespawnguildid_sub,m,0,0,map[m].xs-1,map[m].ys-1,BL_NUL,g_id,flag);
  4418. return 0;
  4419. }
  4420. int buildin_agitstart(struct script_state *st)
  4421. {
  4422. if(agit_flag==1) return 1; // Agit already Start.
  4423. agit_flag=1;
  4424. guild_agit_start();
  4425. return 0;
  4426. }
  4427. int buildin_agitend(struct script_state *st)
  4428. {
  4429. if(agit_flag==0) return 1; // Agit already End.
  4430. agit_flag=0;
  4431. guild_agit_end();
  4432. return 0;
  4433. }
  4434. /*==========================================
  4435. * agitcheck 1; // choice script
  4436. * if(@agit_flag == 1) goto agit;
  4437. * if(agitcheck(0) == 1) goto agit;
  4438. *------------------------------------------
  4439. */
  4440. int buildin_agitcheck(struct script_state *st)
  4441. {
  4442. struct map_session_data *sd;
  4443. int cond;
  4444. sd=script_rid2sd(st);
  4445. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4446. if(cond == 0) {
  4447. if (agit_flag==1) push_val(st->stack,C_INT,1);
  4448. if (agit_flag==0) push_val(st->stack,C_INT,0);
  4449. } else {
  4450. if (agit_flag==1) pc_setreg(sd,add_str("@agit_flag"),1);
  4451. if (agit_flag==0) pc_setreg(sd,add_str("@agit_flag"),0);
  4452. }
  4453. return 0;
  4454. }
  4455. int buildin_flagemblem(struct script_state *st)
  4456. {
  4457. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4458. if(g_id < 0) return 0;
  4459. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  4460. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  4461. return 1;
  4462. }
  4463. int buildin_getcastlename(struct script_state *st)
  4464. {
  4465. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4466. struct guild_castle *gc;
  4467. int i;
  4468. char *buf=NULL;
  4469. for(i=0;i<MAX_GUILDCASTLE;i++){
  4470. if( (gc=guild_castle_search(i)) != NULL ){
  4471. if(strcmp(mapname,gc->map_name)==0){
  4472. buf=(char *)aCalloc(24,sizeof(char));
  4473. strncpy(buf,gc->castle_name,24);
  4474. break;
  4475. }
  4476. }
  4477. }
  4478. if(buf)
  4479. push_str(st->stack,C_STR,buf);
  4480. else
  4481. push_str(st->stack,C_CONSTSTR,"");
  4482. return 0;
  4483. }
  4484. int buildin_getcastledata(struct script_state *st)
  4485. {
  4486. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4487. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4488. char *event=NULL;
  4489. struct guild_castle *gc;
  4490. int i,j;
  4491. if( st->end>st->start+4 && index==0){
  4492. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  4493. if( (gc=guild_castle_search(i)) != NULL &&
  4494. strcmp(mapname,gc->map_name)==0 )
  4495. j=i;
  4496. if(j>=0){
  4497. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  4498. guild_addcastleinfoevent(j,17,event);
  4499. }
  4500. }
  4501. for(i=0;i<MAX_GUILDCASTLE;i++){
  4502. if( (gc=guild_castle_search(i)) != NULL ){
  4503. if(strcmp(mapname,gc->map_name)==0){
  4504. switch(index){
  4505. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  4506. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  4507. case 2: push_val(st->stack,C_INT,gc->economy); break;
  4508. case 3: push_val(st->stack,C_INT,gc->defense); break;
  4509. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  4510. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  4511. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  4512. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  4513. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  4514. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  4515. case 10: push_val(st->stack,C_INT,gc->visibleG0); break;
  4516. case 11: push_val(st->stack,C_INT,gc->visibleG1); break;
  4517. case 12: push_val(st->stack,C_INT,gc->visibleG2); break;
  4518. case 13: push_val(st->stack,C_INT,gc->visibleG3); break;
  4519. case 14: push_val(st->stack,C_INT,gc->visibleG4); break;
  4520. case 15: push_val(st->stack,C_INT,gc->visibleG5); break;
  4521. case 16: push_val(st->stack,C_INT,gc->visibleG6); break;
  4522. case 17: push_val(st->stack,C_INT,gc->visibleG7); break;
  4523. case 18: push_val(st->stack,C_INT,gc->Ghp0); break;
  4524. case 19: push_val(st->stack,C_INT,gc->Ghp1); break;
  4525. case 20: push_val(st->stack,C_INT,gc->Ghp2); break;
  4526. case 21: push_val(st->stack,C_INT,gc->Ghp3); break;
  4527. case 22: push_val(st->stack,C_INT,gc->Ghp4); break;
  4528. case 23: push_val(st->stack,C_INT,gc->Ghp5); break;
  4529. case 24: push_val(st->stack,C_INT,gc->Ghp6); break;
  4530. case 25: push_val(st->stack,C_INT,gc->Ghp7); break;
  4531. default:
  4532. push_val(st->stack,C_INT,0); break;
  4533. }
  4534. return 0;
  4535. }
  4536. }
  4537. }
  4538. push_val(st->stack,C_INT,0);
  4539. return 0;
  4540. }
  4541. int buildin_setcastledata(struct script_state *st)
  4542. {
  4543. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4544. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4545. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4546. struct guild_castle *gc;
  4547. int i;
  4548. for(i=0;i<MAX_GUILDCASTLE;i++){
  4549. if( (gc=guild_castle_search(i)) != NULL ){
  4550. if(strcmp(mapname,gc->map_name)==0){
  4551. // Save Data byself First
  4552. switch(index){
  4553. case 1: gc->guild_id = value; break;
  4554. case 2: gc->economy = value; break;
  4555. case 3: gc->defense = value; break;
  4556. case 4: gc->triggerE = value; break;
  4557. case 5: gc->triggerD = value; break;
  4558. case 6: gc->nextTime = value; break;
  4559. case 7: gc->payTime = value; break;
  4560. case 8: gc->createTime = value; break;
  4561. case 9: gc->visibleC = value; break;
  4562. case 10: gc->visibleG0 = value; break;
  4563. case 11: gc->visibleG1 = value; break;
  4564. case 12: gc->visibleG2 = value; break;
  4565. case 13: gc->visibleG3 = value; break;
  4566. case 14: gc->visibleG4 = value; break;
  4567. case 15: gc->visibleG5 = value; break;
  4568. case 16: gc->visibleG6 = value; break;
  4569. case 17: gc->visibleG7 = value; break;
  4570. case 18: gc->Ghp0 = value; break;
  4571. case 19: gc->Ghp1 = value; break;
  4572. case 20: gc->Ghp2 = value; break;
  4573. case 21: gc->Ghp3 = value; break;
  4574. case 22: gc->Ghp4 = value; break;
  4575. case 23: gc->Ghp5 = value; break;
  4576. case 24: gc->Ghp6 = value; break;
  4577. case 25: gc->Ghp7 = value; break;
  4578. default: return 0;
  4579. }
  4580. guild_castledatasave(gc->castle_id,index,value);
  4581. return 0;
  4582. }
  4583. }
  4584. }
  4585. return 0;
  4586. }
  4587. /* =====================================================================
  4588. * ギルド情報を要求する
  4589. * ---------------------------------------------------------------------
  4590. */
  4591. int buildin_requestguildinfo(struct script_state *st)
  4592. {
  4593. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4594. char *event=NULL;
  4595. if( st->end>st->start+3 )
  4596. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4597. if(guild_id>0)
  4598. guild_npc_request_info(guild_id,event);
  4599. return 0;
  4600. }
  4601. /* =====================================================================
  4602. * カードの数を得る
  4603. * ---------------------------------------------------------------------
  4604. */
  4605. int buildin_getequipcardcnt(struct script_state *st)
  4606. {
  4607. int i,num;
  4608. struct map_session_data *sd;
  4609. int c=4;
  4610. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4611. sd=script_rid2sd(st);
  4612. i=pc_checkequip(sd,equip[num-1]);
  4613. if(sd->status.inventory[i].card[0] == 0x00ff){ // 製造武器はカードなし
  4614. push_val(st->stack,C_INT,0);
  4615. return 0;
  4616. }
  4617. do{
  4618. if( (sd->status.inventory[i].card[c-1] > 4000) &&
  4619. (sd->status.inventory[i].card[c-1] < 5000)){
  4620. push_val(st->stack,C_INT,(c));
  4621. return 0;
  4622. }
  4623. }while(c--);
  4624. push_val(st->stack,C_INT,0);
  4625. return 0;
  4626. }
  4627. /* ================================================================
  4628. * カード取り外し成功
  4629. * ----------------------------------------------------------------
  4630. */
  4631. int buildin_successremovecards(struct script_state *st)
  4632. {
  4633. int i,num,cardflag=0,flag;
  4634. struct map_session_data *sd;
  4635. struct item item_tmp;
  4636. int c=4;
  4637. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4638. sd=script_rid2sd(st);
  4639. i=pc_checkequip(sd,equip[num-1]);
  4640. if(sd->status.inventory[i].card[0]==0x00ff){ // 製造武器は処理しない
  4641. return 0;
  4642. }
  4643. do{
  4644. if( (sd->status.inventory[i].card[c-1] > 4000) &&
  4645. (sd->status.inventory[i].card[c-1] < 5000)){
  4646. cardflag = 1;
  4647. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  4648. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  4649. item_tmp.attribute=0;
  4650. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4651. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  4652. clif_additem(sd,0,0,flag);
  4653. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4654. }
  4655. }
  4656. }while(c--);
  4657. if(cardflag == 1){ // カードを取り除いたアイテム所得
  4658. flag=0;
  4659. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  4660. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  4661. item_tmp.attribute=sd->status.inventory[i].attribute;
  4662. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4663. pc_delitem(sd,i,1,0);
  4664. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  4665. clif_additem(sd,0,0,flag);
  4666. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4667. }
  4668. clif_misceffect(&sd->bl,3);
  4669. return 0;
  4670. }
  4671. return 0;
  4672. }
  4673. /* ================================================================
  4674. * カード取り外し失敗 slot,type
  4675. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  4676. * ----------------------------------------------------------------
  4677. */
  4678. int buildin_failedremovecards(struct script_state *st)
  4679. {
  4680. int i,num,cardflag=0,flag,typefail;
  4681. struct map_session_data *sd;
  4682. struct item item_tmp;
  4683. int c=4;
  4684. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4685. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4686. sd=script_rid2sd(st);
  4687. i=pc_checkequip(sd,equip[num-1]);
  4688. if(sd->status.inventory[i].card[0]==0x00ff){ // 製造武器は処理しない
  4689. return 0;
  4690. }
  4691. do{
  4692. if(( sd->status.inventory[i].card[c-1] > 4000) &&
  4693. (sd->status.inventory[i].card[c-1] < 5000)){
  4694. cardflag = 1;
  4695. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  4696. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  4697. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  4698. item_tmp.attribute=0;
  4699. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4700. if((flag=pc_additem(sd,&item_tmp,1))){
  4701. clif_additem(sd,0,0,flag);
  4702. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4703. }
  4704. }
  4705. }
  4706. }while(c--);
  4707. if(cardflag == 1){
  4708. if(typefail == 0 || typefail == 2){ // 武具損失
  4709. pc_delitem(sd,i,1,0);
  4710. clif_misceffect(&sd->bl,2);
  4711. return 0;
  4712. }
  4713. if(typefail == 1){ // カードのみ損失(武具を返す)
  4714. flag=0;
  4715. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  4716. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  4717. item_tmp.attribute=sd->status.inventory[i].attribute;
  4718. item_tmp.card[0]=0,item_tmp.card[1]=0,item_tmp.card[2]=0,item_tmp.card[3]=0;
  4719. pc_delitem(sd,i,1,0);
  4720. if((flag=pc_additem(sd,&item_tmp,1))){
  4721. clif_additem(sd,0,0,flag);
  4722. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4723. }
  4724. }
  4725. clif_misceffect(&sd->bl,2);
  4726. return 0;
  4727. }
  4728. return 0;
  4729. }
  4730. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  4731. {
  4732. int x,y,m;
  4733. char *str;
  4734. char *mapname;
  4735. int x0,y0,x1,y1;
  4736. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4737. x0=0;
  4738. y0=0;
  4739. x1=map[map_mapname2mapid(mapname)].xs;
  4740. y1=map[map_mapname2mapid(mapname)].ys;
  4741. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4742. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4743. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4744. if( (m=map_mapname2mapid(mapname))< 0)
  4745. return 0;
  4746. map_foreachinarea(buildin_areawarp_sub,
  4747. m,x0,y0,x1,y1,BL_PC, str,x,y );
  4748. return 0;
  4749. }
  4750. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  4751. {
  4752. char *npc,*command;
  4753. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4754. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4755. npc_command(map_id2sd(st->rid),npc,command);
  4756. return 0;
  4757. }
  4758. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  4759. {
  4760. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  4761. // nd->lastaction=nd->timer=gettick();
  4762. npc_do_ontimer(st->oid, map_id2sd(st->rid), 1);
  4763. return 0;
  4764. }
  4765. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  4766. {
  4767. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  4768. // nd->lastaction=nd->timer=-1;
  4769. npc_do_ontimer(st->oid, map_id2sd(st->rid), 0);
  4770. return 0;
  4771. }
  4772. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  4773. {
  4774. char *event=va_arg(ap,char *);
  4775. int *c=va_arg(ap,int *);
  4776. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  4777. (*c)++;
  4778. return 0;
  4779. }
  4780. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  4781. {
  4782. char *mapname,*event;
  4783. int m,c=0;
  4784. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4785. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  4786. if( (m=map_mapname2mapid(mapname))<0 ) {
  4787. push_val(st->stack,C_INT,-1);
  4788. return 0;
  4789. }
  4790. map_foreachinarea(buildin_mobcount_sub,
  4791. m,0,0,map[m].xs,map[m].ys,BL_MOB, event,&c );
  4792. push_val(st->stack,C_INT, (c - 1));
  4793. return 0;
  4794. }
  4795. int buildin_marriage(struct script_state *st)
  4796. {
  4797. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4798. struct map_session_data *sd=script_rid2sd(st);
  4799. struct map_session_data *p_sd=map_nick2sd(partner);
  4800. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  4801. push_val(st->stack,C_INT,0);
  4802. return 0;
  4803. }
  4804. push_val(st->stack,C_INT,1);
  4805. return 0;
  4806. }
  4807. int buildin_wedding_effect(struct script_state *st)
  4808. {
  4809. struct map_session_data *sd=script_rid2sd(st);
  4810. if(sd==NULL)
  4811. return 0;
  4812. clif_wedding_effect(&sd->bl);
  4813. return 0;
  4814. }
  4815. int buildin_divorce(struct script_state *st)
  4816. {
  4817. struct map_session_data *sd=script_rid2sd(st);
  4818. if(sd==NULL || pc_divorce(sd) < 0){
  4819. push_val(st->stack,C_INT,0);
  4820. return 0;
  4821. }
  4822. push_val(st->stack,C_INT,1);
  4823. return 0;
  4824. }
  4825. /*================================================
  4826. * Script for Displaying MOB Information [Valaris]
  4827. *------------------------------------------------
  4828. */
  4829. int buildin_strmobinfo(struct script_state *st)
  4830. {
  4831. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4832. int class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4833. if(num<=0 || num>=8 || (class>=0 && class<=1000) || class >2000)
  4834. return 0;
  4835. if(num==1) {
  4836. char *buf;
  4837. buf=calloc(24, 1);
  4838. buf=mob_db[class].name;
  4839. push_str(st->stack,C_STR,buf);
  4840. return 0;
  4841. }
  4842. else if(num==2) {
  4843. char *buf;
  4844. buf=calloc(24, 1);
  4845. buf=mob_db[class].jname;
  4846. push_str(st->stack,C_STR,buf);
  4847. return 0;
  4848. }
  4849. else if(num==3)
  4850. push_val(st->stack,C_INT,mob_db[class].lv);
  4851. else if(num==4)
  4852. push_val(st->stack,C_INT,mob_db[class].max_hp);
  4853. else if(num==5)
  4854. push_val(st->stack,C_INT,mob_db[class].max_sp);
  4855. else if(num==6)
  4856. push_val(st->stack,C_INT,mob_db[class].base_exp);
  4857. else if(num==7)
  4858. push_val(st->stack,C_INT,mob_db[class].job_exp);
  4859. return 0;
  4860. }
  4861. /*==========================================
  4862. * Summon guardians [Valaris]
  4863. *------------------------------------------
  4864. */
  4865. int buildin_guardian(struct script_state *st)
  4866. {
  4867. int class=0,amount=1,x=0,y=0,guardian=0;
  4868. char *str,*map,*event="";
  4869. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  4870. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  4871. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  4872. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  4873. class=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4874. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4875. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  4876. if( st->end>st->start+9 )
  4877. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4878. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class,amount,event,guardian);
  4879. return 0;
  4880. }
  4881. /*================================================
  4882. * Script for Displaying Guardian Info [Valaris]
  4883. *------------------------------------------------
  4884. */
  4885. int buildin_guardianinfo(struct script_state *st)
  4886. {
  4887. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4888. struct map_session_data *sd=script_rid2sd(st);
  4889. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  4890. if(guardian==0 && gc->visibleG0 == 1) push_val(st->stack,C_INT,gc->Ghp0);
  4891. if(guardian==1 && gc->visibleG1 == 1) push_val(st->stack,C_INT,gc->Ghp1);
  4892. if(guardian==2 && gc->visibleG2 == 1) push_val(st->stack,C_INT,gc->Ghp2);
  4893. if(guardian==3 && gc->visibleG3 == 1) push_val(st->stack,C_INT,gc->Ghp3);
  4894. if(guardian==4 && gc->visibleG4 == 1) push_val(st->stack,C_INT,gc->Ghp4);
  4895. if(guardian==5 && gc->visibleG5 == 1) push_val(st->stack,C_INT,gc->Ghp5);
  4896. if(guardian==6 && gc->visibleG6 == 1) push_val(st->stack,C_INT,gc->Ghp6);
  4897. if(guardian==7 && gc->visibleG7 == 1) push_val(st->stack,C_INT,gc->Ghp7);
  4898. else push_val(st->stack,C_INT,-1);
  4899. return 0;
  4900. }
  4901. /*==========================================
  4902. * IDからItem名
  4903. *------------------------------------------
  4904. */
  4905. int buildin_getitemname(struct script_state *st)
  4906. {
  4907. int item_id;
  4908. struct item_data *i_data;
  4909. char *item_name;
  4910. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4911. i_data = NULL;
  4912. i_data = itemdb_search(item_id);
  4913. item_name=(char *)aCalloc(24,sizeof(char));
  4914. strncpy(item_name,i_data->jname,23);
  4915. push_str(st->stack,C_STR,item_name);
  4916. return 0;
  4917. }
  4918. /*==========================================
  4919. * petskillbonus [Valaris]
  4920. *------------------------------------------
  4921. */
  4922. int buildin_petskillbonus(struct script_state *st)
  4923. {
  4924. int type,val,duration,timer;
  4925. struct pet_data *pd;
  4926. struct map_session_data *sd=script_rid2sd(st);
  4927. if(sd==NULL || sd->pd==NULL)
  4928. return 0;
  4929. pd=sd->pd;
  4930. if(pd==NULL)
  4931. return 0;
  4932. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4933. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4934. duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4935. timer=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4936. pd->skillbonusduration=-1;
  4937. pd->skillbonustimer=-1;
  4938. pet_skill_bonus(sd,pd,type,val,duration,timer,0);
  4939. return 0;
  4940. }
  4941. /*==========================================
  4942. * pet looting [Valaris]
  4943. *------------------------------------------
  4944. */
  4945. int buildin_petloot(struct script_state *st)
  4946. {
  4947. int max;
  4948. struct pet_data *pd;
  4949. struct map_session_data *sd=script_rid2sd(st);
  4950. if(sd==NULL || sd->pd==NULL)
  4951. return 0;
  4952. pd=sd->pd;
  4953. if(pd==NULL)
  4954. return 0;
  4955. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4956. if(!max)
  4957. return 0;
  4958. pd->loot=1;
  4959. pd->lootmax=max;
  4960. return 0;
  4961. }
  4962. /*==========================================
  4963. * PCの所持品情報読み取り
  4964. *------------------------------------------
  4965. */
  4966. int buildin_getinventorylist(struct script_state *st)
  4967. {
  4968. struct map_session_data *sd=script_rid2sd(st);
  4969. int i,j=0;
  4970. if(!sd) return 0;
  4971. for(i=0;i<MAX_INVENTORY;i++){
  4972. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  4973. pc_setreg(sd,add_str("@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  4974. pc_setreg(sd,add_str("@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  4975. pc_setreg(sd,add_str("@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  4976. pc_setreg(sd,add_str("@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  4977. pc_setreg(sd,add_str("@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  4978. pc_setreg(sd,add_str("@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  4979. pc_setreg(sd,add_str("@inventorylist_card1")+(j<<24),sd->status.inventory[i].card[0]);
  4980. pc_setreg(sd,add_str("@inventorylist_card2")+(j<<24),sd->status.inventory[i].card[1]);
  4981. pc_setreg(sd,add_str("@inventorylist_card3")+(j<<24),sd->status.inventory[i].card[2]);
  4982. pc_setreg(sd,add_str("@inventorylist_card4")+(j<<24),sd->status.inventory[i].card[3]);
  4983. j++;
  4984. }
  4985. }
  4986. pc_setreg(sd,add_str("@inventorylist_count"),j);
  4987. return 0;
  4988. }
  4989. int buildin_getskilllist(struct script_state *st)
  4990. {
  4991. struct map_session_data *sd=script_rid2sd(st);
  4992. int i,j=0;
  4993. if(!sd) return 0;
  4994. for(i=0;i<MAX_SKILL;i++){
  4995. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  4996. pc_setreg(sd,add_str("@skilllist_id")+(j<<24),sd->status.skill[i].id);
  4997. pc_setreg(sd,add_str("@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  4998. pc_setreg(sd,add_str("@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  4999. j++;
  5000. }
  5001. }
  5002. pc_setreg(sd,add_str("@skilllist_count"),j);
  5003. return 0;
  5004. }
  5005. int buildin_clearitem(struct script_state *st)
  5006. {
  5007. struct map_session_data *sd=script_rid2sd(st);
  5008. int i;
  5009. if(sd==NULL) return 0;
  5010. for (i=0; i<MAX_INVENTORY; i++) {
  5011. if (sd->status.inventory[i].amount)
  5012. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  5013. }
  5014. return 0;
  5015. }
  5016. /*==========================================
  5017. * NPCクラスチェンジ
  5018. * classは変わりたいclass
  5019. * typeは通常0なのかな?
  5020. *------------------------------------------
  5021. */
  5022. int buildin_classchange(struct script_state *st)
  5023. {
  5024. int class,type;
  5025. struct block_list *bl=map_id2bl(st->oid);
  5026. if(bl==NULL) return 0;
  5027. class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5028. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5029. clif_class_change(bl,class,type);
  5030. return 0;
  5031. }
  5032. /*==========================================
  5033. * NPCから発生するエフェクト
  5034. *------------------------------------------
  5035. */
  5036. int buildin_misceffect(struct script_state *st)
  5037. {
  5038. int type;
  5039. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5040. if(st->oid)
  5041. clif_misceffect2(map_id2bl(st->oid),type);
  5042. else{
  5043. struct map_session_data *sd=script_rid2sd(st);
  5044. if(sd)
  5045. clif_misceffect2(&sd->bl,type);
  5046. }
  5047. return 0;
  5048. }
  5049. /*==========================================
  5050. * サウンドエフェクト
  5051. *------------------------------------------
  5052. */
  5053. int buildin_soundeffect(struct script_state *st)
  5054. {
  5055. struct map_session_data *sd=script_rid2sd(st);
  5056. char *name;
  5057. int type=0;
  5058. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5059. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5060. if(sd){
  5061. if(st->oid)
  5062. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  5063. else{
  5064. clif_soundeffect(sd,&sd->bl,name,type);
  5065. }
  5066. }
  5067. return 0;
  5068. }
  5069. /*==========================================
  5070. * pet status recovery [Valaris]
  5071. *------------------------------------------
  5072. */
  5073. int buildin_petrecovery(struct script_state *st)
  5074. {
  5075. struct pet_data *pd;
  5076. struct map_session_data *sd=script_rid2sd(st);
  5077. if(sd==NULL || sd->pd==NULL)
  5078. return 0;
  5079. pd=sd->pd;
  5080. if(pd==NULL)
  5081. return 0;
  5082. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5083. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5084. pd->skillbonustimer=add_timer(gettick()+pd->skilltimer*1000,pet_recovery_timer,sd->bl.id,0);
  5085. return 0;
  5086. }
  5087. /*==========================================
  5088. * pet healing [Valaris]
  5089. *------------------------------------------
  5090. */
  5091. int buildin_petheal(struct script_state *st)
  5092. {
  5093. struct pet_data *pd;
  5094. struct map_session_data *sd=script_rid2sd(st);
  5095. if(sd==NULL || sd->pd==NULL)
  5096. return 0;
  5097. pd=sd->pd;
  5098. if(pd==NULL)
  5099. return 0;
  5100. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5101. pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5102. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5103. pd->skillbonustimer=add_timer(gettick()+pd->skilltimer*1000,pet_heal_timer,sd->bl.id,0);
  5104. return 0;
  5105. }
  5106. /*==========================================
  5107. * pet magnificat [Valaris]
  5108. *------------------------------------------
  5109. */
  5110. int buildin_petmag(struct script_state *st)
  5111. {
  5112. struct pet_data *pd;
  5113. struct map_session_data *sd=script_rid2sd(st);
  5114. if(sd==NULL || sd->pd==NULL)
  5115. return 0;
  5116. pd=sd->pd;
  5117. if(pd==NULL)
  5118. return 0;
  5119. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5120. pd->skillduration=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5121. pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5122. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5123. pd->skillbonustimer=add_timer(gettick()+pd->skilltimer*1000,pet_mag_timer,sd->bl.id,0);
  5124. return 0;
  5125. }
  5126. /*==========================================
  5127. * pet attack skills [Valaris]
  5128. *------------------------------------------
  5129. */
  5130. int buildin_petskillattack(struct script_state *st)
  5131. {
  5132. struct pet_data *pd;
  5133. struct map_session_data *sd=script_rid2sd(st);
  5134. if(sd==NULL || sd->pd==NULL)
  5135. return 0;
  5136. pd=sd->pd;
  5137. if(pd==NULL)
  5138. return 0;
  5139. pd->skilltype=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5140. pd->skillval=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5141. pd->skillduration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5142. pd->skilltimer=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5143. pd->skillbonustimer=add_timer(gettick()+100,pet_skillattack_timer,sd->bl.id,0);
  5144. return 0;
  5145. }
  5146. /*==========================================
  5147. * NPC skill effects [Valaris]
  5148. *------------------------------------------
  5149. */
  5150. int buildin_npcskilleffect(struct script_state *st)
  5151. {
  5152. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5153. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5154. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5155. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5156. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5157. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  5158. return 0;
  5159. }
  5160. /*==========================================
  5161. * Special effects [Valaris]
  5162. *------------------------------------------
  5163. */
  5164. int buildin_specialeffect(struct script_state *st)
  5165. {
  5166. struct block_list *bl=map_id2bl(st->oid);
  5167. if(bl==NULL)
  5168. return 0;
  5169. clif_specialeffect(bl,conv_num(st,& (st->stack->stack_data[st->start+2])), 0);
  5170. return 0;
  5171. }
  5172. int buildin_specialeffect2(struct script_state *st)
  5173. {
  5174. struct map_session_data *sd=script_rid2sd(st);
  5175. if(sd==NULL)
  5176. return 0;
  5177. clif_specialeffect(&sd->bl,conv_num(st,& (st->stack->stack_data[st->start+2])), 0);
  5178. return 0;
  5179. }
  5180. /*==========================================
  5181. * Nude [Valaris]
  5182. *------------------------------------------
  5183. */
  5184. int buildin_nude(struct script_state *st)
  5185. {
  5186. struct map_session_data *sd=script_rid2sd(st);
  5187. int i;
  5188. if(sd==NULL)
  5189. return 0;
  5190. for(i=0;i<11;i++)
  5191. if(sd->equip_index[i] >= 0)
  5192. pc_unequipitem(sd,sd->equip_index[i],1);
  5193. return 0;
  5194. }
  5195. /*==========================================
  5196. * gmcommand [MouseJstr]
  5197. *
  5198. * suggested on the forums...
  5199. *------------------------------------------
  5200. */
  5201. int buildin_gmcommand(struct script_state *st)
  5202. {
  5203. struct map_session_data *sd;
  5204. char *cmd;
  5205. sd = script_rid2sd(st);
  5206. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5207. is_atcommand(sd->fd, sd, cmd, 99);
  5208. return 0;
  5209. }
  5210. /*==========================================
  5211. * movenpc [MouseJstr]
  5212. *------------------------------------------
  5213. */
  5214. int buildin_movenpc(struct script_state *st)
  5215. {
  5216. struct map_session_data *sd;
  5217. char *map,*npc;
  5218. int x,y;
  5219. sd = script_rid2sd(st);
  5220. map = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5221. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  5222. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  5223. npc = conv_str(st,& (st->stack->stack_data[st->start+5]));
  5224. return 0;
  5225. }
  5226. /*==========================================
  5227. * message [MouseJstr]
  5228. *------------------------------------------
  5229. */
  5230. int buildin_message(struct script_state *st)
  5231. {
  5232. struct map_session_data *sd;
  5233. char *msg,*player;
  5234. struct map_session_data *pl_sd = NULL;
  5235. sd = script_rid2sd(st);
  5236. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5237. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  5238. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  5239. return 1;
  5240. clif_displaymessage(pl_sd->fd, msg);
  5241. return 0;
  5242. }
  5243. /*==========================================
  5244. * npctalk (sends message to surrounding
  5245. * area) [Valaris]
  5246. *------------------------------------------
  5247. */
  5248. int buildin_npctalk(struct script_state *st)
  5249. {
  5250. char *str;
  5251. char message[255];
  5252. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5253. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5254. if(nd) {
  5255. memcpy(message,nd->name,24);
  5256. strcat(message," : ");
  5257. strcat(message,str);
  5258. clif_message(&(nd->bl), message);
  5259. }
  5260. return 0;
  5261. }
  5262. /*==========================================
  5263. * hasitems (checks to see if player has any
  5264. * items on them, if so will return a 1)
  5265. * [Valaris]
  5266. *------------------------------------------
  5267. */
  5268. int buildin_hasitems(struct script_state *st)
  5269. {
  5270. int i;
  5271. struct map_session_data *sd;
  5272. sd=script_rid2sd(st);
  5273. for(i=0; i<MAX_INVENTORY; i++) {
  5274. if(sd->status.inventory[i].amount) {
  5275. push_val(st->stack,C_INT,1);
  5276. return 0;
  5277. }
  5278. }
  5279. push_val(st->stack,C_INT,0);
  5280. return 0;
  5281. }
  5282. // change npc walkspeed [Valaris]
  5283. int buildin_npcspeed(struct script_state *st)
  5284. {
  5285. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5286. int x=0;
  5287. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5288. if(nd) {
  5289. nd->speed=x;
  5290. }
  5291. return 0;
  5292. }
  5293. // make an npc walk to a position [Valaris]
  5294. int buildin_npcwalkto(struct script_state *st)
  5295. {
  5296. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5297. int x=0,y=0;
  5298. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5299. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5300. if(nd) {
  5301. npc_walktoxy(nd,x,y,0);
  5302. }
  5303. return 0;
  5304. }
  5305. // stop an npc's movement [Valaris]
  5306. int buildin_npcstop(struct script_state *st)
  5307. {
  5308. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5309. if(nd) {
  5310. if(nd->state.state==MS_WALK)
  5311. npc_stop_walking(nd,1);
  5312. }
  5313. return 0;
  5314. }
  5315. /*==========================================
  5316. * getlook char info. getlook(arg)
  5317. *------------------------------------------
  5318. */
  5319. int buildin_getlook(struct script_state *st){
  5320. int type,val;
  5321. struct map_session_data *sd;
  5322. sd=script_rid2sd(st);
  5323. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5324. val=-1;
  5325. switch(type){
  5326. case LOOK_HAIR: //1
  5327. val=sd->status.hair;
  5328. break;
  5329. case LOOK_WEAPON: //2
  5330. val=sd->status.weapon;
  5331. break;
  5332. case LOOK_HEAD_BOTTOM: //3
  5333. val=sd->status.head_bottom;
  5334. break;
  5335. case LOOK_HEAD_TOP: //4
  5336. val=sd->status.head_top;
  5337. break;
  5338. case LOOK_HEAD_MID: //5
  5339. val=sd->status.head_mid;
  5340. break;
  5341. case LOOK_HAIR_COLOR: //6
  5342. val=sd->status.hair_color;
  5343. break;
  5344. case LOOK_CLOTHES_COLOR: //7
  5345. val=sd->status.clothes_color;
  5346. break;
  5347. case LOOK_SHIELD: //8
  5348. val=sd->status.shield;
  5349. break;
  5350. case LOOK_SHOES: //9
  5351. break;
  5352. }
  5353. push_val(st->stack,C_INT,val);
  5354. return 0;
  5355. }
  5356. /*==========================================
  5357. * get char save point. argument: 0- map name, 1- x, 2- y
  5358. *------------------------------------------
  5359. */
  5360. int buildin_getsavepoint(struct script_state *st)
  5361. {
  5362. int x,y,type;
  5363. char *mapname;
  5364. struct map_session_data *sd;
  5365. sd=script_rid2sd(st);
  5366. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5367. mapname=calloc(24, 1);
  5368. x=sd->status.save_point.x;
  5369. y=sd->status.save_point.y;
  5370. strncpy(mapname,sd->status.save_point.map,24);
  5371. switch(type){
  5372. case 0:
  5373. push_str(st->stack,C_STR,mapname);
  5374. break;
  5375. case 1:
  5376. push_val(st->stack,C_INT,x);
  5377. break;
  5378. case 2:
  5379. push_val(st->stack,C_INT,y);
  5380. break;
  5381. }
  5382. return 0;
  5383. }
  5384. /*==========================================
  5385. * Get position for char/npc/pet/mob objects. Added by Lorky
  5386. *
  5387. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  5388. * where type:
  5389. * MapName$ - String variable for output map name
  5390. * MapX - Integer variable for output coord X
  5391. * MapY - Integer variable for output coord Y
  5392. * type - type of object
  5393. * 0 - Character coord
  5394. * 1 - NPC coord
  5395. * 2 - Pet coord
  5396. * 3 - Mob coord (not released)
  5397. * CharName$ - Name object. If miss or "this" the current object
  5398. *
  5399. * Return:
  5400. * 0 - success
  5401. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  5402. *------------------------------------------
  5403. */
  5404. int buildin_getmapxy(struct script_state *st){
  5405. struct map_session_data *sd=NULL;
  5406. struct npc_data *nd;
  5407. struct pet_data *pd;
  5408. int num;
  5409. char *name;
  5410. char prefix;
  5411. int x,y,type;
  5412. char *mapname;
  5413. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  5414. printf("script: buildin_getmapxy: not mapname variable\n");
  5415. push_val(st->stack,C_INT,-1);
  5416. return 0;
  5417. }
  5418. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  5419. printf("script: buildin_getmapxy: not mapx variable\n");
  5420. push_val(st->stack,C_INT,-1);
  5421. return 0;
  5422. }
  5423. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  5424. printf("script: buildin_getmapxy: not mapy variable\n");
  5425. push_val(st->stack,C_INT,-1);
  5426. return 0;
  5427. }
  5428. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  5429. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5430. mapname=calloc(24, 1);
  5431. switch (type){
  5432. case 0: //Get Character Position
  5433. if( st->end>st->start+6 )
  5434. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  5435. else
  5436. sd=script_rid2sd(st);
  5437. if ( sd==NULL ) { //wrong char name or char offline
  5438. push_val(st->stack,C_INT,-1);
  5439. return 0;
  5440. }
  5441. x=sd->bl.x;
  5442. y=sd->bl.y;
  5443. strncpy(mapname,sd->mapname,24);
  5444. printf(">>>>%s %d %d\n",mapname,x,y);
  5445. break;
  5446. case 1: //Get NPC Position
  5447. if( st->end > st->start+6 )
  5448. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  5449. else
  5450. nd=(struct npc_data *)map_id2bl(st->oid);
  5451. if ( nd==NULL ) { //wrong npc name or char offline
  5452. push_val(st->stack,C_INT,-1);
  5453. return 0;
  5454. }
  5455. x=nd->bl.x;
  5456. y=nd->bl.y;
  5457. strncpy(mapname,map[nd->bl.m].name,24);
  5458. printf(">>>>%s %d %d\n",mapname,x,y);
  5459. break;
  5460. case 2: //Get Pet Position
  5461. if( st->end>st->start+6 )
  5462. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  5463. else
  5464. sd=script_rid2sd(st);
  5465. if ( sd==NULL ) { //wrong char name or char offline
  5466. push_val(st->stack,C_INT,-1);
  5467. return 0;
  5468. }
  5469. pd=sd->pd;
  5470. if(pd==NULL){ //ped data not found
  5471. push_val(st->stack,C_INT,-1);
  5472. return 0;
  5473. }
  5474. x=pd->bl.x;
  5475. y=pd->bl.y;
  5476. strncpy(mapname,map[pd->bl.m].name,24);
  5477. printf(">>>>%s %d %d\n",mapname,x,y);
  5478. break;
  5479. case 3: //Get Mob Position
  5480. push_val(st->stack,C_INT,-1);
  5481. return 0;
  5482. default: //Wrong type parameter
  5483. push_val(st->stack,C_INT,-1);
  5484. return 0;
  5485. }
  5486. //Set MapName$
  5487. num=st->stack->stack_data[st->start+2].u.num;
  5488. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  5489. prefix=*name;
  5490. if( prefix!='$' )
  5491. sd=script_rid2sd(st);
  5492. else
  5493. sd=NULL;
  5494. set_reg(sd,num,name,(void*)mapname);
  5495. //Set MapX
  5496. num=st->stack->stack_data[st->start+3].u.num;
  5497. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  5498. prefix=*name;
  5499. if( prefix!='$' )
  5500. sd=script_rid2sd(st);
  5501. else
  5502. sd=NULL;
  5503. set_reg(sd,num,name,(void*)x);
  5504. //Set MapY
  5505. num=st->stack->stack_data[st->start+4].u.num;
  5506. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  5507. prefix=*name;
  5508. if( prefix!='$' )
  5509. sd=script_rid2sd(st);
  5510. else
  5511. sd=NULL;
  5512. set_reg(sd,num,name,(void*)y);
  5513. //Return Success value
  5514. push_val(st->stack,C_INT,0);
  5515. return 0;
  5516. }
  5517. //
  5518. // 実行部main
  5519. //
  5520. /*==========================================
  5521. * コマンドの読み取り
  5522. *------------------------------------------
  5523. */
  5524. static int unget_com_data=-1;
  5525. int get_com(unsigned char *script,int *pos)
  5526. {
  5527. int i,j;
  5528. if(unget_com_data>=0){
  5529. i=unget_com_data;
  5530. unget_com_data=-1;
  5531. return i;
  5532. }
  5533. if(script[*pos]>=0x80){
  5534. return C_INT;
  5535. }
  5536. i=0; j=0;
  5537. while(script[*pos]>=0x40){
  5538. i=script[(*pos)++]<<j;
  5539. j+=6;
  5540. }
  5541. return i+(script[(*pos)++]<<j);
  5542. }
  5543. /*==========================================
  5544. * コマンドのプッシュバック
  5545. *------------------------------------------
  5546. */
  5547. void unget_com(int c)
  5548. {
  5549. if(unget_com_data!=-1){
  5550. if(battle_config.error_log)
  5551. printf("unget_com can back only 1 data\n");
  5552. }
  5553. unget_com_data=c;
  5554. }
  5555. /*==========================================
  5556. * 数値の所得
  5557. *------------------------------------------
  5558. */
  5559. int get_num(unsigned char *script,int *pos)
  5560. {
  5561. int i,j;
  5562. i=0; j=0;
  5563. while(script[*pos]>=0xc0){
  5564. i+=(script[(*pos)++]&0x7f)<<j;
  5565. j+=6;
  5566. }
  5567. return i+((script[(*pos)++]&0x7f)<<j);
  5568. }
  5569. /*==========================================
  5570. * スタックから値を取り出す
  5571. *------------------------------------------
  5572. */
  5573. int pop_val(struct script_state* st)
  5574. {
  5575. if(st->stack->sp<=0)
  5576. return 0;
  5577. st->stack->sp--;
  5578. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  5579. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  5580. return st->stack->stack_data[st->stack->sp].u.num;
  5581. return 0;
  5582. }
  5583. #define isstr(c) ((c).type==C_STR || (c).type==C_CONSTSTR)
  5584. /*==========================================
  5585. * 加算演算子
  5586. *------------------------------------------
  5587. */
  5588. void op_add(struct script_state* st)
  5589. {
  5590. st->stack->sp--;
  5591. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  5592. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  5593. if(isstr(st->stack->stack_data[st->stack->sp]) || isstr(st->stack->stack_data[st->stack->sp-1])){
  5594. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  5595. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  5596. }
  5597. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  5598. st->stack->stack_data[st->stack->sp-1].u.num += st->stack->stack_data[st->stack->sp].u.num;
  5599. } else { // ssの予定
  5600. char *buf;
  5601. buf=(char *)aCalloc(strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  5602. strlen(st->stack->stack_data[st->stack->sp].u.str)+1,sizeof(char));
  5603. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  5604. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  5605. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  5606. free(st->stack->stack_data[st->stack->sp-1].u.str);
  5607. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  5608. free(st->stack->stack_data[st->stack->sp].u.str);
  5609. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  5610. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  5611. }
  5612. }
  5613. /*==========================================
  5614. * 二項演算子(文字列)
  5615. *------------------------------------------
  5616. */
  5617. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  5618. {
  5619. char *s1=st->stack->stack_data[sp1].u.str,
  5620. *s2=st->stack->stack_data[sp2].u.str;
  5621. int a=0;
  5622. switch(op){
  5623. case C_EQ:
  5624. a= (strcmp(s1,s2)==0);
  5625. break;
  5626. case C_NE:
  5627. a= (strcmp(s1,s2)!=0);
  5628. break;
  5629. case C_GT:
  5630. a= (strcmp(s1,s2)> 0);
  5631. break;
  5632. case C_GE:
  5633. a= (strcmp(s1,s2)>=0);
  5634. break;
  5635. case C_LT:
  5636. a= (strcmp(s1,s2)< 0);
  5637. break;
  5638. case C_LE:
  5639. a= (strcmp(s1,s2)<=0);
  5640. break;
  5641. default:
  5642. printf("illegal string operater\n");
  5643. break;
  5644. }
  5645. push_val(st->stack,C_INT,a);
  5646. if(st->stack->stack_data[sp1].type==C_STR) free(s1);
  5647. if(st->stack->stack_data[sp2].type==C_STR) free(s2);
  5648. }
  5649. /*==========================================
  5650. * 二項演算子(数値)
  5651. *------------------------------------------
  5652. */
  5653. void op_2num(struct script_state *st,int op,int i1,int i2)
  5654. {
  5655. switch(op){
  5656. case C_SUB:
  5657. i1-=i2;
  5658. break;
  5659. case C_MUL:
  5660. {
  5661. long long res = i1 * i2;
  5662. if (res > 2147483647 )
  5663. i1 = 2147483647;
  5664. else
  5665. i1*=i2;
  5666. }
  5667. break;
  5668. case C_DIV:
  5669. i1/=i2;
  5670. break;
  5671. case C_MOD:
  5672. i1%=i2;
  5673. break;
  5674. case C_AND:
  5675. i1&=i2;
  5676. break;
  5677. case C_OR:
  5678. i1|=i2;
  5679. break;
  5680. case C_XOR:
  5681. i1^=i2;
  5682. break;
  5683. case C_LAND:
  5684. i1=i1&&i2;
  5685. break;
  5686. case C_LOR:
  5687. i1=i1||i2;
  5688. break;
  5689. case C_EQ:
  5690. i1=i1==i2;
  5691. break;
  5692. case C_NE:
  5693. i1=i1!=i2;
  5694. break;
  5695. case C_GT:
  5696. i1=i1>i2;
  5697. break;
  5698. case C_GE:
  5699. i1=i1>=i2;
  5700. break;
  5701. case C_LT:
  5702. i1=i1<i2;
  5703. break;
  5704. case C_LE:
  5705. i1=i1<=i2;
  5706. break;
  5707. case C_R_SHIFT:
  5708. i1=i1>>i2;
  5709. break;
  5710. case C_L_SHIFT:
  5711. i1=i1<<i2;
  5712. break;
  5713. }
  5714. push_val(st->stack,C_INT,i1);
  5715. }
  5716. /*==========================================
  5717. * 二項演算子
  5718. *------------------------------------------
  5719. */
  5720. void op_2(struct script_state *st,int op)
  5721. {
  5722. int i1,i2;
  5723. char *s1=NULL,*s2=NULL;
  5724. i2=pop_val(st);
  5725. if( isstr(st->stack->stack_data[st->stack->sp]) )
  5726. s2=st->stack->stack_data[st->stack->sp].u.str;
  5727. i1=pop_val(st);
  5728. if( isstr(st->stack->stack_data[st->stack->sp]) )
  5729. s1=st->stack->stack_data[st->stack->sp].u.str;
  5730. if( s1!=NULL && s2!=NULL ){
  5731. // ss => op_2str
  5732. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  5733. }else if( s1==NULL && s2==NULL ){
  5734. // ii => op_2num
  5735. op_2num(st,op,i1,i2);
  5736. }else{
  5737. // si,is => error
  5738. printf("script: op_2: int&str, str&int not allow.");
  5739. push_val(st->stack,C_INT,0);
  5740. }
  5741. }
  5742. /*==========================================
  5743. * 単項演算子
  5744. *------------------------------------------
  5745. */
  5746. void op_1num(struct script_state *st,int op)
  5747. {
  5748. int i1;
  5749. i1=pop_val(st);
  5750. switch(op){
  5751. case C_NEG:
  5752. i1=-i1;
  5753. break;
  5754. case C_NOT:
  5755. i1=~i1;
  5756. break;
  5757. case C_LNOT:
  5758. i1=!i1;
  5759. break;
  5760. }
  5761. push_val(st->stack,C_INT,i1);
  5762. }
  5763. /*==========================================
  5764. * 関数の実行
  5765. *------------------------------------------
  5766. */
  5767. int run_func(struct script_state *st)
  5768. {
  5769. int i,start_sp,end_sp,func;
  5770. end_sp=st->stack->sp;
  5771. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  5772. if(i==0){
  5773. if(battle_config.error_log)
  5774. printf("function not found\n");
  5775. // st->stack->sp=0;
  5776. st->state=END;
  5777. return 0;
  5778. }
  5779. start_sp=i-1;
  5780. st->start=i-1;
  5781. st->end=end_sp;
  5782. func=st->stack->stack_data[st->start].u.num;
  5783. if( st->stack->stack_data[st->start].type!=C_NAME || str_data[func].type!=C_FUNC ){
  5784. printf("run_func: not function and command! \n");
  5785. // st->stack->sp=0;
  5786. st->state=END;
  5787. return 0;
  5788. }
  5789. #ifdef DEBUG_RUN
  5790. if(battle_config.etc_log) {
  5791. printf("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  5792. printf("stack dump :");
  5793. for(i=0;i<end_sp;i++){
  5794. switch(st->stack->stack_data[i].type){
  5795. case C_INT:
  5796. printf(" int(%d)",st->stack->stack_data[i].u.num);
  5797. break;
  5798. case C_NAME:
  5799. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num].str);
  5800. break;
  5801. case C_ARG:
  5802. printf(" arg");
  5803. break;
  5804. case C_POS:
  5805. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  5806. break;
  5807. default:
  5808. printf(" %d,%d",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  5809. }
  5810. }
  5811. printf("\n");
  5812. }
  5813. #endif
  5814. if(str_data[func].func){
  5815. str_data[func].func(st);
  5816. } else {
  5817. if(battle_config.error_log)
  5818. printf("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  5819. push_val(st->stack,C_INT,0);
  5820. }
  5821. pop_stack(st->stack,start_sp,end_sp);
  5822. if(st->state==RETFUNC){
  5823. // ユーザー定義関数からの復帰
  5824. int olddefsp=st->defsp;
  5825. int i;
  5826. pop_stack(st->stack,st->defsp,start_sp); // 復帰に邪魔なスタック削除
  5827. if(st->defsp<4 || st->stack->stack_data[st->defsp-1].type!=C_RETINFO){
  5828. printf("script:run_func(return) return without callfunc or callsub!\n");
  5829. st->state=END;
  5830. return 0;
  5831. }
  5832. i = conv_num(st,& (st->stack->stack_data[st->defsp-4])); // 引数の数所得
  5833. st->pos=conv_num(st,& (st->stack->stack_data[st->defsp-1])); // スクリプト位置の復元
  5834. st->script=(char*)conv_num(st,& (st->stack->stack_data[st->defsp-2])); // スクリプトを復元
  5835. st->defsp=conv_num(st,& (st->stack->stack_data[st->defsp-3])); // 基準スタックポインタを復元
  5836. pop_stack(st->stack,olddefsp-4-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  5837. st->state=GOTO;
  5838. }
  5839. return 0;
  5840. }
  5841. /*==========================================
  5842. * スクリプトの実行メイン部分
  5843. *------------------------------------------
  5844. */
  5845. int run_script_main(unsigned char *script,int pos,int rid,int oid,struct script_state *st,unsigned char *rootscript)
  5846. {
  5847. int c,rerun_pos;
  5848. int cmdcount=script_config.check_cmdcount;
  5849. int gotocount=script_config.check_gotocount;
  5850. struct script_stack *stack=st->stack;
  5851. st->defsp=stack->sp;
  5852. st->script=script;
  5853. rerun_pos=st->pos;
  5854. for(st->state=0;st->state==0;){
  5855. switch(c=get_com(script,&st->pos)){
  5856. case C_EOL:
  5857. if(stack->sp!=st->defsp){
  5858. if(battle_config.error_log)
  5859. printf("stack.sp(%d) != default(%d)\n",stack->sp,st->defsp);
  5860. stack->sp=st->defsp;
  5861. }
  5862. rerun_pos=st->pos;
  5863. break;
  5864. case C_INT:
  5865. push_val(stack,C_INT,get_num(script,&st->pos));
  5866. break;
  5867. case C_POS:
  5868. case C_NAME:
  5869. push_val(stack,c,(*(int*)(script+st->pos))&0xffffff);
  5870. st->pos+=3;
  5871. break;
  5872. case C_ARG:
  5873. push_val(stack,c,0);
  5874. break;
  5875. case C_STR:
  5876. push_str(stack,C_CONSTSTR,script+st->pos);
  5877. while(script[st->pos++]);
  5878. break;
  5879. case C_FUNC:
  5880. run_func(st);
  5881. if(st->state==GOTO){
  5882. rerun_pos=st->pos;
  5883. script=st->script;
  5884. st->state=0;
  5885. if( gotocount>0 && (--gotocount)<=0 ){
  5886. printf("run_script: infinity loop !\n");
  5887. st->state=END;
  5888. }
  5889. }
  5890. break;
  5891. case C_ADD:
  5892. op_add(st);
  5893. break;
  5894. case C_SUB:
  5895. case C_MUL:
  5896. case C_DIV:
  5897. case C_MOD:
  5898. case C_EQ:
  5899. case C_NE:
  5900. case C_GT:
  5901. case C_GE:
  5902. case C_LT:
  5903. case C_LE:
  5904. case C_AND:
  5905. case C_OR:
  5906. case C_XOR:
  5907. case C_LAND:
  5908. case C_LOR:
  5909. case C_R_SHIFT:
  5910. case C_L_SHIFT:
  5911. op_2(st,c);
  5912. break;
  5913. case C_NEG:
  5914. case C_NOT:
  5915. case C_LNOT:
  5916. op_1num(st,c);
  5917. break;
  5918. case C_NOP:
  5919. st->state=END;
  5920. break;
  5921. default:
  5922. if(battle_config.error_log)
  5923. printf("unknown command : %d @ %d\n",c,pos);
  5924. st->state=END;
  5925. break;
  5926. }
  5927. if( cmdcount>0 && (--cmdcount)<=0 ){
  5928. printf("run_script: infinity loop !\n");
  5929. st->state=END;
  5930. }
  5931. }
  5932. switch(st->state){
  5933. case STOP:
  5934. break;
  5935. case END:
  5936. {
  5937. struct map_session_data *sd=map_id2sd(st->rid);
  5938. st->pos=-1;
  5939. if(sd && sd->npc_id==st->oid)
  5940. npc_event_dequeue(sd);
  5941. }
  5942. break;
  5943. case RERUNLINE:
  5944. {
  5945. st->pos=rerun_pos;
  5946. }
  5947. break;
  5948. }
  5949. if( st->state!=END){
  5950. // 再開するためにスタック情報を保存
  5951. struct map_session_data *sd=map_id2sd(st->rid);
  5952. if(sd/* && sd->npc_stackbuf==NULL*/){
  5953. if( sd->npc_stackbuf )
  5954. free( sd->npc_stackbuf );
  5955. sd->npc_stackbuf = (char *)aCalloc(sizeof(stack->stack_data[0])*stack->sp_max,sizeof(char));
  5956. memcpy(sd->npc_stackbuf, stack->stack_data, sizeof(stack->stack_data[0]) * stack->sp_max);
  5957. sd->npc_stack = stack->sp;
  5958. sd->npc_stackmax = stack->sp_max;
  5959. sd->npc_script=script;
  5960. sd->npc_scriptroot=rootscript;
  5961. }
  5962. }
  5963. return 0;
  5964. }
  5965. /*==========================================
  5966. * スクリプトの実行
  5967. *------------------------------------------
  5968. */
  5969. int run_script(unsigned char *script,int pos,int rid,int oid)
  5970. {
  5971. struct script_stack stack;
  5972. struct script_state st;
  5973. struct map_session_data *sd=map_id2sd(rid);
  5974. unsigned char *rootscript=script;
  5975. if(script==NULL || pos<0)
  5976. return -1;
  5977. if(sd && sd->npc_stackbuf && sd->npc_scriptroot==(char*)rootscript){
  5978. // 前回のスタックを復帰
  5979. script=sd->npc_script;
  5980. stack.sp=sd->npc_stack;
  5981. stack.sp_max=sd->npc_stackmax;
  5982. stack.stack_data=(struct script_data *)aCalloc(stack.sp_max,sizeof(stack.stack_data[0]));
  5983. memcpy(stack.stack_data,sd->npc_stackbuf,sizeof(stack.stack_data[0])*stack.sp_max);
  5984. free(sd->npc_stackbuf);
  5985. sd->npc_stackbuf=NULL;
  5986. }else{
  5987. // スタック初期化
  5988. stack.sp=0;
  5989. stack.sp_max=64;
  5990. stack.stack_data=(struct script_data *)aCalloc(stack.sp_max,sizeof(stack.stack_data[0]));
  5991. }
  5992. st.stack=&stack;
  5993. st.pos=pos;
  5994. st.rid=rid;
  5995. st.oid=oid;
  5996. run_script_main(script,pos,rid,oid,&st,rootscript);
  5997. free(stack.stack_data);
  5998. stack.stack_data=NULL;
  5999. return st.pos;
  6000. }
  6001. /*==========================================
  6002. * マップ変数の変更
  6003. *------------------------------------------
  6004. */
  6005. int mapreg_setreg(int num,int val)
  6006. {
  6007. if(val!=0)
  6008. numdb_insert(mapreg_db,num,val);
  6009. else
  6010. numdb_erase(mapreg_db,num);
  6011. mapreg_dirty=1;
  6012. return 0;
  6013. }
  6014. /*==========================================
  6015. * 文字列型マップ変数の変更
  6016. *------------------------------------------
  6017. */
  6018. int mapreg_setregstr(int num,const char *str)
  6019. {
  6020. char *p;
  6021. if( (p=numdb_search(mapregstr_db,num))!=NULL )
  6022. free(p);
  6023. if( str==NULL || *str==0 ){
  6024. numdb_erase(mapregstr_db,num);
  6025. mapreg_dirty=1;
  6026. return 0;
  6027. }
  6028. p=(char *)aCalloc(strlen(str)+1, sizeof(char));
  6029. strcpy(p,str);
  6030. numdb_insert(mapregstr_db,num,p);
  6031. mapreg_dirty=1;
  6032. return 0;
  6033. }
  6034. /*==========================================
  6035. * 永続的マップ変数の読み込み
  6036. *------------------------------------------
  6037. */
  6038. static int script_load_mapreg()
  6039. {
  6040. FILE *fp;
  6041. char line[1024];
  6042. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  6043. return -1;
  6044. while(fgets(line,sizeof(line),fp)){
  6045. char buf1[256],buf2[1024],*p;
  6046. int n,v,s,i;
  6047. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  6048. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  6049. continue;
  6050. if( buf1[strlen(buf1)-1]=='$' ){
  6051. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  6052. printf("%s: %s broken data !\n",mapreg_txt,buf1);
  6053. continue;
  6054. }
  6055. p=(char *)aCalloc(strlen(buf2) + 1,sizeof(char));
  6056. strcpy(p,buf2);
  6057. s=add_str(buf1);
  6058. numdb_insert(mapregstr_db,(i<<24)|s,p);
  6059. }else{
  6060. if( sscanf(line+n,"%d",&v)!=1 ){
  6061. printf("%s: %s broken data !\n",mapreg_txt,buf1);
  6062. continue;
  6063. }
  6064. s=add_str(buf1);
  6065. numdb_insert(mapreg_db,(i<<24)|s,v);
  6066. }
  6067. }
  6068. fclose(fp);
  6069. mapreg_dirty=0;
  6070. return 0;
  6071. }
  6072. /*==========================================
  6073. * 永続的マップ変数の書き込み
  6074. *------------------------------------------
  6075. */
  6076. static int script_save_mapreg_intsub(void *key,void *data,va_list ap)
  6077. {
  6078. FILE *fp=va_arg(ap,FILE*);
  6079. int num=((int)key)&0x00ffffff, i=((int)key)>>24;
  6080. char *name=str_buf+str_data[num].str;
  6081. if( name[1]!='@' ){
  6082. if(i==0)
  6083. fprintf(fp,"%s\t%d\n", name, (int)data);
  6084. else
  6085. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  6086. }
  6087. return 0;
  6088. }
  6089. static int script_save_mapreg_strsub(void *key,void *data,va_list ap)
  6090. {
  6091. FILE *fp=va_arg(ap,FILE*);
  6092. int num=((int)key)&0x00ffffff, i=((int)key)>>24;
  6093. char *name=str_buf+str_data[num].str;
  6094. if( name[1]!='@' ){
  6095. if(i==0)
  6096. fprintf(fp,"%s\t%s\n", name, (char *)data);
  6097. else
  6098. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  6099. }
  6100. return 0;
  6101. }
  6102. static int script_save_mapreg()
  6103. {
  6104. FILE *fp;
  6105. int lock;
  6106. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL )
  6107. return -1;
  6108. numdb_foreach(mapreg_db,script_save_mapreg_intsub,fp);
  6109. numdb_foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  6110. lock_fclose(fp,mapreg_txt,&lock);
  6111. mapreg_dirty=0;
  6112. return 0;
  6113. }
  6114. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  6115. {
  6116. if(mapreg_dirty)
  6117. script_save_mapreg();
  6118. return 0;
  6119. }
  6120. /*==========================================
  6121. *
  6122. *------------------------------------------
  6123. */
  6124. static int set_posword(char *p)
  6125. {
  6126. char* np,* str[15];
  6127. int i=0;
  6128. for(i=0;i<11;i++) {
  6129. if((np=strchr(p,','))!=NULL) {
  6130. str[i]=p;
  6131. *np=0;
  6132. p=np+1;
  6133. } else {
  6134. str[i]=p;
  6135. p+=strlen(p);
  6136. }
  6137. if(str[i])
  6138. strcpy(pos[i],str[i]);
  6139. }
  6140. return 0;
  6141. }
  6142. int script_config_read(char *cfgName)
  6143. {
  6144. int i;
  6145. char line[1024],w1[1024],w2[1024];
  6146. FILE *fp;
  6147. script_config.warn_func_no_comma=1;
  6148. script_config.warn_cmd_no_comma=1;
  6149. script_config.warn_func_mismatch_paramnum=1;
  6150. script_config.warn_cmd_mismatch_paramnum=1;
  6151. script_config.check_cmdcount=8192;
  6152. script_config.check_gotocount=512;
  6153. fp=fopen(cfgName,"r");
  6154. if(fp==NULL){
  6155. printf("file not found: %s\n",cfgName);
  6156. return 1;
  6157. }
  6158. while(fgets(line,1020,fp)){
  6159. if(line[0] == '/' && line[1] == '/')
  6160. continue;
  6161. i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  6162. if(i!=2)
  6163. continue;
  6164. if(strcmpi(w1,"refine_posword")==0) {
  6165. set_posword(w2);
  6166. }
  6167. if(strcmpi(w1,"import")==0){
  6168. script_config_read(w2);
  6169. }
  6170. }
  6171. fclose(fp);
  6172. return 0;
  6173. }
  6174. /*==========================================
  6175. * 終了
  6176. *------------------------------------------
  6177. */
  6178. static int mapreg_db_final(void *key,void *data,va_list ap)
  6179. {
  6180. return 0;
  6181. }
  6182. static int mapregstr_db_final(void *key,void *data,va_list ap)
  6183. {
  6184. free(data);
  6185. return 0;
  6186. }
  6187. static int scriptlabel_db_final(void *key,void *data,va_list ap)
  6188. {
  6189. return 0;
  6190. }
  6191. static int userfunc_db_final(void *key,void *data,va_list ap)
  6192. {
  6193. free(key);
  6194. free(data);
  6195. return 0;
  6196. }
  6197. int do_final_script()
  6198. {
  6199. if(mapreg_dirty>=0)
  6200. script_save_mapreg();
  6201. if(script_buf)
  6202. free(script_buf);
  6203. if(mapreg_db)
  6204. numdb_final(mapreg_db,mapreg_db_final);
  6205. if(mapregstr_db)
  6206. strdb_final(mapregstr_db,mapregstr_db_final);
  6207. if(scriptlabel_db)
  6208. strdb_final(scriptlabel_db,scriptlabel_db_final);
  6209. if(userfunc_db)
  6210. strdb_final(userfunc_db,userfunc_db_final);
  6211. if (str_data)
  6212. free(str_data);
  6213. if (str_buf)
  6214. free(str_buf);
  6215. return 0;
  6216. }
  6217. /*==========================================
  6218. * 初期化
  6219. *------------------------------------------
  6220. */
  6221. int do_init_script()
  6222. {
  6223. mapreg_db=numdb_init();
  6224. mapregstr_db=numdb_init();
  6225. script_load_mapreg();
  6226. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  6227. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  6228. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  6229. scriptlabel_db=strdb_init(50);
  6230. return 0;
  6231. }