main.py 460 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #This file is part of RogueBox Adventures.
  4. #
  5. # RogueBox Adventures is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # RogueBox Adventures is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with RogueBox Adventures. If not, see <http://www.gnu.org/licenses/>.
  17. import datetime
  18. import time
  19. from time import sleep as sleep
  20. import sys
  21. import os
  22. low_res = False
  23. gcwz_input = False
  24. home_save = False
  25. force_small_worlds = False
  26. cheat_mode = False
  27. Time_ready = False
  28. entrance_x = 0
  29. entrance_y = 0
  30. basic_path = os.path.dirname(os.path.realpath('main.py')) #just get the execution path for resources
  31. for t in sys.argv:
  32. if t == '-m':
  33. p = os.path.expanduser(basic_path)
  34. lf = open('rba.desktop','w')
  35. lf.write('[Desktop Entry]\n')
  36. lf.write('Type=Application\n')
  37. lf.write('Name=RogueBox Adventures\n')
  38. lf.write('Comment=A RogueBox Game\n')
  39. lf.write('Exec=sh ' + p + os.sep + 'LIB' + os.sep + 'run.sh\n')
  40. lf.write('Icon=' + p + os.sep + 'icon_big.png\n')
  41. lf.write('Terminal=false\n')
  42. lf.write('Categories=Game;')
  43. lf.close()
  44. rf_path = p + os.sep + 'LIB' + os.sep + 'run.sh'
  45. rf = open(rf_path,'w')
  46. rf.write('#This file was generated automatically. Please don\'t change anything.\n')
  47. rf.write('cd ' + p + '\n')
  48. rf.write('python ' + p + os.sep + 'run.py')
  49. sys_com = 'chmod +x ' + p + os.sep + 'rba.desktop'
  50. os.system(sys_com)
  51. exit(0)
  52. if t == '-c':
  53. cheat_mode = True
  54. if t == '-g':
  55. gcwz_input = True
  56. if t == '-s':
  57. force_small_worlds = True
  58. if t == '-h':
  59. home_save = True
  60. lib_path = basic_path + os.sep + 'LIB'
  61. data_path = basic_path + os.sep + 'DATA'
  62. if home_save == False:
  63. save_path = basic_path + os.sep + 'SAVE' + os.sep + 'World0'
  64. else:
  65. save_path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures' + os.sep + 'SAVE' + os.sep + 'World0'
  66. path = save_path.replace(os.sep+'World0','')
  67. if os.path.exists(path) == False:
  68. for c in range(0,5):
  69. ph = path + os.sep + 'World' + str(c)
  70. os.makedirs(ph)
  71. del path
  72. playing = False
  73. sys.path.append(lib_path)
  74. max_map_size = 52
  75. monitor = [0,0]
  76. try:
  77. import cPickle as p
  78. except:
  79. import pickle as p
  80. try:
  81. p.DEFAULT_PROTOCOL=0
  82. except:
  83. p.HIGHEST_PROTOCOL=0
  84. import random
  85. if gcwz_input == True:
  86. from getch_gcwz import *
  87. else:
  88. from getch import *
  89. from tile import tile
  90. from attribute import attribute
  91. from item import *
  92. from countdown import *
  93. import pygame
  94. from gra_files import *
  95. from util import *
  96. from monster import monster
  97. from copy import deepcopy
  98. from buffs import buffs
  99. from itemlist import *
  100. from tilelist import *
  101. from monsterlist import *
  102. from text import texts
  103. from skill import *
  104. from version import *
  105. game_options = game_options(basic_path,home_save)
  106. if game_options.check_version == 1:
  107. ver_string = check_version()
  108. else:
  109. ver_string = ' '
  110. class g_screen():
  111. def __init__(self, mode = game_options.screenmode, show_logo = True):
  112. string = 'RogueBoxAdventures ' + version +' "'+version_name+'"'
  113. pygame.display.set_caption(string)
  114. icon = pygame.image.load('icon_small.png')
  115. pygame.display.set_icon(icon)
  116. global monitor
  117. self.fire_mode = 0 #0: normal, 1: fire
  118. self.win_mode = mode
  119. self.hit_matrix = []
  120. for y in range(0,12):
  121. self.hit_matrix.append([])
  122. for x in range(0,15):
  123. self.hit_matrix[y].append(0)
  124. pygame.init()
  125. display_info = pygame.display.Info()
  126. if monitor == [0,0]:
  127. monitor[0] = display_info.current_w
  128. monitor[1] = display_info.current_h
  129. self.displayx = monitor[0]
  130. self.displayy = monitor[1]
  131. #check if the screenmode is 16:9
  132. if float(self.displayx/self.displayy) < float(16/9):
  133. self.displayx = monitor[0]-monitor[0]%16
  134. elif float(self.displayx/self.displayy) > float(16/9):
  135. self.displayy = monitor[1]-monitor[1]%9
  136. winstyle = pygame.FULLSCREEN
  137. if cheat_mode == True and self.win_mode == 2:
  138. self.win_mode = 1 #disable fullscreen in cheat mode
  139. if self.win_mode == 2:
  140. self.screen = pygame.display.set_mode((self.displayx,self.displayy),winstyle)
  141. pygame.mouse.set_visible(game_options.mousepad)
  142. elif self.win_mode == 0 and low_res == False:
  143. self.screen = pygame.display.set_mode((640,360))
  144. self.displayx = 640
  145. self.displayy = 360
  146. elif self.win_mode == 1 and low_res == False:
  147. self.screen = pygame.display.set_mode((1280,720))
  148. self.displayx = 1280
  149. self.displayy = 720
  150. font_path = basic_path + os.sep + 'FONT' + os.sep + 'PressStart2P.ttf'
  151. self.font = pygame.font.Font(font_path,8)
  152. if low_res == True:
  153. str_ext = '_low_res'
  154. else:
  155. str_ext = ''
  156. if __name__ == '__main__':
  157. show_logo = False
  158. if show_logo == True:
  159. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  160. ran = random.randint(0,4)
  161. i_name = display_path + 'logo' + str(ran) + str_ext + '.png'
  162. i = pygame.image.load(i_name)
  163. i = pygame.transform.scale(i,(self.displayx,self.displayy))
  164. self.screen.blit(i,(0,0))
  165. pygame.display.flip()
  166. getch(640,360,mode=1)
  167. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  168. ran = random.randint(0,4)
  169. i_name = display_path + 'logo_gpl' + str_ext + '.png'
  170. i = pygame.image.load(i_name)
  171. i = pygame.transform.scale(i,(self.displayx,self.displayy))
  172. self.screen.blit(i,(0,0))
  173. pygame.display.flip()
  174. getch(640,360,mode=1)
  175. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  176. i_name = display_path + 'oga' + str_ext + '.png'
  177. i = pygame.image.load(i_name)
  178. i = pygame.transform.scale(i,(self.displayx,self.displayy))
  179. self.screen.blit(i,(0,0))
  180. pygame.display.flip()
  181. getch(640,360,mode=1)
  182. def render_fade(self,fadeout,fadein,menu='default'):
  183. if menu == 'inventory':
  184. bg = player.inventory.render(0,0,simulate=True)
  185. elif menu == 'screen':
  186. bg = screen.screen
  187. elif menu == 'loot':
  188. bg = world.maplist[player.pos[2]][player.on_map].containers[player.pos[1]][player.pos[0]].inventory(simulated=True)
  189. elif menu == 'brake':
  190. bg = screen.render_brake(simulate=True)
  191. elif menu == 'main':
  192. bg = screen.render_main_menu(simulate=True)
  193. else:
  194. bg = self.render(0,True)
  195. clock = pygame.time.Clock()
  196. if fadein:
  197. for i in range(255,0,-15):
  198. helpsur = pygame.Surface((self.displayx,self.displayy))
  199. helpsur.fill((48,48,48))
  200. helpsur.set_alpha(i)
  201. self.screen.blit(bg,(0,0))
  202. self.screen.blit(helpsur,(0,0))
  203. pygame.display.flip()
  204. clock.tick(510)
  205. if fadeout:
  206. for i in range(0,255,15):
  207. helpsur = pygame.Surface((self.displayx,self.displayy))
  208. helpsur.fill((48,48,48))
  209. helpsur.set_alpha(i)
  210. self.screen.blit(bg,(0,0))
  211. self.screen.blit(helpsur,(0,0))
  212. pygame.display.flip()
  213. clock.tick(510)
  214. def reset_hit_matrix(self):
  215. self.hit_matrix = []
  216. for y in range(0,12):
  217. self.hit_matrix.append([])
  218. for x in range(0,15):
  219. self.hit_matrix[y].append(0)
  220. def write_hit_matrix(self,x,y,style):
  221. #style: 0:nothing
  222. # 1:fire_path
  223. # 2:fire_path_monster
  224. # 3:miss
  225. # 4:hit
  226. # 5:critical
  227. # 6:heal
  228. # 7:teleport
  229. # 8:minus_gem
  230. # 9:plus_gem
  231. # 10:plus_fish
  232. # 11:plus_shoe
  233. # 12:monster_lvl_up
  234. # 13:monster_die
  235. # 14:attention
  236. # 15:found
  237. # 16:drop
  238. # 17:fear
  239. # 18:blood_minus
  240. # 19:blood_plus
  241. # 20:throw
  242. # 21:minus_item
  243. # 22:plus_item
  244. xx = x - player.pos[0] + 8
  245. yy = y - player.pos[1] + 6
  246. try:
  247. if xx >= 0 and yy >= 0:
  248. self.hit_matrix[yy][xx] = style
  249. except:
  250. None
  251. def render_hits(self):
  252. s = pygame.Surface((480,360))
  253. s.fill((255,0,255))
  254. start = 0
  255. for y in range(start,len(self.hit_matrix)):
  256. for x in range(start,len(self.hit_matrix[0])):
  257. if self.hit_matrix[y][x] == 1:
  258. s.blit(gra_files.gdic['display'][11],(((x-start)*32),(y-start)*32))
  259. elif self.hit_matrix[y][x] == 2:
  260. s.blit(gra_files.gdic['display'][12],(((x-start)*32),(y-start)*32))
  261. elif self.hit_matrix[y][x] == 3:
  262. s.blit(gra_files.gdic['display'][13],(((x-start)*32),(y-start)*32))
  263. elif self.hit_matrix[y][x] == 4:
  264. s.blit(gra_files.gdic['display'][14],(((x-start)*32),(y-start)*32))
  265. elif self.hit_matrix[y][x] == 5:
  266. s.blit(gra_files.gdic['display'][15],(((x-start)*32),(y-start)*32))
  267. elif self.hit_matrix[y][x] == 6:
  268. s.blit(gra_files.gdic['display'][23],(((x-start)*32),(y-start)*32))
  269. elif self.hit_matrix[y][x] == 7:
  270. s.blit(gra_files.gdic['display'][24],(((x-start)*32),(y-start)*32))
  271. elif self.hit_matrix[y][x] == 8:
  272. s.blit(gra_files.gdic['display'][26],(((x-start)*32),(y-start)*32))
  273. elif self.hit_matrix[y][x] == 9:
  274. s.blit(gra_files.gdic['display'][27],(((x-start)*32),(y-start)*32))
  275. elif self.hit_matrix[y][x] == 10:
  276. s.blit(gra_files.gdic['display'][42],(((x-start)*32),(y-start)*32))
  277. elif self.hit_matrix[y][x] == 11:
  278. s.blit(gra_files.gdic['display'][43],(((x-start)*32),(y-start)*32))
  279. elif self.hit_matrix[y][x] == 12:
  280. s.blit(gra_files.gdic['display'][51],(((x-start)*32),(y-start)*32))
  281. elif self.hit_matrix[y][x] == 13:
  282. s.blit(gra_files.gdic['display'][58],(((x-start)*32),(y-start)*32))
  283. elif self.hit_matrix[y][x] == 14:
  284. s.blit(gra_files.gdic['display'][59],(((x-start)*32),(y-start)*32))
  285. elif self.hit_matrix[y][x] == 15:
  286. s.blit(gra_files.gdic['display'][60],(((x-start)*32),(y-start)*32))
  287. elif self.hit_matrix[y][x] == 16:
  288. s.blit(gra_files.gdic['display'][61],(((x-start)*32),(y-start)*32))
  289. elif self.hit_matrix[y][x] == 17:
  290. s.blit(gra_files.gdic['display'][62],(((x-start)*32),(y-start)*32))
  291. elif self.hit_matrix[y][x] == 18:
  292. s.blit(gra_files.gdic['display'][63],(((x-start)*32),(y-start)*32))
  293. elif self.hit_matrix[y][x] == 19:
  294. s.blit(gra_files.gdic['display'][64],(((x-start)*32),(y-start)*32))
  295. elif self.hit_matrix[y][x] == 20:
  296. s.blit(gra_files.gdic['display'][65],(((x-start)*32),(y-start)*32))
  297. elif self.hit_matrix[y][x] == 21:
  298. s.blit(gra_files.gdic['display'][66],(((x-start)*32),(y-start)*32))
  299. elif self.hit_matrix[y][x] == 22:
  300. s.blit(gra_files.gdic['display'][67],(((x-start)*32),(y-start)*32))
  301. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  302. s = s.convert_alpha()
  303. return s
  304. def render_main_menu(self,simulate=False):
  305. if simulate == False:
  306. screen.render_fade(False,True,'main')
  307. if home_save == False:
  308. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  309. alt_path = display_path
  310. else:
  311. display_path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures' + os.sep
  312. alt_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  313. num = 0
  314. master_loop = True
  315. run = True
  316. while run:
  317. s = pygame.Surface((640,360))
  318. s.fill((48,48,48))
  319. try:
  320. i_name = display_path + 'tmp.png'
  321. i = pygame.image.load(i_name)
  322. i.set_colorkey((255,0,255),pygame.RLEACCEL)
  323. i = i.convert_alpha()
  324. s.blit(i,(0,0))
  325. except:
  326. i_name = alt_path + 'alt.png'
  327. i = pygame.image.load(i_name)
  328. i.set_colorkey((255,0,255),pygame.RLEACCEL)
  329. i = i.convert_alpha()
  330. s.blit(i,(0,0))
  331. s.blit(gra_files.gdic['display'][16],(0,0))
  332. menu_list = ('PLAY','OPTIONS','CREDITS','QUIT')
  333. for c in range(0,len(menu_list)):
  334. name_image = self.font.render(menu_list[c],1,(0,0,0))
  335. s.blit(name_image,(210,145+(c*45)))
  336. s.blit(gra_files.gdic['display'][4],(185,138+(num*45)))
  337. version_info = 'v'+version+' "'+version_name+'"'
  338. ver_info_image1 = self.font.render(version_info,1,(0,0,0))
  339. ver_info_image2 = self.font.render(version_info,1,(255,255,255))
  340. s.blit(ver_info_image1,(107,85))
  341. s.blit(ver_info_image2,(105,85))
  342. if game_options.check_version == 1:
  343. if ver_string == 'This version is up to date.':
  344. ver_image = self.font.render(ver_string,1,(0,255,0))
  345. elif ver_string == 'Old version!!! Please update.':
  346. ver_image = self.font.render(ver_string,1,(255,0,0))
  347. else:
  348. ver_image = self.font.render(ver_string,1,(255,255,255))
  349. ver_image2 = self.font.render(ver_string,1,(0,0,0))
  350. s.blit(ver_image2,(12,340))
  351. s.blit(ver_image,(10,340))
  352. if game_options.mousepad == 0:
  353. s_h = pygame.Surface((160,360))
  354. s_h.fill((48,48,48))
  355. s.blit(s_h,(480,0))
  356. s_help = pygame.Surface((640,360))
  357. s_help.fill((48,48,48))
  358. s_help.blit(s,(80,0))
  359. s = s_help
  360. else:
  361. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  362. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  363. if simulate == True:
  364. return s
  365. self.screen.blit(s,(0,0))
  366. pygame.display.flip()
  367. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  368. if ui == 'exit':
  369. master_loop = False
  370. run = False
  371. if ui == 'w':
  372. num -= 1
  373. if num < 0:
  374. num = 0
  375. elif ui == 's':
  376. num += 1
  377. if num > 3:
  378. num = 3
  379. elif ui == 'e':
  380. if num == 0:
  381. test = screen.choose_save_path()
  382. if test == 'exit':
  383. master_loop = False
  384. run = False
  385. elif num == 1:
  386. test = screen.render_options()
  387. if test == 'exit':
  388. master_loop = False
  389. run = False
  390. elif num == 2:
  391. test = screen.render_credits()
  392. if test == 'exit':
  393. master_loop = False
  394. run = False
  395. elif num == 3:
  396. master_loop = False
  397. run = False
  398. return master_loop
  399. def render_crash(self):
  400. run = True
  401. while run:
  402. self.screen.fill((48,48,48))
  403. string = []
  404. string.append('Sorry, something went wrong.')
  405. string.append('Check out debug.txt for more informations.')
  406. debug_location = '('+save_path+')'
  407. for c in range(0,6):
  408. debug_location = debug_location.replace('World'+str(c),'debug.txt')
  409. string.append(debug_location)
  410. st = []
  411. for i in string:
  412. st.append(self.font.render(i,1,(255,255,255)))
  413. for j in range(0,len(st)):
  414. self.screen.blit(st[j],(5,25+j*25))
  415. pygame.display.flip()
  416. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  417. if ui != 'none':
  418. run = False
  419. def choose_save_path(self):
  420. global save_path
  421. global playing
  422. global master_loop
  423. global gra_files
  424. gra_files = g_files()
  425. if home_save == True:
  426. path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures'
  427. else:
  428. path = basic_path
  429. run = True
  430. while run:
  431. menu_items = []
  432. for c in range(0,5):
  433. save_path = path + os.sep + 'SAVE' + os.sep + 'World' + str(c)
  434. p_attribute = attribute(2,2,2,2,2,10,10)
  435. p_inventory = inventory()
  436. player_help = player_class ('-EMPTY SLOT-', 'local_0_0', p_attribute,p_inventory, build= 'Auto')
  437. if player_help.name != '-EMPTY SLOT-':
  438. item_string = player_help.name + ' LVL:' + str(player_help.lvl)
  439. else:
  440. item_string = '-EMPTY SLOT-'
  441. menu_items.append(item_string)
  442. menu_items.append('~~ERASE~~')
  443. menu_items.append('~~BACK~~')
  444. choice = screen.get_choice('Choose a saved game',menu_items,False)
  445. if choice == 'exit':
  446. master_loop = False
  447. run = False
  448. return('exit')
  449. if choice < 5:
  450. save_path = path + os.sep + 'SAVE' + os.sep + 'World' + str(choice)
  451. playing = True
  452. run = False
  453. elif choice == 5:
  454. menu_items_erase = []
  455. for d in range(0,5):
  456. menu_items_erase.append(menu_items[d])
  457. menu_items_erase.append('~~BACK~~')
  458. choice2 = screen.get_choice('Choose a game to erase',menu_items_erase,False,'Warning')
  459. if choice2 < 5:
  460. save_path = path + os.sep + 'SAVE' + os.sep + 'World' + str(choice2)
  461. try:
  462. choice3 = screen.get_choice('Are you sure?',('No','Yes'),False,'Warning')
  463. if choice3 == 1:
  464. h = ('world.data','time.data','player.data','gods.data')
  465. for i in h:
  466. p = save_path + os.sep + i
  467. os.remove(p)
  468. except:
  469. None
  470. elif choice == 6:
  471. run = False
  472. def save_tmp_png(self):
  473. x = player.pos[0]
  474. if x-10 < 0:
  475. x += -1*(x-11)
  476. elif x+10 > max_map_size-2:
  477. x -= 10
  478. y = player.pos[1]
  479. if y-10 < 0:
  480. y += -1*(y-11)
  481. elif y+10 > max_map_size-2:
  482. y -= 10
  483. z = player.pos[2]
  484. s = pygame.Surface((480,360))
  485. for yy in range(-5,10):
  486. for xx in range(-7,8):
  487. t_pos = world.maplist[z][player.on_map].tilemap[y+yy][x+xx].tile_pos
  488. t_replace = world.maplist[z][player.on_map].tilemap[y+yy][x+xx].replace
  489. if t_replace == None:
  490. s.blit(gra_files.gdic['tile32'][t_pos[1]][t_pos[0]],((xx+7)*32,(yy+5)*32))
  491. else:
  492. try:
  493. #render the replaced tile under the replacing one. eg.: for stacks
  494. s.blit(gra_files.gdic['tile32'][t_replace.tile_pos[1]][t_replace.tile_pos[0]],((xx+7)*32,(yy+5)*32))
  495. s.blit(gra_files.gdic['tile32'][t_pos[1]][t_pos[0]],((xx+7)*32,(yy+5)*32))
  496. except:
  497. None
  498. if home_save == False:
  499. tmp_save_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep + 'tmp.png'
  500. else:
  501. tmp_save_path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures' + os.sep + 'tmp.png'
  502. pygame.image.save(s,tmp_save_path)
  503. def re_init(self): # For changing screenmode
  504. options_path = save_path.replace(os.sep + 'World0','')
  505. if game_options.screenmode == 2 and cheat_mode == True:
  506. game_options.screenmode = 0
  507. mode = game_options.screenmode
  508. if self.win_mode < 2:
  509. mode += 1
  510. else:
  511. mode = 0
  512. if mode == 2 and cheat_mode == True:
  513. mode = 0
  514. game_options.screenmode = mode
  515. save_options(game_options,options_path,os.sep)
  516. self.__init__(game_options.screenmode,False)
  517. def draw_player(self):
  518. s = pygame.Surface((32,32))
  519. s.fill((255,0,255))
  520. if player.inventory.wearing['Background'] != player.inventory.nothing:
  521. s.blit(gra_files.gdic['clothe'][player.inventory.wearing['Background'].gra_pos[player.gender][0]][player.inventory.wearing['Background'].gra_pos[player.gender][1]],(0,0))
  522. skinstring = 'SKIN_' + player.gender + '_' + str(player.style +1)
  523. s.blit(gra_files.gdic['char'][skinstring],(0,0))
  524. try:
  525. render_hair = (player.inventory.wearing['Hat'].override_hair == False)
  526. except:
  527. render_hair = True
  528. if player.inventory.wearing['Head'] == player.inventory.nothing and render_hair:
  529. hairstring = 'HAIR_' + player.gender + '_' + str(player.style +1)
  530. s.blit(gra_files.gdic['char'][hairstring],(0,0))
  531. if player.inventory.wearing['Hat'] != player.inventory.nothing:
  532. s.blit(gra_files.gdic['clothe'][player.inventory.wearing['Hat'].gra_pos[player.gender][0]][player.inventory.wearing['Hat'].gra_pos[player.gender][1]],(0,0))
  533. else:
  534. if player.inventory.wearing['Hat'] == player.inventory.nothing:
  535. if player.inventory.wearing['Head'] != player.inventory.nothing:
  536. helmetstring = player.gender + '_' + player.inventory.wearing['Head'].material + '_' + player.inventory.wearing['Head'].classe
  537. s.blit(gra_files.gdic['char'][helmetstring],(0,0))
  538. else:
  539. if render_hair == True:
  540. hairstring = 'HAIR_' + player.gender + '_' + str(player.style +1)
  541. s.blit(gra_files.gdic['char'][hairstring],(0,0))
  542. s.blit(gra_files.gdic['clothe'][player.inventory.wearing['Hat'].gra_pos[player.gender][0]][player.inventory.wearing['Hat'].gra_pos[player.gender][1]],(0,0))
  543. if player.inventory.wearing['Clothing'] == player.inventory.nothing:
  544. if player.inventory.wearing['Body'] != player.inventory.nothing:
  545. armorstring = player.gender + '_' + player.inventory.wearing['Body'].material + '_' + player.inventory.wearing['Body'].classe
  546. s.blit(gra_files.gdic['char'][armorstring],(0,0))
  547. if player.inventory.wearing['Legs'] != player.inventory.nothing:
  548. cuissestring = player.gender + '_' + player.inventory.wearing['Legs'].material + '_' + player.inventory.wearing['Legs'].classe
  549. s.blit(gra_files.gdic['char'][cuissestring],(0,0))
  550. if player.inventory.wearing['Feet'] != player.inventory.nothing:
  551. shoestring = player.gender + '_' + player.inventory.wearing['Feet'].material + '_' + player.inventory.wearing['Feet'].classe
  552. s.blit(gra_files.gdic['char'][shoestring],(0,0))
  553. else:
  554. s.blit(gra_files.gdic['clothe'][player.inventory.wearing['Clothing'].gra_pos[player.gender][0]][player.inventory.wearing['Clothing'].gra_pos[player.gender][1]],(0,0))
  555. if player.inventory.wearing['Hold(R)'] != player.inventory.nothing:
  556. weaponstring = 'WEAPONS_' + player.inventory.wearing['Hold(R)'].material + '_' + player.inventory.wearing['Hold(R)'].classe
  557. s.blit(gra_files.gdic['char'][weaponstring],(0,0))
  558. if player.inventory.wearing['Hold(L)'] != player.inventory.nothing:
  559. weaponstring = 'WEAPONS_' + player.inventory.wearing['Hold(L)'].material + '_' + player.inventory.wearing['Hold(L)'].classe
  560. s.blit(gra_files.gdic['char'][weaponstring],(0,0))
  561. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]][player.pos[0]].move_group == 'low_liquid':
  562. help_s = pygame.Surface((32,5))
  563. help_s.fill((255,0,255))
  564. s.blit(help_s,(0,27))
  565. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]][player.pos[0]].move_group == 'swim':
  566. help_s = pygame.Surface((32,13))
  567. help_s.fill((255,0,255))
  568. s.blit(help_s,(0,19))
  569. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  570. return s
  571. def draw_tile(self,on_map,x,y,z,visible):
  572. s = pygame.Surface((32,32))
  573. s.fill((48,48,48))
  574. if x > max_map_size-1 or y > max_map_size-1 or x < 0 or y < 0:
  575. return s
  576. if world.maplist[z][on_map].known[y][x] == 0:
  577. s.blit(gra_files.gdic['tile32'][0][3],(0,0))
  578. else:
  579. if world.maplist[z][on_map].tilemap[y][x].replace != None:
  580. old_tile = world.maplist[z][on_map].tilemap[y][x]
  581. new_tile = world.maplist[z][on_map].tilemap[y][x]
  582. run = True
  583. while run:
  584. new_tile = old_tile.replace
  585. if new_tile != None:
  586. old_tile = new_tile
  587. else:
  588. run = False
  589. if len(old_tile.tile_pos) > 2:
  590. if time.minute%2 == 0:
  591. s.blit(gra_files.gdic['tile32'][old_tile.tile_pos[1]][old_tile.tile_pos[0]],(0,0))
  592. else:
  593. s.blit(gra_files.gdic['tile32'][old_tile.tile_pos[3]][old_tile.tile_pos[2]],(0,0))
  594. else:
  595. s.blit(gra_files.gdic['tile32'][old_tile.tile_pos[1]][old_tile.tile_pos[0]],(0,0))
  596. if len(world.maplist[z][on_map].tilemap[y][x].tile_pos) > 2:
  597. if time.minute%2 == 0:
  598. s.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]],(0,0))
  599. else:
  600. s.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y][x].tile_pos[3]][world.maplist[z][on_map].tilemap[y][x].tile_pos[2]],(0,0))
  601. else:
  602. s.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]],(0,0))
  603. if visible == False:
  604. s.blit(gra_files.gdic['display'][6],(0,0))
  605. if world.maplist[z][on_map].npcs[y][x] != 0:
  606. s.blit(self.draw_monster(x,y,z,on_map,visible),(0,0))
  607. return s
  608. def draw_monster(self,x,y,z,on_map,visible):
  609. s = pygame.Surface((32,32))
  610. s.fill((255,0,255))
  611. if visible == True:
  612. pos = world.maplist[z][on_map].npcs[y][x].sprite_pos
  613. s.blit(gra_files.gdic['monster'][pos[1]][pos[0]],(0,0))
  614. if world.maplist[z][on_map].tilemap[y][x].move_group == 'low_liquid':
  615. help_s = pygame.Surface((32,5))
  616. help_s.fill((255,0,255))
  617. s.blit(help_s,(0,27))
  618. elif world.maplist[z][on_map].tilemap[y][x].move_group == 'swim':
  619. help_s = pygame.Surface((32,13))
  620. help_s.fill((255,0,255))
  621. s.blit(help_s,(0,19))
  622. if world.maplist[z][on_map].npcs[y][x].move_border > 9:
  623. None
  624. elif world.maplist[z][on_map].npcs[y][x].AI_style == 'ignore':
  625. s.blit(gra_files.gdic['display'][28],(0,0))
  626. lvl = str(world.maplist[z][on_map].npcs[y][x].lvl)
  627. if len(lvl) == 1:
  628. lvl = '0'+lvl
  629. elif len(lvl) > 2:
  630. lvl = lvl[0]+'+'
  631. s.blit(gra_files.gdic['num'][lvl[0]],(0,6))
  632. s.blit(gra_files.gdic['num'][lvl[1]],(0,14))
  633. elif world.maplist[z][on_map].npcs[y][x].AI_style == 'flee':
  634. s.blit(gra_files.gdic['display'][29],(0,0))
  635. lvl = str(world.maplist[z][on_map].npcs[y][x].lvl)
  636. if len(lvl) == 1:
  637. lvl = '0'+lvl
  638. elif len(lvl) > 2:
  639. lvl = lvl[0]+'+'
  640. s.blit(gra_files.gdic['num'][lvl[0]],(0,6))
  641. s.blit(gra_files.gdic['num'][lvl[1]],(0,14))
  642. else:
  643. s.blit(gra_files.gdic['display'][30],(0,0))
  644. lvl = str(world.maplist[z][on_map].npcs[y][x].lvl)
  645. if len(lvl) == 1:
  646. lvl = '0'+lvl
  647. elif len(lvl) > 2:
  648. lvl = lvl[0]+'+'
  649. s.blit(gra_files.gdic['num'][lvl[0]],(0,6))
  650. s.blit(gra_files.gdic['num'][lvl[1]],(0,14))
  651. else:
  652. if world.maplist[z][on_map].npcs[y][x].techID == ml.mlist['special'][0].techID or world.maplist[z][on_map].npcs[y][x].techID == ml.mlist['special'][1].techID or world.maplist[z][on_map].npcs[y][x].techID == ml.mlist['special'][3].techID or world.maplist[z][on_map].npcs[y][x].name == 'cage':
  653. pos = world.maplist[z][on_map].npcs[y][x].sprite_pos
  654. s.blit(gra_files.gdic['monster'][pos[1]][pos[0]],(0,0))
  655. else:
  656. coin = random.randint(0,1)
  657. if coin == 1:
  658. s.blit(gra_files.gdic['display'][7],(0,0))
  659. else:
  660. s.blit(gra_files.gdic['display'][6],(0,0))
  661. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  662. return s
  663. def generate_light_effect(self):
  664. if player.buffs.berzerk > 0:
  665. y = 3
  666. elif player.buffs.nightvision > 0:
  667. y = 2
  668. elif player.pos[2] > 0:
  669. y = 1
  670. else:
  671. y= 0
  672. x = time.hour
  673. if player.buffs.berzerk > 0:
  674. alpha = 135
  675. elif player.buffs.nightvision > 0:
  676. alpha = 60
  677. elif player.pos[2] == 0:
  678. if time.hour == 12:
  679. alpha = 0
  680. elif time.hour < 12:
  681. alpha = 60-(time.hour*5)
  682. elif time.hour > 12:
  683. alpha = 0+((time.hour-12)*5)
  684. else:
  685. alpha = 135
  686. light_color = gra_files.gdic['lightmap'].get_at((x,y))
  687. s = pygame.Surface((640,360))
  688. s.fill(light_color)
  689. if player.buffs.light > 0 and player.buffs.berzerk == 0:
  690. pygame.draw.circle(s,(255,0,255),[254,197],120,0)
  691. help_tile = pygame.Surface((32,32))
  692. help_tile.fill(light_color)
  693. fov = world.maplist[player.pos[2]][player.on_map].check_fov(player.pos[0],player.pos[1],6)
  694. for y in range(0,len(fov)-1):
  695. for x in range(0,len(fov[y])-1):
  696. if fov[y][x] == 0:
  697. s.blit(help_tile,(x*32,y*32))
  698. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  699. s.set_alpha(alpha)
  700. return s
  701. def render(self,mes_num, simulate = False, photo = False):
  702. radius = 6
  703. if player.pos[2] > 0:
  704. radius = 2
  705. elif player.pos[2] == 0:
  706. if time.hour > 22 or time.hour < 4:
  707. radius = 2
  708. elif time.hour > 21 or time.hour < 5:
  709. radius = 3
  710. elif time.hour > 20 or time.hour < 6:
  711. radius = 4
  712. elif time.hour > 19 or time.hour < 7:
  713. radius = 5
  714. if player.buffs.light > 0 or player.buffs.nightvision:
  715. radius = 6
  716. if player.buffs.blind > 0:
  717. radius = 0
  718. s = pygame.Surface((640,360))
  719. test = message.sget()
  720. s.fill((48,48,48)) #paint it grey(to clear the screen)
  721. start_pos_x = 240 #the center of the main map view
  722. start_pos_y = 180
  723. ymin = player.pos[1]-6
  724. ymax = player.pos[1]+6
  725. xmin = player.pos[0]-8
  726. xmax = player.pos[0]+7
  727. ry = 0
  728. fow = world.maplist[player.pos[2]][player.on_map].check_fov(player.pos[0],player.pos[1],radius)
  729. for y in range(ymin,ymax):
  730. rx = 0
  731. for x in range(xmin,xmax):
  732. s.blit(screen.draw_tile(player.on_map,x,y,player.pos[2],fow[ry][rx]),(rx*32,ry*32))
  733. if x == player.pos[0] and y == player.pos[1]:
  734. s.blit(screen.draw_player(),(rx*32,ry*32))
  735. player_pos_help = (x,y)
  736. rx+=1
  737. ry+=1
  738. s.blit(self.render_hits(),(0,0))
  739. s.blit(screen.generate_light_effect(),(0,0))
  740. if photo == True:
  741. if low_res == False:
  742. photo_help = pygame.Surface((480,360))
  743. photo_help.blit(s,(0,0))
  744. s = photo_help
  745. else:
  746. photo_help = pygame.Surface((320,240))
  747. photo_help.blit(s,(0,0))
  748. s = photo_help
  749. return s
  750. if self.fire_mode == 0:
  751. if (player.lp*100)/player.attribute.max_lp>20 and (player.attribute.hunger*100)/player.attribute.hunger_max>10 and (player.attribute.thirst*100)/player.attribute.thirst_max>10 and (player.attribute.tiredness*100)/player.attribute.tiredness_max>10:
  752. s.blit(gra_files.gdic['display'][0],(0,0)) #render gui
  753. else:
  754. s.blit(gra_files.gdic['display'][25],(0,0)) #render gui_warning
  755. elif self.fire_mode == 1:
  756. s.blit(gra_files.gdic['display'][10],(0,0))
  757. s.blit(gra_files.gdic['display'][41],(start_pos_x+((player_pos_help[0]-player.pos[0])*32)-16,start_pos_y+((player_pos_help[1]-player.pos[1])*32)-16))
  758. else:
  759. if (player.lp*100)/player.attribute.max_lp>20 and (player.attribute.hunger*100)/player.attribute.hunger_max>10 and (player.attribute.thirst*100)/player.attribute.thirst_max>10 and (player.attribute.tiredness*100)/player.attribute.tiredness_max>10:
  760. s.blit(gra_files.gdic['display'][0],(0,0)) #render gui
  761. else:
  762. s.blit(gra_files.gdic['display'][25],(0,0)) #render gui_warning
  763. s.blit(gra_files.gdic['display'][68],(start_pos_x+((player_pos_help[0]-player.pos[0])*32)-16,start_pos_y+((player_pos_help[1]-player.pos[1])*32)-16))
  764. #render tool info
  765. #1. Axe
  766. if player.inventory.wearing['Axe'] == player.inventory.nothing:
  767. s.blit(gra_files.gdic['display'][44],(0,39))
  768. else:
  769. s.blit(gra_files.gdic['display'][46],(0,39))
  770. axestring = 'WEAPONS_' + player.inventory.wearing['Axe'].material + '_' + player.inventory.wearing['Axe'].classe
  771. s.blit(gra_files.gdic['char'][axestring],(0,39))
  772. s.blit(gra_files.gdic['display'][47],(0,39))
  773. axe_state = (15*player.inventory.wearing['Axe'].state)/100
  774. help_sur = pygame.Surface((axe_state,1))
  775. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  776. s.blit(help_sur,(10,67))
  777. #2. Pickaxe
  778. if player.inventory.wearing['Pickaxe'] == player.inventory.nothing:
  779. s.blit(gra_files.gdic['display'][45],(16,39))
  780. else:
  781. s.blit(gra_files.gdic['display'][46],(16,39))
  782. pickaxestring = 'WEAPONS_' + player.inventory.wearing['Pickaxe'].material + '_' + player.inventory.wearing['Pickaxe'].classe
  783. s.blit(gra_files.gdic['char'][pickaxestring],(16,39))
  784. s.blit(gra_files.gdic['display'][47],(16,39))
  785. pickaxe_state = (15*player.inventory.wearing['Pickaxe'].state)/100
  786. help_sur = pygame.Surface((pickaxe_state,1))
  787. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  788. s.blit(help_sur,(26,67))
  789. #3. Melee weapon
  790. if player.inventory.wearing['Hold(R)'] == player.inventory.nothing:
  791. s.blit(gra_files.gdic['display'][52],(32,39))
  792. else:
  793. s.blit(gra_files.gdic['display'][46],(32,39))
  794. melee_string = 'WEAPONS_' + player.inventory.wearing['Hold(R)'].material + '_' + player.inventory.wearing['Hold(R)'].classe
  795. if player.inventory.wearing['Hold(R)'].classe != 'spear':
  796. s.blit(gra_files.gdic['char'][melee_string],(32,39))
  797. else:
  798. h_sur = pygame.Surface((32,19))
  799. h_sur.fill((255,0,255))
  800. h_sur.blit(gra_files.gdic['char'][melee_string],(0,0))
  801. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  802. h_sur = h_sur.convert_alpha()
  803. s.blit(h_sur,(39,48))
  804. s.blit(gra_files.gdic['display'][47],(32,39))
  805. melee_state = (15*player.inventory.wearing['Hold(R)'].state)/100
  806. help_sur = pygame.Surface((melee_state,1))
  807. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  808. s.blit(help_sur,(42,67))
  809. #4. Magic weapon
  810. if player.inventory.wearing['Hold(L)'] == player.inventory.nothing:
  811. s.blit(gra_files.gdic['display'][53],(48,39))
  812. else:
  813. s.blit(gra_files.gdic['display'][46],(48,39))
  814. magic_string = 'WEAPONS_' + player.inventory.wearing['Hold(L)'].material + '_' + player.inventory.wearing['Hold(L)'].classe
  815. if player.inventory.wearing['Hold(L)'].classe != 'rune staff':
  816. s.blit(gra_files.gdic['char'][magic_string],(42,39))
  817. else:
  818. h_sur = pygame.Surface((32,19))
  819. h_sur.fill((255,0,255))
  820. h_sur.blit(gra_files.gdic['char'][magic_string],(0,0))
  821. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  822. h_sur = h_sur.convert_alpha()
  823. s.blit(h_sur,(42,48))
  824. s.blit(gra_files.gdic['display'][47],(48,39))
  825. magic_state = (15*player.inventory.wearing['Hold(L)'].state)/100
  826. help_sur = pygame.Surface((magic_state,1))
  827. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  828. s.blit(help_sur,(58,67))
  829. #5. Necklace
  830. if player.inventory.wearing['Neck'] == player.inventory.nothing:
  831. s.blit(gra_files.gdic['display'][40],(64,39))
  832. else:
  833. s.blit(gra_files.gdic['display'][46],(64,39))
  834. necklacestring = 'WEAPONS_' + player.inventory.wearing['Neck'].material + '_' + player.inventory.wearing['Neck'].classe
  835. s.blit(gra_files.gdic['char'][necklacestring],(64,39))
  836. s.blit(gra_files.gdic['display'][47],(64,39))
  837. necklace_state = (15*player.inventory.wearing['Neck'].state)/100
  838. help_sur = pygame.Surface((necklace_state,1))
  839. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  840. s.blit(help_sur,(74,67))
  841. #6. Helmet
  842. if player.inventory.wearing['Head'] == player.inventory.nothing:
  843. s.blit(gra_files.gdic['display'][54],(0,54))
  844. else:
  845. s.blit(gra_files.gdic['display'][46],(0,54))
  846. helmet_string = player.gender + '_' + player.inventory.wearing['Head'].material + '_' + player.inventory.wearing['Head'].classe
  847. h_sur = pygame.Surface((32,32))
  848. h_sur.fill((255,0,255))
  849. h_sur.blit(gra_files.gdic['char'][helmet_string],(0,0))
  850. pygame.draw.rect(h_sur,(255,0,255),(0,0,10,32),0)
  851. pygame.draw.rect(h_sur,(255,0,255),(0,0,32,4),0)
  852. pygame.draw.rect(h_sur,(255,0,255),(25,0,7,32),0)
  853. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  854. h_sur = h_sur.convert_alpha()
  855. s.blit(h_sur,(0,65))
  856. s.blit(gra_files.gdic['display'][47],(0,54))
  857. helmet_state = (15*player.inventory.wearing['Head'].state)/100
  858. help_sur = pygame.Surface((helmet_state,1))
  859. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  860. s.blit(help_sur,(10,82))
  861. #7. Armor
  862. if player.inventory.wearing['Body'] == player.inventory.nothing:
  863. s.blit(gra_files.gdic['display'][55],(16,54))
  864. else:
  865. s.blit(gra_files.gdic['display'][46],(16,54))
  866. armor_string = player.gender + '_' + player.inventory.wearing['Body'].material + '_' + player.inventory.wearing['Body'].classe
  867. h_sur = pygame.Surface((32,32))
  868. h_sur.fill((255,0,255))
  869. h_sur.blit(gra_files.gdic['char'][armor_string],(0,0))
  870. pygame.draw.rect(h_sur,(255,0,255),(0,0,10,32),0)
  871. pygame.draw.rect(h_sur,(255,0,255),(25,0,7,32),0)
  872. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  873. h_sur = h_sur.convert_alpha()
  874. s.blit(h_sur,(16,55))
  875. s.blit(gra_files.gdic['display'][47],(16,54))
  876. armor_state = (15*player.inventory.wearing['Body'].state)/100
  877. help_sur = pygame.Surface((armor_state,1))
  878. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  879. s.blit(help_sur,(26,82))
  880. #8. Cuisse
  881. if player.inventory.wearing['Legs'] == player.inventory.nothing:
  882. s.blit(gra_files.gdic['display'][56],(32,54))
  883. else:
  884. s.blit(gra_files.gdic['display'][46],(32,54))
  885. cuisse_string = player.gender + '_' + player.inventory.wearing['Legs'].material + '_' + player.inventory.wearing['Legs'].classe
  886. s.blit(gra_files.gdic['char'][cuisse_string],(32,50))
  887. s.blit(gra_files.gdic['display'][47],(32,54))
  888. cuisse_state = (15*player.inventory.wearing['Legs'].state)/100
  889. help_sur = pygame.Surface((cuisse_state,1))
  890. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  891. s.blit(help_sur,(42,82))
  892. #9. Shoes
  893. if player.inventory.wearing['Feet'] == player.inventory.nothing:
  894. s.blit(gra_files.gdic['display'][57],(48,54))
  895. else:
  896. s.blit(gra_files.gdic['display'][46],(48,54))
  897. shoes_string = player.gender + '_' + player.inventory.wearing['Feet'].material + '_' + player.inventory.wearing['Feet'].classe
  898. s.blit(gra_files.gdic['char'][shoes_string],(49,46))
  899. s.blit(gra_files.gdic['display'][47],(48,54))
  900. shoes_state = (15*player.inventory.wearing['Feet'].state)/100
  901. help_sur = pygame.Surface((shoes_state,1))
  902. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  903. s.blit(help_sur,(58,82))
  904. #10. Ring
  905. if player.inventory.wearing['Hand'] == player.inventory.nothing:
  906. s.blit(gra_files.gdic['display'][39],(64,54))
  907. else:
  908. s.blit(gra_files.gdic['display'][46],(64,54))
  909. ring_string = 'WEAPONS_' + player.inventory.wearing['Hand'].material + '_' + player.inventory.wearing['Hand'].classe
  910. s.blit(gra_files.gdic['char'][ring_string],(64,54))
  911. s.blit(gra_files.gdic['display'][47],(64,54))
  912. ring_state = (15*player.inventory.wearing['Hand'].state)/100
  913. help_sur = pygame.Surface((ring_state,1))
  914. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  915. s.blit(help_sur,(74,82))
  916. #render icons
  917. #1. Use
  918. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]][player.pos[0]].use_group == 'None' and world.maplist[player.pos[2]][player.on_map].containers[player.pos[1]][player.pos[0]] == 0:
  919. s.blit(gra_files.gdic['display'][32],(0,161))
  920. s.blit(gra_files.gdic['display'][34],(0,161))
  921. else:
  922. s.blit(gra_files.gdic['display'][31],(0,161))
  923. s.blit(gra_files.gdic['display'][33],(0,161))
  924. use_string = '['+key_name['e']+']action'
  925. use_image1 = self.font.render(use_string,1,(0,0,0))
  926. use_image2 = self.font.render(use_string,1,(255,255,255))
  927. s.blit(use_image1,(36,173))
  928. s.blit(use_image2,(34,173))
  929. #2. Fire
  930. if player.inventory.wearing['Hold(L)'] == player.inventory.nothing:
  931. s.blit(gra_files.gdic['display'][32],(0,129))
  932. s.blit(gra_files.gdic['display'][36],(0,129))
  933. else:
  934. s.blit(gra_files.gdic['display'][31],(0,129))
  935. s.blit(gra_files.gdic['display'][35],(0,129))
  936. if self.fire_mode == False:
  937. fire_string = '['+key_name['f']+']fire'
  938. else:
  939. fire_string = '['+key_name['x']+']cancel'
  940. fire_image1 = self.font.render(fire_string,1,(0,0,0))
  941. fire_image2 = self.font.render(fire_string,1,(255,255,255))
  942. s.blit(fire_image1,(36,141))
  943. s.blit(fire_image2,(34,141))
  944. #4.Focus
  945. s.blit(gra_files.gdic['display'][32],(0,97))#65
  946. try:
  947. focus_state = (32*player.mp/player.attribute.max_mp)
  948. except:
  949. focus_state = 1
  950. help_sur = pygame.Surface((focus_state,32))
  951. help_sur.fill((255,0,255))
  952. help_sur.blit(gra_files.gdic['display'][31],(0,0))
  953. help_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  954. help_sur = help_sur.convert_alpha()
  955. s.blit(help_sur,(0,97))
  956. if player.mp < player.attribute.max_mp:
  957. s.blit(gra_files.gdic['display'][38],(0,97))
  958. focus_string = 'unfocused'
  959. else:
  960. s.blit(gra_files.gdic['display'][37],(0,97))
  961. focus_string = 'focused'
  962. focus_image1 = self.font.render(focus_string,1,(0,0,0))
  963. focus_image2 = self.font.render(focus_string,1,(255,255,255))
  964. s.blit(focus_image1,(36,109))#77
  965. s.blit(focus_image2,(34,109))
  966. # render messages
  967. if low_res == False:
  968. mes_pos_y = 335
  969. else:
  970. mes_pos_y = 225
  971. mlist = test
  972. for c in range(0,5):
  973. shadow_image = self.font.render(mlist[c],1,(0,0,0))
  974. text_image = self.font.render(mlist[c],1,(255,255,255))
  975. s.blit(shadow_image,(2,mes_pos_y-(c*10)))
  976. s.blit(text_image,(0,mes_pos_y-(c*10)))
  977. #render lvl info
  978. lvl_string = str(player.lvl)
  979. if len(lvl_string) == 1:
  980. lvl_string = '0'+lvl_string
  981. lvl_image = self.font.render(lvl_string,1,(255,255,255))
  982. s.blit(lvl_image,(153,48))
  983. bar_length = 1 + ((319/100)*player.xp)
  984. xp_surface = pygame.Surface((bar_length,64))
  985. xp_surface.fill((255,0,255))
  986. xp_surface.blit(gra_files.gdic['display'][19],(0,0))
  987. xp_surface.set_colorkey((255,0,255),pygame.RLEACCEL)
  988. xp_surface = xp_surface.convert_alpha()
  989. s.blit(xp_surface,(0,0))
  990. if game_options.mousepad == 1:
  991. if self.fire_mode == 0:
  992. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  993. else:
  994. s.blit(gra_files.gdic['display'][9],(480,0))
  995. else:
  996. s_help = pygame.Surface((160,360))
  997. s_help.fill((48,48,48))
  998. s.blit(s_help,(480,0))
  999. #render buffs
  1000. buffs = player.buffs.sget()
  1001. if low_res == False:
  1002. posx = 388
  1003. posy = 10
  1004. else:
  1005. posx = 228
  1006. posy = 75
  1007. for i in buffs:
  1008. if i != ' ':
  1009. buff_shadow = self.font.render(i,1,(0,0,0))
  1010. s.blit(buff_shadow,(posx+2,posy))
  1011. buff_image = self.font.render(i,1,(200,200,200))
  1012. s.blit(buff_image,(posx,posy))
  1013. else:
  1014. None
  1015. posy += 20
  1016. #render date
  1017. date_string = time.sget()
  1018. posx = 235
  1019. posy = 10
  1020. date_image = self.font.render(date_string[0],1,(0,0,0))
  1021. s.blit(date_image,(posx,posy))
  1022. posy = 20
  1023. time_image = self.font.render(date_string[1],1,(0,0,0))
  1024. s.blit(time_image,(posx,posy))
  1025. #render player info
  1026. #lp
  1027. lp_string = str(player.lp) + '/' + str(player.attribute.max_lp)
  1028. posx = 13
  1029. posy = 12
  1030. if player.lp < 4:
  1031. lp_image = self.font.render(lp_string,1,(200,0,0))
  1032. else:
  1033. lp_image = self.font.render(lp_string,1,(0,0,0))
  1034. s.blit(lp_image,(posx,posy))
  1035. #hunger
  1036. hunger_percent = int((100 * player.attribute.hunger) / player.attribute.hunger_max)
  1037. hunger_string = str(hunger_percent) + '%'
  1038. posx = 75
  1039. posy = 12
  1040. if hunger_percent < 11:
  1041. hunger_image = self.font.render(hunger_string,1,(200,0,0))
  1042. else:
  1043. hunger_image = self.font.render(hunger_string,1,(0,0,0))
  1044. s.blit(hunger_image,(posx,posy))
  1045. #trirst
  1046. thirst_percent = int((100 * player.attribute.thirst) / player.attribute.thirst_max)
  1047. thirst_string = str(thirst_percent) + '%'
  1048. posx = 125
  1049. posy = 12
  1050. if thirst_percent < 11:
  1051. thirst_image = self.font.render(thirst_string,1,(200,0,0))
  1052. else:
  1053. thirst_image = self.font.render(thirst_string,1,(0,0,0))
  1054. s.blit(thirst_image,(posx,posy))
  1055. #tiredness
  1056. tiredness_percent = int((100 * player.attribute.tiredness) / player.attribute.tiredness_max)
  1057. tiredness_string = str(tiredness_percent) + '%'
  1058. posx = 180
  1059. posy = 12
  1060. if tiredness_percent < 11:
  1061. tiredness_image = self.font.render(tiredness_string,1,(200,0,0))
  1062. else:
  1063. tiredness_image = self.font.render(tiredness_string,1,(0,0,0))
  1064. s.blit(tiredness_image,(posx,posy))
  1065. if game_options.mousepad == 0:
  1066. s_help = pygame.Surface((640,360))
  1067. s_help.fill((48,48,48))
  1068. s_help.blit(s,(80,0))
  1069. s = s_help
  1070. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1071. self.screen.blit(s,(0,0))
  1072. if simulate == False:
  1073. pygame.display.flip()
  1074. else:
  1075. return s
  1076. if test[1] == '~*~':
  1077. return True
  1078. else:
  1079. return False
  1080. def render_load(self,num,progress=None):
  1081. s = pygame.Surface((640,360))
  1082. s.fill((48,48,48)) #paint it grey(to clear the screen)
  1083. if num == 0:
  1084. string = 'Looking for saved data... '
  1085. elif num == 1:
  1086. string = 'Loading world data...'
  1087. elif num == 2:
  1088. string = 'Nothing found...'
  1089. elif num == 3:
  1090. string = 'Generate overworld...'
  1091. elif num == 4:
  1092. string = 'Generate caves...'
  1093. elif num == 5:
  1094. string = 'Saving...'
  1095. elif num == 6:
  1096. string = 'Loading time data...'
  1097. elif num == 7:
  1098. string = 'Loading player data...'
  1099. elif num == 8:
  1100. string = 'Set time...'
  1101. elif num == 9:
  1102. string = 'Generate player...'
  1103. elif num == 10:
  1104. string = 'Making time related changes...'
  1105. elif num == 11:
  1106. string = 'Something has gone wrong...'
  1107. elif num == 12:
  1108. string = 'Zzzzzzzzzz'
  1109. elif num == 13:
  1110. string = 'Generate deus ex machina...'
  1111. elif num == 14:
  1112. string = 'Loading deus ex machina...'
  1113. elif num == 15:
  1114. string = 'Generate grot...'
  1115. elif num == 16:
  1116. string = 'Generate elfish fortress...'
  1117. elif num == 17:
  1118. string = 'Generate orcish mines...'
  1119. elif num == 18:
  1120. string = 'Generate desert...'
  1121. elif num == 19:
  1122. string = 'Initialize level...'
  1123. elif num == 20:
  1124. string = 'Please use run.py/run.exe'
  1125. ######add more here
  1126. if low_res == False:
  1127. posx = 150
  1128. posy = 200
  1129. else:
  1130. posx=50
  1131. posy= 100
  1132. image = self.font.render(string,1,(255,255,255))
  1133. s.blit(image,(posx,posy))
  1134. if progress != None:
  1135. s.blit(gra_files.gdic['display'][20],(posx-50,posy+20))
  1136. help_sur = pygame.Surface((((progress*320)/100),12))
  1137. help_sur.fill((255,0,255))
  1138. help_sur.blit(gra_files.gdic['display'][21],(0,0))
  1139. help_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  1140. help_sur = help_sur.convert_alpha()
  1141. s.blit(help_sur,(posx-50,posy+20))
  1142. if low_res == False:
  1143. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1144. self.screen.blit(s,(0,0))
  1145. pygame.display.flip()
  1146. def render_built(self,xmin,xmax,ymin,ymax,style):
  1147. start_pos_x = 256 #the center of the main map view
  1148. start_pos_y = 192
  1149. price = 0
  1150. self.render(0, False)
  1151. s = pygame.Surface((640,360))
  1152. s.fill((255,0,255))
  1153. if style == 'wall':
  1154. for y in range (-ymin,ymax+1):
  1155. for x in range (-xmin,xmax+1):
  1156. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].move_group == 'soil' and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].damage == False and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == False and world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+y][player.pos[0]+x] == 0:
  1157. built_here = 1
  1158. price += 2
  1159. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == True:
  1160. built_here = 2
  1161. price += 1
  1162. else:
  1163. built_here = 0
  1164. if world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+y][player.pos[0]+x] != 0:
  1165. built_here = False
  1166. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].build_here == False:
  1167. if built_here == 1:
  1168. price -= 2
  1169. elif built_here == 2:
  1170. price -= 1
  1171. built_here = 0
  1172. if built_here != 0:
  1173. if x == xmax or x == -xmin or y == ymax or y == -ymin:
  1174. if x == xmax or x == -xmin:
  1175. if built_here == 1:
  1176. s.blit(gra_files.gdic['built'][1],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_true here
  1177. elif built_here == 2:
  1178. s.blit(gra_files.gdic['built'][6],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_over here
  1179. if y == ymax or y == -ymin:
  1180. if built_here == 1:
  1181. s.blit(gra_files.gdic['built'][1],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_true here
  1182. elif built_here == 2:
  1183. s.blit(gra_files.gdic['built'][6],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_over here
  1184. else:
  1185. None
  1186. else:
  1187. if x == xmax or x == -xmin or y == ymax or y == -ymin:
  1188. if x == xmax or x == -xmin:
  1189. s.blit(gra_files.gdic['built'][0],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_false here
  1190. if y == ymax or y == -ymin:
  1191. s.blit(gra_files.gdic['built'][0],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_false here
  1192. else:
  1193. None
  1194. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1195. # render mode name
  1196. name = '~Build Walls~'
  1197. name_image = self.font.render(name,1,(255,255,255))
  1198. posx = 0
  1199. posy = 0
  1200. s.blit(name_image,(posx,posy))
  1201. # render wood needed
  1202. wood_need = int(price/3)
  1203. if wood_need == 0:
  1204. wood_need = 1
  1205. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1206. posx = 0
  1207. posy = 15
  1208. if wood_need <= player.inventory.materials.wood:
  1209. wood_image = self.font.render(wood_string,1,(255,255,255))
  1210. else:
  1211. wood_image = self.font.render(wood_string,1,(200,0,0))
  1212. s.blit(wood_image,(posx,posy))
  1213. # render stone needed
  1214. stone_need = int(price/2)
  1215. if stone_need == 0:
  1216. stone_need = 1
  1217. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1218. posx = 160
  1219. posy = 15
  1220. if stone_need <= player.inventory.materials.stone:
  1221. stone_image = self.font.render(stone_string,1,(255,255,255))
  1222. else:
  1223. stone_image = self.font.render(stone_string,1,(200,0,0))
  1224. s.blit(stone_image,(posx,posy))
  1225. # render info line
  1226. info_string_0 = '['+key_name['wasd']+']ch. Size ['+key_name['b']+']ch. Mode'
  1227. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1228. posx = 0
  1229. posy = 30
  1230. info_image = self.font.render(info_string_0,1,(255,255,255))
  1231. s.blit(info_image,(posx,posy))
  1232. posx = 0
  1233. posy = 40
  1234. info_image = self.font.render(info_string_1,1,(255,255,255))
  1235. s.blit(info_image,(posx,posy))
  1236. elif style == 'floor':
  1237. for y in range (-ymin,ymax+1):
  1238. for x in range (-xmin,xmax+1):
  1239. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].move_group == 'soil' and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].damage == False and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == False:
  1240. built_here = 1
  1241. price += 2
  1242. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == True:
  1243. built_here = 2
  1244. price += 1
  1245. else:
  1246. built_here = 0
  1247. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].build_here == False:
  1248. if built_here == 1:
  1249. price -= 2
  1250. elif built_here == 2:
  1251. price -= 1
  1252. built_here = 0
  1253. if built_here != 0:
  1254. if built_here == 1:
  1255. s.blit(gra_files.gdic['built'][5],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_true here
  1256. elif built_here == 2:
  1257. s.blit(gra_files.gdic['built'][7],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_over
  1258. else:
  1259. s.blit(gra_files.gdic['built'][4],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_false here
  1260. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1261. # render mode name
  1262. name = '~Build Floor~'
  1263. name_image = self.font.render(name,1,(255,255,255))
  1264. posx = 0
  1265. posy = 0
  1266. s.blit(name_image,(posx,posy))
  1267. # render wood needed
  1268. wood_need = int(price/2)
  1269. if wood_need == 0:
  1270. wood_need = 1
  1271. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1272. posx = 0
  1273. posy = 15
  1274. if wood_need <= player.inventory.materials.wood:
  1275. wood_image = self.font.render(wood_string,1,(255,255,255))
  1276. else:
  1277. wood_image = self.font.render(wood_string,1,(200,0,0))
  1278. s.blit(wood_image,(posx,posy))
  1279. # render stone needed
  1280. stone_need = int(price/3)
  1281. if stone_need == 0:
  1282. stone_need = 1
  1283. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1284. posx = 160
  1285. posy = 15
  1286. if stone_need <= player.inventory.materials.stone:
  1287. stone_image = self.font.render(stone_string,1,(255,255,255))
  1288. else:
  1289. stone_image = self.font.render(stone_string,1,(200,0,0))
  1290. s.blit(stone_image,(posx,posy))
  1291. # render info line
  1292. info_string_0 = '['+key_name['wasd']+']ch. Size ['+key_name['b']+']ch. Mode'
  1293. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1294. posx = 0
  1295. posy = 30
  1296. info_image = self.font.render(info_string_0,1,(255,255,255))
  1297. s.blit(info_image,(posx,posy))
  1298. posx = 0
  1299. posy = 40
  1300. info_image = self.font.render(info_string_1,1,(255,255,255))
  1301. s.blit(info_image,(posx,posy))
  1302. elif style == 'Door':
  1303. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].move_group == 'soil' and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].damage == False and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].civilisation == False and world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+ymin][player.pos[0]+xmin] == 0:
  1304. built_here = 1
  1305. price += 2
  1306. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].civilisation == True:
  1307. built_here = 2
  1308. price += 1
  1309. else:
  1310. built_here = 0
  1311. if world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+ymin][player.pos[0]+xmin] != 0:
  1312. built_here = False
  1313. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].build_here == False:
  1314. if built_here == 1:
  1315. price -= 2
  1316. elif built_here == 2:
  1317. price -= 1
  1318. built_here = 0
  1319. if built_here != 0:
  1320. if built_here == 1:
  1321. s.blit(gra_files.gdic['built'][3],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_true here
  1322. elif built_here == 2:
  1323. s.blit(gra_files.gdic['built'][8],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_over
  1324. else:
  1325. s.blit(gra_files.gdic['built'][2],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_false here
  1326. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1327. # render mode name
  1328. name = '~Built Door~'
  1329. name_image = self.font.render(name,1,(255,255,255))
  1330. posx = 0
  1331. posy = 0
  1332. s.blit(name_image,(posx,posy))
  1333. # render wood needed
  1334. wood_need = price
  1335. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1336. posx = 0
  1337. posy = 15
  1338. if wood_need <= player.inventory.materials.wood:
  1339. wood_image = self.font.render(wood_string,1,(255,255,255))
  1340. else:
  1341. wood_image = self.font.render(wood_string,1,(200,0,0))
  1342. s.blit(wood_image,(posx,posy))
  1343. # render stone needed
  1344. stone_need = 0
  1345. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1346. posx = 160
  1347. posy = 15
  1348. if stone_need <= player.inventory.materials.stone:
  1349. stone_image = self.font.render(stone_string,1,(255,255,255))
  1350. else:
  1351. stone_image = self.font.render(stone_string,1,(200,0,0))
  1352. s.blit(stone_image,(posx,posy))
  1353. # render info line
  1354. info_string_0 = '['+key_name['wasd']+']ch. Pos. ['+key_name['b']+']ch. Mode'
  1355. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1356. posx = 0
  1357. posy = 30
  1358. info_image = self.font.render(info_string_0,1,(255,255,255))
  1359. s.blit(info_image,(posx,posy))
  1360. posx = 0
  1361. posy = 40
  1362. info_image = self.font.render(info_string_1,1,(255,255,255))
  1363. s.blit(info_image,(posx,posy))
  1364. pygame.display.flip()
  1365. elif style == 'Stair up':
  1366. if player.pos[2] > 0:
  1367. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].replace == None and world.maplist[player.pos[2]-1][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].build_here == True and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].build_here == True and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].move_group == 'soil' and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].damage == False:
  1368. build_here = 0
  1369. else:
  1370. build_here = 1
  1371. if build_here == 0:
  1372. s.blit(gra_files.gdic['built'][10],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up true icon here
  1373. else:
  1374. s.blit(gra_files.gdic['built'][11],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1375. else:
  1376. s.blit(gra_files.gdic['built'][11],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1377. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1378. # render mode name
  1379. name = '~Built stair up~'
  1380. name_image = self.font.render(name,1,(255,255,255))
  1381. posx = 0
  1382. posy = 0
  1383. s.blit(name_image,(posx,posy))
  1384. # render wood needed
  1385. wood_need = 10
  1386. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1387. posx = 0
  1388. posy = 15
  1389. if wood_need <= player.inventory.materials.wood:
  1390. wood_image = self.font.render(wood_string,1,(255,255,255))
  1391. else:
  1392. wood_image = self.font.render(wood_string,1,(200,0,0))
  1393. s.blit(wood_image,(posx,posy))
  1394. # render stone needed
  1395. stone_need = 40
  1396. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1397. posx = 160
  1398. posy = 15
  1399. if stone_need <= player.inventory.materials.stone:
  1400. stone_image = self.font.render(stone_string,1,(255,255,255))
  1401. else:
  1402. stone_image = self.font.render(stone_string,1,(200,0,0))
  1403. s.blit(stone_image,(posx,posy))
  1404. # render info line
  1405. info_string_0 = '['+key_name['wasd']+']ch. Pos. ['+key_name['b']+']ch. Mode'
  1406. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1407. posx = 0
  1408. posy = 30
  1409. info_image = self.font.render(info_string_0,1,(255,255,255))
  1410. s.blit(info_image,(posx,posy))
  1411. posx = 0
  1412. posy = 40
  1413. info_image = self.font.render(info_string_1,1,(255,255,255))
  1414. s.blit(info_image,(posx,posy))
  1415. pygame.display.flip()
  1416. elif style == 'Stair down':
  1417. if player.pos[2] < 15:
  1418. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].replace == None and world.maplist[player.pos[2]+1][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].build_here == True and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].build_here == True and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].move_group == 'soil' and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].damage == False:
  1419. build_here = 0
  1420. else:
  1421. build_here = 1
  1422. if build_here == 0:
  1423. s.blit(gra_files.gdic['built'][12],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up true icon here
  1424. else:
  1425. s.blit(gra_files.gdic['built'][13],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1426. else:
  1427. s.blit(gra_files.gdic['built'][12],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1428. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1429. # render mode name
  1430. name = '~Built stair down~'
  1431. name_image = self.font.render(name,1,(255,255,255))
  1432. posx = 0
  1433. posy = 0
  1434. s.blit(name_image,(posx,posy))
  1435. # render wood needed
  1436. wood_need = 10
  1437. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1438. posx = 0
  1439. posy = 15
  1440. if wood_need <= player.inventory.materials.wood:
  1441. wood_image = self.font.render(wood_string,1,(255,255,255))
  1442. else:
  1443. wood_image = self.font.render(wood_string,1,(200,0,0))
  1444. s.blit(wood_image,(posx,posy))
  1445. # render stone needed
  1446. if player.pos[2] > 0:
  1447. stone_need = 40
  1448. else:
  1449. stone_need = 15
  1450. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1451. posx = 160
  1452. posy = 15
  1453. if stone_need <= player.inventory.materials.stone:
  1454. stone_image = self.font.render(stone_string,1,(255,255,255))
  1455. else:
  1456. stone_image = self.font.render(stone_string,1,(200,0,0))
  1457. s.blit(stone_image,(posx,posy))
  1458. # render info line
  1459. info_string_0 = '['+key_name['wasd']+']ch. Pos. ['+key_name['b']+']ch. Mode'
  1460. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1461. posx = 0
  1462. posy = 30
  1463. info_image = self.font.render(info_string_0,1,(255,255,255))
  1464. s.blit(info_image,(posx,posy))
  1465. posx = 0
  1466. posy = 40
  1467. info_image = self.font.render(info_string_1,1,(255,255,255))
  1468. s.blit(info_image,(posx,posy))
  1469. pygame.display.flip()
  1470. elif style == 'Agriculture':
  1471. for y in range (-ymin,ymax+1):
  1472. for x in range (-xmin,xmax+1):
  1473. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].move_group == 'soil' and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].damage == False and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == False:
  1474. built_here = 1
  1475. price += 1
  1476. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == True:
  1477. built_here = 2
  1478. price += 1
  1479. else:
  1480. built_here = 0
  1481. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].build_here == False:
  1482. if built_here == 1:
  1483. price -= 2
  1484. elif built_here == 2:
  1485. price -= 1
  1486. built_here = 0
  1487. if built_here != 0:
  1488. if built_here == 1:
  1489. s.blit(gra_files.gdic['built'][15],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_true here
  1490. elif built_here == 2:
  1491. s.blit(gra_files.gdic['built'][16],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_over
  1492. else:
  1493. s.blit(gra_files.gdic['built'][14],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_false here
  1494. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1495. # render mode name
  1496. name = '~Build Agriculture~'
  1497. name_image = self.font.render(name,1,(255,255,255))
  1498. posx = 0
  1499. posy = 0
  1500. s.blit(name_image,(posx,posy))
  1501. # render seeds needed
  1502. seed_need = price
  1503. if seed_need == 0:
  1504. seed_need = 1
  1505. wood_need = seed_need
  1506. stone_need = 0
  1507. wood_string = 'Seeds: ' + str(seed_need) + '(' + str(player.inventory.materials.seeds) + ')'
  1508. posx = 120
  1509. posy = 15
  1510. if wood_need <= player.inventory.materials.wood:
  1511. wood_image = self.font.render(wood_string,1,(255,255,255))
  1512. else:
  1513. wood_image = self.font.render(wood_string,1,(200,0,0))
  1514. s.blit(wood_image,(posx,posy))
  1515. # render info line
  1516. info_string_0 = '['+key_name['wasd']+']ch. Size ['+key_name['b']+']ch. Mode'
  1517. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1518. posx = 0
  1519. posy = 30
  1520. info_image = self.font.render(info_string_0,1,(255,255,255))
  1521. s.blit(info_image,(posx,posy))
  1522. posx = 0
  1523. posy = 40
  1524. info_image = self.font.render(info_string_1,1,(255,255,255))
  1525. s.blit(info_image,(posx,posy))
  1526. elif style == 'remove':
  1527. for y in range (-ymin,ymax+1):
  1528. for x in range (-xmin,xmax+1):
  1529. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == True and world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].build_here == True:
  1530. remove_here = 0
  1531. else:
  1532. remove_here = 1
  1533. if remove_here == 0:
  1534. s.blit(gra_files.gdic['built'][9],(start_pos_x+(x*32),start_pos_y+(y*32))) #remove icon here
  1535. else:
  1536. None
  1537. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1538. # render mode name
  1539. name = '~Remove~'
  1540. name_image = self.font.render(name,1,(255,255,255))
  1541. posx = 0
  1542. posy = 0
  1543. s.blit(name_image,(posx,posy))
  1544. # render ---
  1545. wood_string = '---'
  1546. posx = 120
  1547. posy = 15
  1548. wood_image = self.font.render(wood_string,1,(255,255,255))
  1549. s.blit(wood_image,(posx,posy))
  1550. # render info line
  1551. info_string_0 = '['+key_name['wasd']+']ch. Size ['+key_name['b']+']ch. Mode'
  1552. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']REMOVE!'
  1553. posx = 0
  1554. posy = 30
  1555. info_image = self.font.render(info_string_0,1,(255,255,255))
  1556. s.blit(info_image,(posx,posy))
  1557. posx = 0
  1558. posy = 40
  1559. info_image = self.font.render(info_string_1,1,(255,255,255))
  1560. s.blit(info_image,(posx,posy))
  1561. wood_need = 0
  1562. stone_need = 0
  1563. if game_options.mousepad == 0 and low_res == False:
  1564. s_help = pygame.Surface((640,360))
  1565. s_help.fill((255,0,255))
  1566. s_help.blit(s,(80,0))
  1567. s = s_help
  1568. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  1569. s = s.convert_alpha()
  1570. if low_res == False:
  1571. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1572. self.screen.blit(s,(0,0))
  1573. pygame.display.flip()
  1574. return (wood_need,stone_need)
  1575. def render_place(self,tile,use_name):
  1576. global player
  1577. x = player.pos[0]
  1578. y = player.pos[1]
  1579. start_pos_x = 256 #the center of the main map view
  1580. start_pos_y = 192
  1581. run = True
  1582. while run:
  1583. lootable = False
  1584. placeable = True
  1585. plantable = False
  1586. #1: check if lootable
  1587. for i in range(9,14):
  1588. if tile.techID == tl.tlist['functional'][i].techID:#this is a workbench
  1589. lootable = True
  1590. if tile.use_group == 'gather':
  1591. lootable = True
  1592. #2: check if placeable
  1593. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].move_group != 'soil':
  1594. placeable = False
  1595. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].replace != None:
  1596. placeable = False
  1597. if world.maplist[player.pos[2]][player.on_map].npcs[y][x] != 0:
  1598. placeable = False
  1599. if tile.move_group != 'soil':
  1600. if x == player.pos[0] and y == player.pos[1]:
  1601. placeable = False
  1602. #2.5: check if plantable
  1603. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].can_grown == True:
  1604. plantable = True
  1605. if use_name != 'plant':
  1606. plantable = True #if the object to be placeced no plant plantable is always true
  1607. #3: render
  1608. self.render(0,True)
  1609. s = pygame.Surface((640,360))
  1610. s.fill((255,0,255))
  1611. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1612. string1 ='~'+tile.name+'~'
  1613. string1_image = self.font.render(string1,1,(255,255,255))
  1614. s.blit(string1_image,(0,0))
  1615. if lootable == False:
  1616. warning = self.font.render('Can\'t be moved later!',1,(200,0,0))
  1617. s.blit(warning,(0,20))
  1618. string2 = '['+key_name['wasd']+']Move ['+key_name['e']+']Place! ['+key_name['x']+']Leave'
  1619. string2_image = self.font.render(string2,1,(255,255,255))
  1620. s.blit(string2_image,(0,40))
  1621. xx = x - player.pos[0]
  1622. yy = y - player.pos[1]
  1623. if placeable == True and plantable == True:
  1624. s.blit(gra_files.gdic['built'][18],(start_pos_x+(xx*32),start_pos_y+(yy*32)))
  1625. else:
  1626. s.blit(gra_files.gdic['built'][17],(start_pos_x+(xx*32),start_pos_y+(yy*32)))
  1627. if game_options.mousepad == 0:
  1628. s_help = pygame.Surface((640,360))
  1629. s_help.fill((255,0,255))
  1630. s_help.blit(s,(80,0))
  1631. s = s_help
  1632. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  1633. s = s.convert_alpha()
  1634. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1635. self.screen.blit(s,(0,0))
  1636. pygame.display.flip()
  1637. #4: user input
  1638. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  1639. if ui == 'exit':
  1640. global master_loop
  1641. global playing
  1642. global exitgame
  1643. exitgame = True
  1644. try:
  1645. save_options(game_options,options_path,os.sep)
  1646. screen.render_load(5)
  1647. save(world,player,time,gods,save_path,os.sep)
  1648. screen.save_tmp_png()
  1649. del player
  1650. except:
  1651. None
  1652. master_loop = False
  1653. playing = False
  1654. run = False
  1655. return('exit')
  1656. if ui == 'w':
  1657. if y > 0 and y > player.pos[1]-2:
  1658. y -= 1
  1659. elif ui == 's':
  1660. if y < max_map_size-1 and y < player.pos[1]+2:
  1661. y += 1
  1662. elif ui == 'a':
  1663. if x > 0 and x > player.pos[0]-2:
  1664. x -= 1
  1665. elif ui == 'd':
  1666. if x < max_map_size-1 and x < player.pos[0]+2:
  1667. x += 1
  1668. elif ui == 'e':
  1669. if placeable == True and plantable == True:
  1670. replace = world.maplist[player.pos[2]][player.on_map].tilemap[y][x]
  1671. world.maplist[player.pos[2]][player.on_map].tilemap[y][x] = deepcopy(tile)
  1672. world.maplist[player.pos[2]][player.on_map].tilemap[y][x].replace = deepcopy(replace)
  1673. world.maplist[player.pos[2]][player.on_map].tilemap[y][x].civilisation = True
  1674. if use_name == 'plant':
  1675. mes = 'You planted a '+tile.name+'.'
  1676. else:
  1677. mes = 'You placed a '+tile.name+'.'
  1678. message.add(mes)
  1679. return(x,y)
  1680. elif ui == 'x':
  1681. run = False
  1682. return False
  1683. return False#only to be sure
  1684. def render_request(self,line1,line2,line3):
  1685. #this function just renders 3 lines of text in the textbox
  1686. self.render(0, True)
  1687. if low_res == False:
  1688. s = pygame.Surface((640,360))
  1689. else:
  1690. s = pygame.Surface((320,240))
  1691. s.fill((255,0,255))
  1692. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1693. # render lines
  1694. line1_image = self.font.render(line1,1,(255,255,255))
  1695. posx = 0
  1696. posy = 0
  1697. s.blit(line1_image,(posx,posy))
  1698. line2_image = self.font.render(line2,1,(255,255,255))
  1699. posx = 0
  1700. posy = 20
  1701. s.blit(line2_image,(posx,posy))
  1702. line3_image = self.font.render(line3,1,(255,255,255))
  1703. posx = 0
  1704. posy = 40
  1705. s.blit(line3_image,(posx,posy))
  1706. if game_options.mousepad == 0 and low_res == False:
  1707. s_help = pygame.Surface((640,360))
  1708. s_help.fill((255,0,255))
  1709. s_help.blit(s,(80,0))
  1710. s = s_help
  1711. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  1712. s = s.convert_alpha()
  1713. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1714. self.screen.blit(s,(0,0))
  1715. pygame.display.flip()
  1716. def render_map(self,level=0):
  1717. run = True
  1718. while run:
  1719. m = pygame.Surface((max_map_size,max_map_size))
  1720. for y in range(0,max_map_size):
  1721. for x in range(0,max_map_size):
  1722. try:
  1723. t_col = world.maplist[level][player.on_map].tilemap[y][x].tile_color
  1724. except:
  1725. level = 0
  1726. t_col = world.maplist[level][player.on_map].tilemap[y][x].tile_color
  1727. if x > player.pos[0]-2 and x < player.pos[0]+2 and y > player.pos[1]-2 and y < player.pos[1]+2 and level == player.pos[2]: #mark players pos
  1728. m.blit(gra_files.gdic['tile1']['white'],(x,y))
  1729. else:
  1730. if world.maplist[level][player.on_map].known[y][x] == 1:
  1731. m.blit(gra_files.gdic['tile1'][t_col],(x,y))
  1732. elif world.maplist[level][player.on_map].known[y][x] == 0:
  1733. m.blit(gra_files.gdic['tile1']['black'],(x,y))
  1734. else:
  1735. m.blit(gra_files.gdic['tile1']['black'],(x,y))
  1736. m = pygame.transform.scale(m,(270,270))
  1737. s = pygame.Surface((640,360))
  1738. bg = pygame.Surface((480,360))
  1739. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  1740. s.blit(bg,(0,0))
  1741. if game_options.mousepad == 1:
  1742. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  1743. else:
  1744. s_help = pygame.Surface((160,360))
  1745. s_help.fill((48,48,48))
  1746. s.blit(s_help,(480,0))
  1747. text = '~Map~ [Press['+key_name['x']+'] to leave'
  1748. text_image = screen.font.render(text,1,(255,255,255))
  1749. s.blit(text_image,(5,2))#menue title
  1750. lvl_string = 'Level ' + str(level)
  1751. text_image = screen.font.render(lvl_string,1,(0,0,0))
  1752. if low_res == False:
  1753. s.blit(text_image,(300,70))
  1754. else:
  1755. s.blit(text_image,(190,50))
  1756. s.blit(m,(25,55))
  1757. if game_options.mousepad == 0:
  1758. s_help = pygame.Surface((640,360))
  1759. s_help.fill((48,48,48))
  1760. s_help.blit(s,(80,0))
  1761. s = s_help
  1762. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1763. self.screen.blit(s,(0,0))
  1764. pygame.display.flip()
  1765. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  1766. if ui == 'exit':
  1767. global master_loop
  1768. global playing
  1769. global exitgame
  1770. exitgame = True
  1771. screen.render_load(5)
  1772. save(world,player,time,gods,save_path,os.sep)
  1773. screen.save_tmp_png()
  1774. master_loop = False
  1775. playing = False
  1776. run = False
  1777. return('exit')
  1778. if ui == 'x':
  1779. run = False
  1780. def render_credits(self):
  1781. global master_loop
  1782. run = True
  1783. while run:
  1784. s = pygame.Surface((640,360))
  1785. bg = pygame.Surface((480,360))
  1786. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  1787. s.blit(bg,(0,0))
  1788. if game_options.mousepad == 1 and low_res == False:
  1789. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  1790. else:
  1791. s_help = pygame.Surface((160,360))
  1792. s_help.fill((48,48,48))
  1793. s.blit(s_help,(480,0))
  1794. text = '~Credits~ [Press ['+key_name['x']+'] to leave]'
  1795. text_image = screen.font.render(text,1,(255,255,255))
  1796. s.blit(text_image,(5,2))#menue title
  1797. credit_items = ('Code & Art: The Mighty Glider', 'BGM: Various Artists [CC0]' , 'SFX: Various Artists [CC0]', 'Font: Cody Boisclair', 'Testing: eugeneloza', 'Special Thanks: forum.freegamedev.net', ' !freegaming@quitter.se')
  1798. for i in range (0,len(credit_items)):
  1799. text_image = screen.font.render(credit_items[i],1,(0,0,0))
  1800. s.blit(text_image,(21,120+i*25))#blit credit_items
  1801. if game_options.mousepad == 0:
  1802. s_help = pygame.Surface((640,360))
  1803. s_help.fill((48,48,48))
  1804. s_help.blit(s,(80,0))
  1805. s = s_help
  1806. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1807. self.screen.blit(s,(0,0))
  1808. pygame.display.flip()
  1809. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  1810. if ui == 'exit':
  1811. master_loop = False
  1812. run = False
  1813. return('exit')
  1814. if ui == 'x':
  1815. run = False
  1816. def render_status(self):
  1817. player_attribute = ('Strength: '+str(player.attribute.p_strength),
  1818. 'Skill: '+str(player.attribute.p_defense),
  1819. 'Power: '+str(player.attribute.m_strength),
  1820. 'Will: '+str(player.attribute.m_defense),
  1821. 'Health: '+str(player.lp)+'/'+str(player.attribute.max_lp),
  1822. '--> SKILLS')
  1823. attribute_info = ('Strength','Skill','Power','Will','Health')
  1824. if player.skill.woodcutting == 'Novice':
  1825. woodcutting_next_lvl = '200'
  1826. else:
  1827. woodcutting_next_lvl = '1000'
  1828. if player.skill.mining == 'Novice':
  1829. mining_next_lvl = '200'
  1830. else:
  1831. mining_next_lvl = '1000'
  1832. player_skills = ('Weapon Crafting: '+player.skill.weapon_crafting,
  1833. 'Metallurgy: '+player.skill.metallurgy,
  1834. 'Alchemy: '+player.skill.alchemy,
  1835. 'Woodcutting: '+player.skill.woodcutting+' ('+str(player.skill.woodcutting_progress)+'/'+woodcutting_next_lvl+')',
  1836. 'Mining: '+player.skill.mining+' ('+str(player.skill.mining_progress)+'/'+mining_next_lvl+')',
  1837. '<-- ATTRIBUTE')
  1838. skill_info = ('Weapon Crafting','Metallurgy','Alchemy','Woodcutting','Mining')
  1839. run = True
  1840. while run:
  1841. c = screen.get_choice('Attributes',player_attribute,True)
  1842. if c == 'Break':
  1843. run = False
  1844. return False
  1845. if c < 5:
  1846. screen.render_text(texts[attribute_info[c]])
  1847. elif c == 5:
  1848. run2 = True
  1849. while run2:
  1850. d = screen.get_choice('Skills',player_skills,True)
  1851. if d == 'Break':
  1852. run = False
  1853. run2 = False
  1854. return False
  1855. if d < 5:
  1856. screen.render_text(texts[skill_info[d]])
  1857. elif d == 5:
  1858. run2 = False
  1859. def render_text(self,text,replace_keys=True,more_txt=False,simulation= False):
  1860. run = True
  1861. while run:
  1862. if low_res == False:
  1863. s = pygame.Surface((640,360))
  1864. else:
  1865. s = pygame.Surface((320,240))
  1866. bg = pygame.Surface((480,360))
  1867. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  1868. if low_res == True:
  1869. bg = pygame.transform.scale(bg,(320,240))
  1870. s.blit(bg,(0,0))
  1871. if game_options.mousepad == 1 and low_res == False:
  1872. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  1873. else:
  1874. s_help = pygame.Surface((160,360))
  1875. s_help.fill((48,48,48))
  1876. s.blit(s_help,(480,0))
  1877. if simulation == False:
  1878. if more_txt == False:
  1879. top_text = '[Press ['+key_name['x']+'] to leave]'
  1880. else:
  1881. top_text = '[Press ['+key_name['e']+'] for next page]'
  1882. text_image = screen.font.render(top_text,1,(255,255,255))
  1883. s.blit(text_image,(5,2))#menue title
  1884. for i in range (0,len(text)):
  1885. text_image = screen.font.render(text[i],1,(0,0,0))
  1886. if low_res == False:
  1887. s.blit(text_image,(60,80+i*25))#blit credit_items
  1888. else:
  1889. s.blit(text_image,(21,36+i*20))#blit credit_items
  1890. if simulation == True:
  1891. return s
  1892. if game_options.mousepad == 0 and low_res == False:
  1893. s_help = pygame.Surface((640,360))
  1894. s_help.fill((48,48,48))
  1895. s_help.blit(s,(80,0))
  1896. s = s_help
  1897. if low_res == False:
  1898. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1899. self.screen.blit(s,(0,0))
  1900. pygame.display.flip()
  1901. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  1902. if ui == 'exit':
  1903. global master_loop
  1904. global playing
  1905. global exitgame
  1906. exitgame = True
  1907. try:
  1908. screen.render_load(5)
  1909. save(world,player,time,gods,save_path,os.sep)
  1910. screen.save_tmp_png()
  1911. del player
  1912. except:
  1913. None
  1914. master_loop = False
  1915. playing = False
  1916. run = False
  1917. return('exit')
  1918. if ui == 'x':
  1919. run = False
  1920. elif ui == 'e' and more_txt == True:
  1921. run = False
  1922. def render_multi_text(self,texts):
  1923. run = True
  1924. page = 0
  1925. total_pages = len(texts)
  1926. while run:
  1927. s = self.render_text(texts[page],simulation=True)
  1928. page_txt = 'Page '+str(page+1)+ ' of '+str(total_pages)+' ['+key_name['x']+'] - leave'
  1929. page_image = screen.font.render(page_txt,1,(255,255,255))
  1930. s.blit(page_image,(5,2))#menue title
  1931. if game_options.mousepad == 0 and low_res == False:
  1932. s_help = pygame.Surface((640,360))
  1933. s_help.fill((48,48,48))
  1934. s_help.blit(s,(80,0))
  1935. s = s_help
  1936. if low_res == False:
  1937. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1938. self.screen.blit(s,(0,0))
  1939. pygame.display.flip()
  1940. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  1941. if ui == 's' or ui == 'd':
  1942. page += 1
  1943. if page > total_pages-1:
  1944. page = 0
  1945. elif ui == 'w' or ui == 'a':
  1946. page -= 1
  1947. if page < 0:
  1948. page = total_pages-1
  1949. elif ui == 'x':
  1950. run = False
  1951. def render_options(self):
  1952. run = True
  1953. num = 0
  1954. options_path = save_path
  1955. for c in range(0,5):
  1956. options_path = options_path.replace(os.sep + 'World' + str(c),'')
  1957. while run:
  1958. if game_options.screenmode == 2:
  1959. winm = 'Screenmode: Fullscreen'
  1960. elif game_options.screenmode == 1:
  1961. winm = 'Screenmode: Windowed(1280X720)'
  1962. else:
  1963. winm = 'Screenmode: Windowed(640X360)'
  1964. if game_options.bgmmode == 1:
  1965. audiom = 'BGM: ON'
  1966. else:
  1967. audiom = 'BGM: OFF'
  1968. if game_options.sfxmode == 1:
  1969. sfxm = 'SFX: ON'
  1970. else:
  1971. sfxm = 'SFX: OFF'
  1972. if game_options.turnmode == 1:
  1973. turnm = 'Gamemode: Semi-Realtime'
  1974. else:
  1975. turnm = 'Gamemode: Turnbased'
  1976. if game_options.mousepad == 1:
  1977. mousem = 'Use Mouse: yes'
  1978. else:
  1979. mousem = 'Use Mouse: no'
  1980. if game_options.check_version == 1:
  1981. versm = 'Check Version: yes'
  1982. else:
  1983. versm = 'Check Version: no'
  1984. s = pygame.Surface((640,360))
  1985. bg = pygame.Surface((480,360))
  1986. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  1987. if low_res == True:
  1988. bg = pygame.transform.scale(bg,(320,240))
  1989. s.blit(bg,(0,0))
  1990. text = '~Options~ [Press ['+key_name['e']+'] to choose]'
  1991. text_image = screen.font.render(text,1,(255,255,255))
  1992. s.blit(text_image,(5,2))#menue title
  1993. menu_items = (winm,audiom,sfxm,turnm,mousem,versm,'Done')
  1994. for i in range (0,len(menu_items)):
  1995. text_image = screen.font.render(menu_items[i],1,(0,0,0))
  1996. s.blit(text_image,(21,120+i*25))#blit menu_items
  1997. s.blit(gra_files.gdic['display'][4],(0,112+num*25))#blit marker
  1998. if game_options.mousepad == 1:
  1999. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2000. else:
  2001. s_help = pygame.Surface((160,360))
  2002. s_help.fill((48,48,48))
  2003. s.blit(s_help,(480,0))
  2004. if game_options.mousepad == 0:
  2005. s_help = pygame.Surface((640,360))
  2006. s_help.fill((48,48,48))
  2007. s_help.blit(s,(80,0))
  2008. s = s_help
  2009. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  2010. self.screen.blit(s,(0,0))
  2011. pygame.display.flip()
  2012. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2013. if ui == 'exit':
  2014. global master_loop
  2015. global playing
  2016. global exitgame
  2017. global player
  2018. exitgame = True
  2019. try:
  2020. save_options(game_options,options_path,os.sep)
  2021. screen.render_load(5)
  2022. save(world,player,time,gods,save_path,os.sep)
  2023. screen.save_tmp_png()
  2024. del player
  2025. except:
  2026. None
  2027. master_loop = False
  2028. playing = False
  2029. run = False
  2030. return('exit')
  2031. if ui == 'w':
  2032. num -= 1
  2033. if num < 0:
  2034. num = len(menu_items)-1
  2035. if ui == 's':
  2036. num += 1
  2037. if num >= len(menu_items):
  2038. num = 0
  2039. if ui == 'x':
  2040. run = False
  2041. if ui == 'e':
  2042. if num == 0:
  2043. screen.re_init()
  2044. pygame.display.flip()
  2045. save_options(game_options,options_path,os.sep)
  2046. if num == 1:
  2047. if game_options.bgmmode == 1:
  2048. game_options.bgmmode = 0
  2049. pygame.mixer.music.pause()
  2050. else:
  2051. game_options.bgmmode = 1
  2052. pygame.mixer.music.unpause()
  2053. bgm.check_for_song(force_play=True)
  2054. save_options(game_options,options_path,os.sep)
  2055. if num == 2:
  2056. if game_options.sfxmode == 1:
  2057. game_options.sfxmode = 0
  2058. else:
  2059. game_options.sfxmode = 1
  2060. save_options(game_options,options_path,os.sep)
  2061. if num == 3:
  2062. if game_options.turnmode == 1:
  2063. game_options.turnmode = 0
  2064. else:
  2065. game_options.turnmode = 1
  2066. save_options(game_options,options_path,os.sep)
  2067. if num == 4 and low_res == False:
  2068. if game_options.mousepad == 1:
  2069. game_options.mousepad = 0
  2070. else:
  2071. game_options.mousepad = 1
  2072. pygame.mouse.set_visible(game_options.mousepad)
  2073. save_options(game_options,options_path,os.sep)
  2074. if num == 5:
  2075. if game_options.check_version == 1:
  2076. game_options.check_version = 0
  2077. else:
  2078. game_options.check_version = 1
  2079. save_options(game_options,options_path,os.sep)
  2080. if num == 6:
  2081. save_options(game_options,options_path,os.sep)
  2082. run = False
  2083. def render_brake(self,simulate= False):
  2084. run = True
  2085. num = 0
  2086. global exitgame
  2087. global playing
  2088. global player
  2089. while run:
  2090. if low_res == False:
  2091. s = pygame.Surface((640,360))
  2092. else:
  2093. s = pygame.Surface((320,240))
  2094. bg = pygame.Surface((480,360))
  2095. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2096. if low_res == True:
  2097. bg = pygame.transform.scale(bg,(320,240))
  2098. s.blit(bg,(0,0))
  2099. text = '~Game Paused~ [Press ['+key_name['e']+'] to choose]'
  2100. text_image = screen.font.render(text,1,(255,255,255))
  2101. s.blit(text_image,(5,2))#menue title
  2102. menu_items = ('Resume','Status','Message History','Save and Exit', 'Options',)
  2103. for i in range (0,len(menu_items)):
  2104. text_image = screen.font.render(menu_items[i],1,(0,0,0))
  2105. if low_res == False:
  2106. s.blit(text_image,(21,120+i*25))#blit menu_items
  2107. else:
  2108. s.blit(text_image,(21,46+i*25))#blit menu_items
  2109. if low_res == False:
  2110. s.blit(gra_files.gdic['display'][4],(0,112+num*25))#blit marker
  2111. else:
  2112. s.blit(gra_files.gdic['display'][4],(0,38+num*25))#blit marker
  2113. if game_options.mousepad == 1 and low_res != True:
  2114. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2115. else:
  2116. s_help = pygame.Surface((160,360))
  2117. s_help.fill((48,48,48))
  2118. s.blit(s_help,(480,0))
  2119. if game_options.mousepad == 0 and low_res == False:
  2120. s_help = pygame.Surface((640,360))
  2121. s_help.fill((48,48,48))
  2122. s_help.blit(s,(80,0))
  2123. s = s_help
  2124. if low_res == False:
  2125. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  2126. if simulate == True:
  2127. return s
  2128. self.screen.blit(s,(0,0))
  2129. pygame.display.flip()
  2130. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2131. if ui == 'exit':
  2132. global master_loop
  2133. global playing
  2134. global exitgame
  2135. exitgame = True
  2136. screen.render_load(5)
  2137. save(world,player,time,gods,save_path,os.sep)
  2138. screen.save_tmp_png()
  2139. master_loop = False
  2140. playing = False
  2141. run = False
  2142. return('exit')
  2143. if ui == 'w':
  2144. num -= 1
  2145. if num < 0:
  2146. num = len(menu_items)-1
  2147. if ui == 's':
  2148. num += 1
  2149. if num >= len(menu_items):
  2150. num = 0
  2151. if ui == 'x':
  2152. run = False
  2153. screen.render_fade(True,False,'screen')
  2154. if ui == 'e':
  2155. if num == 0:
  2156. run = False
  2157. screen.render_fade(True,False,'screen')
  2158. if num == 1:
  2159. screen.render_status()
  2160. if num == 2:
  2161. do = message.render_history()
  2162. if do == 'exit':
  2163. run = False
  2164. if num == 3:
  2165. exitgame = True
  2166. screen.render_load(5)
  2167. save(world,player,time,gods,save_path,os.sep)
  2168. screen.save_tmp_png()
  2169. del player
  2170. playing = False
  2171. run = False
  2172. if num == 4:
  2173. do = screen.render_options()
  2174. if do == 'exit':
  2175. run = False
  2176. return exitgame
  2177. def get_choice(self,headline,choices,allow_chancel,style='Default'):
  2178. #this function allows the player to make a coice. The choices-variable is a tulpel with strings. The function returns the number of the chosen string inside the tulpel
  2179. run = True
  2180. num = 0
  2181. while run:
  2182. if low_res == False:
  2183. s = pygame.Surface((640,360))
  2184. else:
  2185. s = pygame.Surface((320,240))
  2186. bg = pygame.Surface((480,360))
  2187. if style == 'Default':
  2188. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2189. elif style == 'Warning':
  2190. bg.blit(gra_files.gdic['display'][17],(0,0))
  2191. if low_res == True:
  2192. bg = pygame.transform.scale(bg,(320,240))
  2193. s.blit(bg,(0,0))
  2194. text_image = screen.font.render(headline,1,(255,255,255))
  2195. if low_res == False:
  2196. s.blit(text_image,(5,2))#menue title
  2197. else:
  2198. s.blit(text_image,(0,2))#menue title
  2199. menu_items = choices
  2200. for i in range (0,len(menu_items)):
  2201. text_image = screen.font.render(menu_items[i],1,(0,0,0))
  2202. if low_res == False:
  2203. s.blit(text_image,(21,120+i*25))#blit menu_items
  2204. else:
  2205. s.blit(text_image,(21,46+i*25))#blit menu_items
  2206. if allow_chancel == True:
  2207. string = '['+key_name['e']+'] - choose ['+key_name['x']+'] - leave'
  2208. text_image = screen.font.render(string,1,(255,255,255))
  2209. if low_res == True:
  2210. s.blit(text_image,(0,225))
  2211. else:
  2212. s.blit(text_image,(5,335))
  2213. else:
  2214. string = '['+key_name['e']+'] - choose'
  2215. text_image = screen.font.render(string,1,(255,255,255))
  2216. if low_res == True:
  2217. s.blit(text_image,(0,225))
  2218. else:
  2219. s.blit(text_image,(5,335))
  2220. if style == 'Default':
  2221. if low_res == False:
  2222. s.blit(gra_files.gdic['display'][4],(0,112+num*25))#blit marker
  2223. else:
  2224. s.blit(gra_files.gdic['display'][4],(0,38+num*25))#blit marker
  2225. elif style == 'Warning':
  2226. if low_res == False:
  2227. s.blit(gra_files.gdic['display'][18],(0,112+num*25))#blit marker
  2228. else:
  2229. s.blit(gra_files.gdic['display'][18],(0,38+num*25))#blit marker
  2230. if game_options.mousepad == 1 and low_res == True:
  2231. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2232. else:
  2233. s_help = pygame.Surface((160,360))
  2234. s_help.fill((48,48,48))
  2235. s.blit(s_help,(480,0))
  2236. if game_options.mousepad == 0 and low_res == False:
  2237. s_help = pygame.Surface((640,360))
  2238. s_help.fill((48,48,48))
  2239. s_help.blit(s,(80,0))
  2240. s = s_help
  2241. else:
  2242. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2243. if low_res == False:
  2244. s = pygame.transform.scale(s,(screen.displayx,screen.displayy))
  2245. screen.screen.blit(s,(0,0))
  2246. pygame.display.flip()
  2247. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2248. if ui == 'exit':
  2249. global master_loop
  2250. global playing
  2251. global exitgame
  2252. global player
  2253. exitgame = True
  2254. try:
  2255. screen.render_load(5)
  2256. save(world,player,time,gods,save_path,os.sep)
  2257. screen.save_tmp_png()
  2258. except:
  2259. None
  2260. master_loop = False
  2261. playing = False
  2262. run = False
  2263. return('exit')
  2264. if ui == 'w':
  2265. num -= 1
  2266. if num < 0:
  2267. num = len(menu_items)-1
  2268. if ui == 's':
  2269. num += 1
  2270. if num >= len(menu_items):
  2271. num = 0
  2272. if ui == 'e':
  2273. run = False
  2274. return num
  2275. if ui == 'x' and allow_chancel == True:
  2276. run = False
  2277. return 'Break'
  2278. def string_input(self, input_message, length):
  2279. run = True
  2280. string = ''
  2281. pos = 0
  2282. x = 0
  2283. y = 0
  2284. char_field = (('A','B','C','D','E','F','G','H','a','b','c','d','e','f','g','h'),('I','J','K','L','M','N','O','P','i','j','k','l','m','n','o','p'),('Q','R','S','T','U','V','W','X','q','r','s','t','u','v','w','x'),('Y','Z','y','z','0','1','2','3','4','5','6','7','8','9', '.',','),('(','[','<','{',')',']','>','}','#','+','-','_','*','/','&','%'))
  2285. while run:
  2286. s = pygame.Surface((640,360))
  2287. s.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2288. text_image = screen.font.render(input_message,1,(255,255,255))
  2289. s.blit(text_image,(5,2))#menue title
  2290. num_stars = length - len(string)
  2291. star_string = ''
  2292. if num_stars > 0:
  2293. for i in range (0,num_stars):
  2294. star_string += '*'
  2295. shown_string = string + '_' + star_string
  2296. string_image = screen.font.render(shown_string,1,(255,255,255))
  2297. s.blit(string_image,(5,35))#string so far
  2298. for i in range (0,5):#blit chars
  2299. for j in range (0,len(char_field[1])):
  2300. if i == y and j == x:
  2301. char_image = screen.font.render(char_field[i][j],1,(255,255,255))
  2302. else:
  2303. char_image = screen.font.render(char_field[i][j],1,(0,0,0))
  2304. if low_res == False:
  2305. s.blit(char_image,(55+(j*20),150+(i*20)))
  2306. else:
  2307. s.blit(char_image,(5+(j*20),90+(i*20)))
  2308. if game_options.mousepad == 1 and low_res == False:
  2309. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2310. else:
  2311. s_help = pygame.Surface((160,360))
  2312. s_help.fill((48,48,48))
  2313. s.blit(s_help,(480,0))
  2314. text = '['+key_name['e']+'] - Add Char ['+key_name['x']+'] - Del Char ['+key_name['b']+'] - Done'
  2315. text_image = screen.font.render(text,1,(255,255,255))
  2316. if low_res == False:
  2317. s.blit(text_image,(5,335))
  2318. else:
  2319. help_sur = pygame.Surface((320,16))
  2320. help_sur.fill((48,48,48))
  2321. help_sur.blit(text_image,(5,5))
  2322. s.blit(help_sur,(0,224))
  2323. if game_options.mousepad == 0 and low_res == False:
  2324. s_help = pygame.Surface((640,360))
  2325. s_help.fill((48,48,48))
  2326. s_help.blit(s,(80,0))
  2327. s = s_help
  2328. if low_res == False:
  2329. s = pygame.transform.scale(s,(screen.displayx,screen.displayy))
  2330. screen.screen.blit(s,(0,0))
  2331. pygame.display.flip()
  2332. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2333. if ui == 'w':
  2334. y -= 1
  2335. if y < 0:
  2336. y = 4
  2337. if ui == 's':
  2338. y += 1
  2339. if y > 4:
  2340. y = 0
  2341. if ui == 'a':
  2342. x -= 1
  2343. if x < 0:
  2344. x = len(char_field[1])-1
  2345. if ui == 'd':
  2346. x += 1
  2347. if x > len(char_field[1])-1:
  2348. x = 0
  2349. if ui == 'e':
  2350. if pos <= length:
  2351. string += char_field[y][x]
  2352. pos += 1
  2353. if ui == 'b':
  2354. run = False
  2355. if ui == 'x':
  2356. if pos > 0:
  2357. pos -= 1
  2358. string = string[:pos]
  2359. return string
  2360. def render_dead(self):
  2361. global exitgame
  2362. self.reset_hit_matrix()
  2363. if player.godmode == True:
  2364. player.respawn()
  2365. message.add('YOU DIE.. NOT!')
  2366. return True
  2367. run = True
  2368. while run:
  2369. if low_res == False:
  2370. s = pygame.Surface((640,360))
  2371. else:
  2372. s = pygame.Surface((320,240))
  2373. s.fill((48,48,48)) #paint it grey(to clear the screen)
  2374. text_image = screen.font.render('YOU ARE DEAD!',1,(255,255,255))
  2375. if low_res == False:
  2376. s.blit(text_image,(175,60))
  2377. else:
  2378. s.blit(text_image,(75,60))
  2379. if player.difficulty == 3: #you play on roguelike mode
  2380. choose_string = '------------- ['+key_name['x']+'] - END GAME'
  2381. else:#you play on a other mode
  2382. choose_string = '['+key_name['e']+'] - RESPAWN ['+key_name['x']+'] - END GAME'
  2383. choose_image = screen.font.render(choose_string,1,(255,255,255))
  2384. if low_res == False:
  2385. s.blit(choose_image,(125,200))
  2386. else:
  2387. s.blit(choose_image,(25,200))
  2388. if game_options.mousepad == 1 and low_res == False:
  2389. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2390. else:
  2391. s_help = pygame.Surface((160,360))
  2392. s_help.fill((48,48,48))
  2393. s.blit(s_help,(480,0))
  2394. if game_options.mousepad == 0 and low_res == False:
  2395. s_help = pygame.Surface((640,360))
  2396. s_help.fill((48,48,48))
  2397. s_help.blit(s,(80,0))
  2398. s = s_help
  2399. else:
  2400. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2401. if low_res == False:
  2402. s = pygame.transform.scale(s,(screen.displayx,screen.displayy))
  2403. screen.screen.blit(s,(0,0))
  2404. pygame.display.flip()
  2405. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2406. if ui == 'exit':
  2407. global master_loop
  2408. global playing
  2409. global exitgame
  2410. exitgame = True
  2411. if player.difficulty !=3:
  2412. screen.render_load(5)
  2413. save(world,player,time,gods,save_path,os.sep)
  2414. screen.save_tmp_png()
  2415. else:
  2416. files_to_remove = ('gods.data','player.data','world.data','time.data')
  2417. for i in files_to_remove:
  2418. del_file = save_path + os.sep + i
  2419. try:
  2420. os.remove(del_file)
  2421. except:
  2422. None
  2423. master_loop = False
  2424. playing = False
  2425. run = False
  2426. return('exit')
  2427. if ui == 'e' and player.difficulty != 3:
  2428. player.respawn()
  2429. save(world,player,time,gods,save_path,os.sep)
  2430. run = False
  2431. elif ui == 'x':
  2432. player.respawn()
  2433. if player.difficulty != 3:
  2434. screen.render_load(5)
  2435. save(world,player,time,gods,save_path,os.sep)
  2436. screen.save_tmp_png()
  2437. else:
  2438. files_to_remove = ('gods.data','player.data','world.data','time.data')
  2439. for i in files_to_remove:
  2440. del_file = save_path + os.sep + i
  2441. try:
  2442. os.remove(del_file)
  2443. except:
  2444. None
  2445. run = False
  2446. exitgame = True
  2447. class maP():
  2448. def __init__(self, name, tilemap, visit=False, map_type='overworld',monster_num=1):
  2449. self.name = name
  2450. self.known = []
  2451. self.containers = []
  2452. self.tilemap = tilemap
  2453. self.visit = visit
  2454. self.last_visit = 0 #-------test only
  2455. self.map_type = map_type
  2456. self.monster_num = monster_num
  2457. self.build_type = 'Full' #Full: build everything you want, Part: no stairs, None: Buildmode is not callable
  2458. self.thirst_multi_day = 1
  2459. self.thirst_multi_night = 1
  2460. self.no_monster_respawn = False
  2461. self.countdowns = []
  2462. self.npcs = []
  2463. self.monster_plus = 0
  2464. self.monster_count = 0
  2465. self.music_day_original = 'overworld'
  2466. self.music_day = self.music_day_original
  2467. self.music_night_original = 'night'
  2468. self.music_night = self.music_night_original
  2469. self.generation_release = release_number
  2470. for y in range (0,max_map_size):
  2471. self.known.append([])
  2472. for x in range (0,max_map_size):
  2473. self.known[y].append(0)
  2474. for y in range (0,max_map_size):
  2475. self.containers.append([])
  2476. for x in range (0,max_map_size):
  2477. self.containers[y].append(0)
  2478. for y in range (0,max_map_size):
  2479. self.npcs.append([])
  2480. for x in range (0,max_map_size):
  2481. self.npcs[y].append(0)
  2482. def fill(self, tile):
  2483. for y in range (0,max_map_size):
  2484. for x in range(0,max_map_size):
  2485. self.tilemap[y][x] = deepcopy(tile)
  2486. def check_fov(self,x,y,dist):
  2487. fov = []
  2488. startx = x-8
  2489. starty = y-6
  2490. extreme_coordinates = []
  2491. dist_coordinates = []
  2492. for yy in range(0,12):
  2493. fov.append([])
  2494. for xx in range(0,15):
  2495. fov[yy].append(0)
  2496. dist1 = ((8-xx)**2+(6-yy)**2)**0.5
  2497. if dist1 > 0:
  2498. extreme_coordinates.append((xx,yy))
  2499. dist_coordinates.append(dist1)
  2500. for i in range(0,len(extreme_coordinates)-1):
  2501. c = 0
  2502. run = True
  2503. while run:
  2504. dir_x = (8-extreme_coordinates[i][0])/dist_coordinates[i]
  2505. dir_y = (6-extreme_coordinates[i][1])/dist_coordinates[i]
  2506. lx = int(round(8+c*dir_x))
  2507. ly = int(6+c*dir_y)
  2508. if ly < 6:
  2509. ly += 1
  2510. elif ly > 6:
  2511. ly -= 1
  2512. ldist = ((8-lx)**2+(6-ly)**2)**0.5
  2513. try:
  2514. fov[ly][lx] = 1
  2515. except:
  2516. None
  2517. c+=1
  2518. if lx < 0 or lx > 14 or ly < 0 or ly > 11:
  2519. run = False
  2520. elif ldist >= dist:
  2521. run = False
  2522. elif self.tilemap[starty+ly][startx+lx].transparency == False:
  2523. run = False
  2524. return fov
  2525. def check_los(self,startx,starty,endx,endy):
  2526. if startx > max_map_size or startx < 0 or endx > max_map_size or endx < 0 or starty > max_map_size or starty < 0 or endy > max_map_size or endy < 0:
  2527. return False
  2528. try:
  2529. m = (startx-endx)/(starty-endy)
  2530. except:
  2531. m = 'error'
  2532. if m != 'error':
  2533. n = starty-(m*startx)
  2534. if startx < endx:
  2535. c = 1
  2536. elif startx > endx:
  2537. c = -1
  2538. else:
  2539. return True
  2540. else:
  2541. if starty < endy:
  2542. c = 1
  2543. elif starty > endy:
  2544. c = -1
  2545. else:
  2546. return True
  2547. test = True
  2548. run=True
  2549. count = 0
  2550. while run:
  2551. if m != 'error':
  2552. x = startx + count
  2553. y = int((m*x)+n)
  2554. elif starty==endy:
  2555. x = startx
  2556. y = starty + count
  2557. try:
  2558. if self.tilemap[y][x].transparency == False and x != endx and y != endy:
  2559. test = False
  2560. if x == endx or y == endy:
  2561. run = False
  2562. count += c
  2563. except:
  2564. run = False
  2565. return test
  2566. def set_round_frame(self,tile,radius):
  2567. center = int(max_map_size/2)
  2568. for y in range(0,max_map_size):
  2569. for x in range(0,max_map_size):
  2570. range_x = x-center
  2571. range_y = y-center
  2572. if ((range_x**2+range_y**2)**0.5) > radius:
  2573. self.tilemap[y][x] = tile
  2574. def set_music(self,day,night,change_original=False):
  2575. if day != None:
  2576. self.music_day = day
  2577. if change_original == True:
  2578. self.music_day_original = day
  2579. if night != None:
  2580. self.music_night = night
  2581. if change_original == True:
  2582. self.music_night_original = night
  2583. def drunken_finder(self,startx,starty,tile):
  2584. x = startx
  2585. y = starty
  2586. run = True
  2587. while run:
  2588. direction = random.randint(0,3)
  2589. if direction == 0:
  2590. y -= 1
  2591. elif direction == 1:
  2592. x += 1
  2593. elif direction == 2:
  2594. y += 1
  2595. else:
  2596. x -= 1
  2597. if self.tilemap[y][x].techID == tile.techID:
  2598. run = False
  2599. return (x,y)
  2600. def drunken_walker(self,startx,starty,tile_replace,num_replace):
  2601. num = 1
  2602. x = startx
  2603. y = starty
  2604. self.tilemap[y][x] = tile_replace
  2605. while num < num_replace:
  2606. #step 0: get possible directions
  2607. dir_list = []
  2608. for n in range(-1,2):
  2609. if x+n < max_map_size-2 and x+n > 2:
  2610. if x+n < max_map_size-7 and x+n > 7:
  2611. count = 5
  2612. else:
  2613. count = min((max_map_size-2)-(x+n),(x+n),3)
  2614. count = max(count,1)#only to be sure count < 1
  2615. for c in range(0,count):
  2616. dir_list.append([x+n,y])
  2617. if y+n < max_map_size-2 and y+n > 2:
  2618. if y+n < max_map_size-7 and y+n > 7:
  2619. count = 5
  2620. else:
  2621. count = min((max_map_size-2)-(y+n),(y+n),3)
  2622. count = max(count,1)#only to be sure count < 1
  2623. for c in range(0,count):
  2624. dir_list.append([x,y+n])
  2625. #step 1: set tile new tile
  2626. ran = random.randint(0,len(dir_list)-1)
  2627. x = dir_list[ran][0]
  2628. y = dir_list[ran][1]
  2629. if self.tilemap[y][x].techID != tile_replace.techID:
  2630. self.tilemap[y][x] = tile_replace
  2631. num += 1
  2632. def floating(self,startx,starty,tile_fill,tile_border):
  2633. #its important to use a tile_fill that isn't on the map and a tile_border that is on the map
  2634. run = True
  2635. self.tilemap[starty][startx] = deepcopy(tile_fill)
  2636. while run:
  2637. count = 0
  2638. for y in range(0,max_map_size):
  2639. for x in range(0,max_map_size):
  2640. if self.tilemap[y][x].techID == tile_fill.techID:
  2641. for yy in range(y-1,y+2):
  2642. for xx in range(x-1,x+2):
  2643. try:
  2644. if self.tilemap[yy][xx].techID != tile_border.techID and self.tilemap[yy][xx].techID != tile_fill.techID:
  2645. self.tilemap[yy][xx] = deepcopy(tile_fill)
  2646. count += 1
  2647. except:
  2648. None
  2649. if count == 0:
  2650. run = False
  2651. def float_civilisation(self,start_x,start_y):
  2652. tm = []
  2653. for y in range(0,max_map_size):
  2654. tm.append([])
  2655. for x in range(0,max_map_size):
  2656. tm[y].append(0)
  2657. tm[start_y][start_x] = 1
  2658. run = True
  2659. total_count = 1
  2660. while run:
  2661. count = 0
  2662. for yy in range(0,max_map_size):
  2663. for xx in range(0,max_map_size):
  2664. if tm[yy][xx] == 1:
  2665. for yyy in range(yy-1,yy+2):
  2666. for xxx in range(xx-1,xx+2):
  2667. try:
  2668. if tm[yyy][xxx] == 0 and self.tilemap[yyy][xxx].move_group == 'soil' and self.tilemap[yyy][xxx].civilisation == True:
  2669. tm[yyy][xxx] = 1
  2670. count += 1
  2671. total_count += 1
  2672. elif self.tilemap[yyy][xxx].civilisation == False:
  2673. return 0
  2674. except:
  2675. None
  2676. if count == 0:
  2677. run = False
  2678. return total_count
  2679. def get_quarter_size(self,startx,starty):
  2680. #this funktion gives back a tulpel with the width and height of a quarter made out of the same tile like the start position
  2681. techID = self.tilemap[starty][startx].techID
  2682. q_width = 0
  2683. q_height = 0
  2684. run_w = True
  2685. run_h = True
  2686. while run_w:
  2687. if self.tilemap[starty][startx+q_width].techID == techID:
  2688. q_width += 1
  2689. else:
  2690. run_w = False
  2691. while run_h:
  2692. if self.tilemap[starty+q_height][startx].techID == techID:
  2693. q_height += 1
  2694. else:
  2695. run_h = False
  2696. return (q_width,q_height)
  2697. def set_frame(self,tile):
  2698. for y in range (0,max_map_size):
  2699. for x in range (0,max_map_size):
  2700. if x == 0 or x == max_map_size-1 or y == 0 or y == max_map_size-1:
  2701. self.tilemap[y][x] = tile
  2702. def cut(self, minx, maxx, miny, maxy, replace):
  2703. #everything that is not between min and mx is replaced abainst a tile
  2704. for y in range (0,max_map_size):
  2705. for x in range (0,max_map_size):
  2706. if x < minx or x > maxx or y < miny or y > maxy:
  2707. self.tilemap[y][x] = replace
  2708. def imp(self, start_x, start_y, replace_inner, replace_outer, step_min, step_max, circles, replace_except=None): #dig random caves
  2709. #was made to generate random caves but dosn't pleased me. maybe this can be used for mazes.(unused atm)
  2710. x = start_x
  2711. y = start_y
  2712. for l in range (0,circles):
  2713. run = True
  2714. while run:
  2715. direction = random.randint(0,3)
  2716. move_x = 0
  2717. move_y = 0
  2718. if direction == 0:
  2719. move_y = -1
  2720. elif direction == 1:
  2721. move_x = 1
  2722. elif direction == 2:
  2723. move_y = 1
  2724. else:
  2725. move_x= -1
  2726. length = random.randint(step_min, step_max)
  2727. for m in range (0,length):
  2728. x = x + move_x
  2729. y = y + move_y
  2730. if x <= 1 or x >= 78 or y <= 1 or y >= 78:
  2731. break
  2732. run = False
  2733. self.tilemap[y][x] = replace_inner
  2734. for b in range (-1,2):
  2735. for a in range (-1,2):
  2736. if self.tilemap[y+a][x+b] != replace_outer and self.tilemap[y+a][x+b] != replace_inner and self.tilemap[y+a][x+b] != replace_except:
  2737. self.tilemap[y+a][x+b] = replace_outer
  2738. run = False
  2739. def imp_connect(self,xpos,ypos,replace_inner,replace_except=None,except_replacer=None,style='straight'): #conects two or more points
  2740. for a in range (0,len(ypos)-1):
  2741. for b in range(0,len(xpos)-1):
  2742. y = ypos[a]
  2743. x = xpos[b]
  2744. go = True
  2745. direction = 0 #needed for natural ways. jumps between 0 and 1
  2746. while go:
  2747. try:
  2748. y_goal = ypos[a+1]
  2749. x_goal = xpos[b+1]
  2750. except:
  2751. y_goal = ypos[0]
  2752. x_goal = xpos[0]
  2753. if x == x_goal and y == y_goal:
  2754. go = False
  2755. if x_goal - x < 0: #find out if you need to go right or left
  2756. x_direction = -1
  2757. else:
  2758. x_direction = 1
  2759. if y_goal - y < 0: #find out if you need to go up or down
  2760. y_direction = -1
  2761. else:
  2762. y_direction = 1
  2763. if style == 'straight':
  2764. if x != x_goal:
  2765. x = x + x_direction
  2766. if self.tilemap[y][x] != replace_except:
  2767. self.tilemap[y][x] = replace_inner
  2768. elif self.tilemap[y][x] == replace_except:
  2769. self.tilemap[y][x] = except_replacer
  2770. elif y != y_goal:
  2771. y = y + y_direction
  2772. if self.tilemap[y][x] != replace_except:
  2773. self.tilemap[y][x] = replace_inner
  2774. elif self.tilemap[y][x] == replace_except:
  2775. self.tilemap[y][x] = except_replacer
  2776. elif style == 'natural':
  2777. if x != x_goal and direction == 0:
  2778. x = x + x_direction
  2779. if self.tilemap[y][x] != replace_except:
  2780. self.tilemap[y][x] = replace_inner
  2781. elif self.tilemap[y][x] == replace_except:
  2782. self.tilemap[y][x] = except_replacer
  2783. elif y != y_goal and direction == 1:
  2784. y = y + y_direction
  2785. if self.tilemap[y][x] != replace_except:
  2786. self.tilemap[y][x] = replace_inner
  2787. elif self.tilemap[y][x] == replace_except:
  2788. self.tilemap[y][x] = except_replacer
  2789. if direction == 0:
  2790. direction = 1
  2791. elif direction == 1:
  2792. direction = 0
  2793. def spawn_monsters(self,depth):
  2794. #This function spawns monsters on the map
  2795. if self.map_type == 'elfish_fortress':
  2796. monster_max = 0
  2797. for y in range(0,max_map_size):
  2798. for x in range(0,max_map_size):
  2799. if self.tilemap[y][x].techID == tl.tlist['functional'][8].techID:#this is a bed
  2800. monster_max += 1
  2801. else:
  2802. monster_max = (max_map_size*max_map_size)/30
  2803. monster_max = int(monster_max * self.monster_num)
  2804. if self.map_type == 'grot':
  2805. spawnpoints = self.find_all_moveable(ignore_water = False, ignore_no_spawn = False)
  2806. else:
  2807. spawnpoints = self.find_all_moveable(ignore_no_spawn = False)
  2808. del_list = []
  2809. monster_count = self.monster_count
  2810. for i in range (0,len(spawnpoints)):
  2811. if self.npcs[spawnpoints[i][1]][spawnpoints[i][0]] != 0: #there is a monster here
  2812. spawnpoints[i] = 'del'
  2813. #monster_count += 1#count the monsters that are already on the map
  2814. newlist = []
  2815. for k in spawnpoints:
  2816. if k != 'del':
  2817. newlist.append(k)
  2818. spawnpoints = newlist
  2819. monster_max -= monster_count
  2820. if monster_max > len(spawnpoints):
  2821. monster_max = len(spawnpoints)
  2822. for k in range(0,monster_max):
  2823. ran = random.randint(0,len(ml.mlist[self.map_type])-1)
  2824. ran2 = random.randint(0,len(spawnpoints)-1)
  2825. ran3 = random.randint(0,len(ml.mlist['civilian'])-1)
  2826. self.npcs[spawnpoints[ran2][1]][spawnpoints[ran2][0]] = deepcopy(ml.mlist[self.map_type][ran])#deepcopy is used that every monster on the map is saved separate
  2827. self.set_monster_strength(spawnpoints[ran2][0],spawnpoints[ran2][1],depth)
  2828. self.monster_count += 1
  2829. if self.no_monster_respawn == False:
  2830. self.countdowns.append(countdown('spawner',spawnpoints[ran2][1],spawnpoints[ran2][0],random.randint(5,60)))
  2831. try:
  2832. if player.difficulty == 4:
  2833. self.npcs[spawnpoints[ran2][1]][spawnpoints[ran2][0]].AI_style = 'ignore'
  2834. except:
  2835. None
  2836. #set monsters personal_id
  2837. self.npcs[spawnpoints[ran2][1]][spawnpoints[ran2][0]].personal_id = str(self.npcs[spawnpoints[ran2][1]][spawnpoints[ran2][0]].techID)+'_'+str(spawnpoints[ran2][0])+'_'+str(spawnpoints[ran2][1])+'_'+str(random.randint(0,9999))
  2838. #set monster groups
  2839. self.spawn_monster_groups(ml.mlist['kobold'][0],ml.mlist['kobold'][1],9)#kobolds
  2840. def set_monster_strength(self,x,y,z,preset_lvl=None,lvl_bonus=0):
  2841. if self.npcs[y][x] != 0:
  2842. old_lvl = self.npcs[y][x].lvl
  2843. ran = random.randint(1,3)
  2844. if Time_ready == True:
  2845. if player.difficulty == 3:
  2846. base_lvl = 25
  2847. elif player.difficulty == 2:
  2848. base_lvl = 20
  2849. elif player.difficulty == 1:
  2850. base_lvl = 15
  2851. elif player.difficulty == 0:
  2852. base_lvl = 10
  2853. else:
  2854. base_lvl = 0
  2855. time_coeff = int(base_lvl*((time.year-1)*28*12 + time.day_total)/150) #base_lvl levels each 150 days of gameplay #
  2856. else:
  2857. time_coeff = 0
  2858. if self.npcs[y][x].techID == ml.mlist['overworld'][0] or self.npcs[y][x].techID == ml.mlist['angry_monster'][2]: #this is a dryade
  2859. try:
  2860. time_coeff = player.lvl
  2861. except:
  2862. None
  2863. monster_lvl = z + ran + self.monster_plus + time_coeff
  2864. if monster_lvl >= old_lvl and old_lvl > 0:
  2865. try:
  2866. screen.write_hit_matrix(x,y,12) #render monster_lvl_up
  2867. except:
  2868. None
  2869. if preset_lvl != None:
  2870. self.npcs[y][x].lvl = preset_lvl
  2871. else:
  2872. self.npcs[y][x].lvl = monster_lvl
  2873. self.npcs[y][x].lvl += lvl_bonus
  2874. attribute_list =[]
  2875. al = ('p_strength','p_defense','m_strength','m_defense','health')
  2876. for c in range(0,5):
  2877. if self.npcs[y][x].attribute_prev[c] > 0:
  2878. for h in range(0,self.npcs[y][x].attribute_prev[c]):
  2879. attribute_list.append(al[c])
  2880. for i in range(0,self.npcs[y][x].lvl):
  2881. choice = attribute_list[random.randint(0,len(attribute_list)-1)]
  2882. if choice == 'p_strength':
  2883. self.npcs[y][x].basic_attribute.p_strength +=3
  2884. elif choice == 'p_defense':
  2885. self.npcs[y][x].basic_attribute.p_defense +=3
  2886. elif choice == 'm_strength':
  2887. self.npcs[y][x].basic_attribute.m_strength +=3
  2888. elif choice == 'm_defense':
  2889. self.npcs[y][x].basic_attribute.m_defense +=3
  2890. elif choice == 'health':
  2891. self.npcs[y][x].basic_attribute.max_lp +=1
  2892. self.npcs[y][x].lp = self.npcs[y][x].basic_attribute.max_lp
  2893. if old_lvl == 0:
  2894. el = [['spear','sword','axe','hammer'],['rune','wand','rune staff','artefact'],['armor','armor'],['necklace','amulet','talisman'],['ring','ring']]
  2895. e_nr = 0
  2896. for q in range(0,len(el)-1):
  2897. ran = random.randint(0,len(el[q])-1)
  2898. if self.npcs[y][x].worn_equipment[q] == 1:
  2899. help_equipment = item_wear(el[q][ran],random.randint(0,min((z*3),21)),random.randint(-2,2))
  2900. self.npcs[y][x].basic_attribute.p_strength += help_equipment.attribute.p_strength
  2901. self.npcs[y][x].basic_attribute.p_defense += help_equipment.attribute.p_defense
  2902. self.npcs[y][x].basic_attribute.m_strength += help_equipment.attribute.m_strength
  2903. self.npcs[y][x].basic_attribute.m_defense += help_equipment.attribute.m_defense
  2904. self.npcs[y][x].basic_attribute.luck += help_equipment.attribute.luck
  2905. def make_vault(self,on_tile,depth):
  2906. run = True
  2907. while run:
  2908. pos = self.find_any(on_tile)
  2909. test = True
  2910. orientation = random.randint(0,3)#0:north, 1:east, 2:south, 3:west
  2911. try:
  2912. if pos[0] < 6 or pos[0] > max_map_size-6 or pos[1] < 6 or pos[1] > max_map_size-6:
  2913. test = False
  2914. if orientation == 0:
  2915. x_offset = -2
  2916. y_offset = random.randint(-1,1)
  2917. elif orientation == 1:
  2918. x_offset = random.randint(-1,1)
  2919. y_offset = -2
  2920. elif orientation == 2:
  2921. x_offset = 2
  2922. y_offste = random.randint(-1,1)
  2923. else:
  2924. x_offset = random.randint(-1,1)
  2925. y_offset = 2
  2926. for ty in range(pos[1]+y_offset-1,pos[1]+y_offset+6):
  2927. for tx in range(pos[0]+x_offset-1,pos[0]+x_offset+6):
  2928. if self.tilemap[ty][tx].techID == tl.tlist['dungeon'][0].techID:
  2929. test = False
  2930. elif self.tilemap[ty][tx].techID == tl.tlist['dungeon'][6].techID:
  2931. test = False
  2932. elif self.tilemap[ty][tx].techID == tl.tlist['dungeon'][9].techID:
  2933. test = False
  2934. elif self.tilemap[ty][tx].techID == tl.tlist['functional'][2].techID:
  2935. test = False
  2936. except:
  2937. test = False
  2938. if test:
  2939. run = False
  2940. for yy in range(pos[1]+y_offset-2,pos[1]+y_offset+3):
  2941. for xx in range(pos[0]+x_offset-2,pos[0]+x_offset+3):
  2942. if xx == pos[0]+x_offset-2 or xx == pos[0]+x_offset+2 or yy == pos[1]+y_offset-2 or yy == pos[1]+y_offset+2:
  2943. self.tilemap[yy][xx] = deepcopy(tl.tlist['dungeon'][9])
  2944. self.tilemap[yy][xx].no_spawn = True
  2945. else:
  2946. self.tilemap[yy][xx] = deepcopy(tl.tlist['dungeon'][0])
  2947. self.tilemap[yy][xx].no_spawn = True
  2948. make_loot = True # if make_loot is set on False no gems or ore will spawn inside the vault
  2949. vault_center_x = pos[0]+x_offset
  2950. vault_center_y = pos[1]+y_offset
  2951. door_pos = self.drunken_finder(vault_center_x,vault_center_y,tl.tlist['dungeon'][9])
  2952. self.tilemap[door_pos[1]][door_pos[0]] = deepcopy(tl.tlist['dungeon'][6])
  2953. self.tilemap[door_pos[1]][door_pos[0]].no_spawn = True
  2954. vault_type = random.randint(0,4)
  2955. #vault_type = 4
  2956. if vault_type == 0: #Libary
  2957. replace = self.tilemap[vault_center_y][vault_center_x]
  2958. self.tilemap[vault_center_y][vault_center_x] = deepcopy(tl.tlist['functional'][19])#set a bookshelf
  2959. self.tilemap[vault_center_y][vault_center_x].replace = replace
  2960. self.tilemap[vault_center_y][vault_center_x].no_spawn = True
  2961. replace = self.tilemap[vault_center_y+1][vault_center_x]
  2962. self.tilemap[vault_center_y+1][vault_center_x] = deepcopy(tl.tlist['functional'][4])#set a chest
  2963. self.tilemap[vault_center_y+1][vault_center_x].replace = replace
  2964. self.tilemap[vault_center_y+1][vault_center_x].no_spawn = True
  2965. num_spellbooks = random.randint(2,3)#fill the chest
  2966. spellbook_list = []
  2967. sb = (il.ilist['misc'][26],il.ilist['misc'][30],il.ilist['misc'][32],il.ilist['misc'][34],il.ilist['misc'][36],il.ilist['misc'][38])
  2968. for i in range(0,num_spellbooks):
  2969. ran = random.randint(0,len(sb)-1)
  2970. spellbook_list.append(sb[ran])
  2971. self.containers[vault_center_y+1][vault_center_x] = container(spellbook_list)
  2972. self.npcs[vault_center_y-1][vault_center_x-1] = deepcopy(ml.mlist['grot'][0]) #
  2973. self.set_monster_strength(vault_center_x-1,vault_center_y-1,depth,lvl_bonus=3) #
  2974. self.npcs[vault_center_y-1][vault_center_x+1] = deepcopy(ml.mlist['grot'][0]) #
  2975. self.set_monster_strength(vault_center_x+1,vault_center_y-1,depth,lvl_bonus=3) #set blue nagas
  2976. self.npcs[vault_center_y+1][vault_center_x-1] = deepcopy(ml.mlist['grot'][0]) #
  2977. self.set_monster_strength(vault_center_x-1,vault_center_y+1,depth,lvl_bonus=3) #
  2978. self.npcs[vault_center_y+1][vault_center_x+1] = deepcopy(ml.mlist['grot'][0]) #
  2979. self.set_monster_strength(vault_center_x+1,vault_center_y+1,depth,lvl_bonus=3) #
  2980. if vault_type == 1: #Slime pit
  2981. replace = self.tilemap[vault_center_y][vault_center_x]
  2982. self.tilemap[vault_center_y][vault_center_x] = deepcopy(tl.tlist['statue'][2])#set a blob statue
  2983. self.tilemap[vault_center_y][vault_center_x].replace = replace
  2984. self.tilemap[vault_center_y][vault_center_x].no_spawn = True
  2985. self.npcs[vault_center_y-1][vault_center_x-1] = deepcopy(ml.mlist['special'][10]) #
  2986. self.set_monster_strength(vault_center_x-1,vault_center_y-1,depth,lvl_bonus=3) #
  2987. self.npcs[vault_center_y-1][vault_center_x+1] = deepcopy(ml.mlist['special'][10]) #
  2988. self.set_monster_strength(vault_center_x+1,vault_center_y-1,depth,lvl_bonus=3) #set giant blobs
  2989. self.npcs[vault_center_y+1][vault_center_x-1] = deepcopy(ml.mlist['special'][10]) #
  2990. self.set_monster_strength(vault_center_x-1,vault_center_y+1,depth,lvl_bonus=3) #
  2991. self.npcs[vault_center_y+1][vault_center_x+1] = deepcopy(ml.mlist['special'][10]) #
  2992. self.set_monster_strength(vault_center_x+1,vault_center_y+1,depth,lvl_bonus=3) #
  2993. if vault_type == 2: #Kobold Lair
  2994. replace = self.tilemap[vault_center_y][vault_center_x]
  2995. self.tilemap[vault_center_y][vault_center_x] = deepcopy(tl.tlist['deco'][9])#set a stony throne
  2996. self.tilemap[vault_center_y][vault_center_x].replace = replace #
  2997. self.tilemap[vault_center_y][vault_center_x].no_spawn = True #
  2998. for posy in range(vault_center_y-1,vault_center_y+2): #
  2999. for posx in range(vault_center_x-1,vault_center_x+2): #set Kobolds
  3000. self.npcs[posy][posx] = deepcopy(ml.mlist['kobold'][1]) #
  3001. self.set_monster_strength(posx,posy,depth,lvl_bonus=3) #
  3002. self.npcs[vault_center_y][vault_center_x] = deepcopy(ml.mlist['kobold'][0]) #set kobold shaman
  3003. self.set_monster_strength(vault_center_x,vault_center_y,depth,lvl_bonus=3) #
  3004. if vault_type == 3: #Bat Cave
  3005. make_loot = False
  3006. for posy in range(vault_center_y-1,vault_center_y+2): #
  3007. for posx in range(vault_center_x-1,vault_center_x+2): #set bats
  3008. self.npcs[posy][posx] = deepcopy(ml.mlist['cave'][2]) #
  3009. self.set_monster_strength(posx,posy,depth) #
  3010. if vault_type == 4: #mimic chamber
  3011. make_loot = False
  3012. ranx = random.randint(-1,1) #
  3013. rany = random.randint(-1,1) #
  3014. replace = self.tilemap[vault_center_y+rany][vault_center_x+ranx] #
  3015. self.tilemap[vault_center_y+rany][vault_center_x+ranx] = deepcopy(tl.tlist['functional'][4])#set a chest
  3016. self.tilemap[vault_center_y+rany][vault_center_x+ranx].replace = replace #
  3017. self.tilemap[vault_center_y+rany][vault_center_x+ranx].no_spawn = True #
  3018. sb = (il.ilist['misc'][26],il.ilist['misc'][30],il.ilist['misc'][32],il.ilist['misc'][34],il.ilist['misc'][36],il.ilist['misc'][38])
  3019. ransb = random.randint(0,len(sb)-1)
  3020. book = sb[ransb]
  3021. pick = item_wear('pickaxe', 20,0)
  3022. axe = item_wear('axe',20,0)
  3023. self.containers[vault_center_y+rany][vault_center_x+ranx] = container([book,axe,pick])#fill chest
  3024. for posy in range(vault_center_y-1,vault_center_y+2): #
  3025. for posx in range(vault_center_x-1,vault_center_x+2): #set sleeping mimics
  3026. if self.tilemap[posy][posx].techID != tl.tlist['functional'][4].techID: #
  3027. self.npcs[posy][posx] = deepcopy(ml.mlist['special'][3]) #
  3028. if make_loot == True:
  3029. for yyy in range(vault_center_y-2,vault_center_y+3):
  3030. for xxx in range(vault_center_x-2,vault_center_x+3):
  3031. if self.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][0].techID:
  3032. ran2 = random.randint(0,2)
  3033. replace = self.tilemap[yyy][xxx]
  3034. if ran2 > 1:
  3035. self.tilemap[yyy][xxx] = deepcopy(tl.tlist['misc'][9])#set gem
  3036. self.tilemap[yyy][xxx].no_spawn = True
  3037. else:
  3038. self.tilemap[yyy][xxx] = deepcopy(tl.tlist['misc'][11])#set ore
  3039. self.tilemap[yyy][xxx].no_spawn = True
  3040. self.tilemap[yyy][xxx].replace = replace
  3041. #print('Made vault at: '+str(pos[0])+','+str(pos[1])+' Type:'+str(vault_type))
  3042. ####go on here
  3043. def make_orc_cave(self,on_tile):
  3044. run = True
  3045. while run:
  3046. pos = self.find_any(on_tile)
  3047. test = True
  3048. try:
  3049. for ty in range(pos[1]-2,pos[1]+3):
  3050. for tx in range(pos[0]-2,pos[0]+3):
  3051. if self.tilemap[ty][tx].techID == tl.tlist['misc'][16]:
  3052. test = False
  3053. elif self.tilemap[ty][tx].techID == tl.tlist['mine'][0]:
  3054. test = False
  3055. elif self.tilemap[ty][tx].techID == tl.tlist['dungeon'][3]:
  3056. test = False
  3057. elif self.tilemap[ty][tx].techID == tl.tlist['misc'][12]:
  3058. test = False
  3059. except:
  3060. test = False
  3061. if ((pos[0]-(max_map_size/2))**2+(pos[1]-(max_map_size/2))**2)**0.5 > 10:
  3062. if pos[0] > 5 and pos[0] < max_map_size-5 and pos[1] > 5 and pos[1] < max_map_size-5 and test == True:
  3063. run = False
  3064. for y in range(pos[1]-2,pos[1]+3):
  3065. for x in range(pos[0]-2,pos[0]+3):
  3066. self.tilemap[y][x] = tl.tlist['misc'][16] #fill with solid orcish wall
  3067. for y in range(pos[1]-1,pos[1]+2):
  3068. for x in range(pos[0]-1,pos[0]+2):
  3069. self.tilemap[y][x] = tl.tlist['mine'][0] #fill inner with orcish mine floor
  3070. if x != pos[0] or y != pos[1]:
  3071. self.npcs[y][x] = deepcopy(ml.mlist['orc'][random.randint(0,len(ml.mlist['orc'])-1)]) #
  3072. else: #
  3073. self.npcs[y][x] = deepcopy(ml.mlist['orcish_mines'][1]) #
  3074. self.set_monster_strength(x,y,1) #generate orcs
  3075. self.countdowns.append(countdown('orc_spawner',x,y,random.randint(5,60))) #
  3076. self.tilemap[pos[1]-2][pos[0]] = deepcopy(tl.tlist['dungeon'][3])#
  3077. self.tilemap[pos[1]+2][pos[0]] = deepcopy(tl.tlist['dungeon'][3])# make dungeon doors
  3078. self.tilemap[pos[1]][pos[0]-2] = deepcopy(tl.tlist['dungeon'][3])#
  3079. self.tilemap[pos[1]][pos[0]+2] = deepcopy(tl.tlist['dungeon'][3])#
  3080. self.tilemap[pos[1]-2][pos[0]-2] = deepcopy(tl.tlist['misc'][12])#
  3081. self.tilemap[pos[1]-2][pos[0]-2].replace = deepcopy(on_tile) #
  3082. self.tilemap[pos[1]-2][pos[0]+2] = deepcopy(tl.tlist['misc'][12])#
  3083. self.tilemap[pos[1]-2][pos[0]+2].replace = deepcopy(on_tile) # add orc deko to the connors
  3084. self.tilemap[pos[1]+2][pos[0]-2] = deepcopy(tl.tlist['misc'][12])#
  3085. self.tilemap[pos[1]+2][pos[0]-2].replace = deepcopy(on_tile) #
  3086. self.tilemap[pos[1]+2][pos[0]+2] = deepcopy(tl.tlist['misc'][12])#
  3087. self.tilemap[pos[1]+2][pos[0]+2].replace = deepcopy(on_tile) #
  3088. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['misc'][18])#set a crystal orb
  3089. def AI_move(self):
  3090. #This function moves all monsters that are 7 or less fields away from the player.
  3091. #It dosn't move all monsters to save performance
  3092. ymin = player.pos[1]-7
  3093. if ymin < 0:
  3094. ymin = 0
  3095. xmin = player.pos[0]-7
  3096. if xmin < 0:
  3097. xmin = 0
  3098. ymax = player.pos[1]+8
  3099. if ymax > max_map_size:
  3100. ymax = max_map_size
  3101. xmax = player.pos[0]+8
  3102. if xmax > max_map_size:
  3103. xmax = max_map_size
  3104. for y in range (ymin,ymax):#reset the move_done switches
  3105. for x in range (xmin,xmax):
  3106. if self.npcs[y][x] != 0:
  3107. if self.npcs[y][x].lp > 0:
  3108. self.npcs[y][x].move_done = 0
  3109. else:
  3110. test = False
  3111. while test == False:
  3112. test = self.monster_die(x,y)
  3113. for y in range (ymin,ymax):
  3114. for x in range (xmin,xmax):
  3115. if self.npcs[y][x] != 0 and self.npcs[y][x].move_done == 0:#if there is a monster at this place
  3116. #I. Get possible fields for a move
  3117. moves = [(x,y)]
  3118. yy = (-1,0,0,1)
  3119. xx = (0,-1,1,0)
  3120. for i in range (0,4):
  3121. try:
  3122. monster_move_groups = self.npcs[y][x].move_groups
  3123. tile_move_group = self.tilemap[y+yy[i]][x+xx[i]].move_group
  3124. move_group_check = tile_move_group in monster_move_groups
  3125. if self.npcs[y+yy[i]][x+xx[i]] == 0:
  3126. npc = False
  3127. else:
  3128. npc = True
  3129. if self.tilemap[y+yy[i]][x+xx[i]].techID == tl.tlist['functional'][1].techID or self.tilemap[y+yy[i]][x+xx[i]].techID == tl.tlist['functional'][2].techID: #this is a stair up/down
  3130. stair = True
  3131. else:
  3132. stair = False
  3133. if x + xx[i] == player.pos[0] and y + yy[i] == player.pos[1]:
  3134. playerpos = True
  3135. else:
  3136. playerpos = False
  3137. if move_group_check == True and npc == False and stair == False and playerpos == False:
  3138. moves.append((x+xx[i],y+yy[i]))
  3139. except:
  3140. print('Debug:Error')
  3141. #II. Find out which possible move leads to which distance between monster and player
  3142. distances = []
  3143. for j in range (0,len(moves)):
  3144. a = player.pos[0] - moves[j][0]
  3145. b = player.pos[1] - moves[j][1]
  3146. c = (a**2 + b**2)**0.5 # this is just the good old pythagoras (c² = a² + b²)
  3147. distances.append(c)
  3148. #III. Choose the right move (or special action)
  3149. do_move = 'foo'
  3150. if self.npcs[y][x].AI_style == 'hostile':
  3151. if self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp and player.lp > 2 and self.npcs[y][x].num_special > 0 :#this is a defensive situation for the monster
  3152. ran = random.randint(0,99)
  3153. if ran < self.npcs[y][x].def_teleport and self.npcs[y][x].move_done != 1:
  3154. moves = self.find_all_moveable(ignore_player_pos = False)
  3155. if moves != False:
  3156. if len(moves) == 1:
  3157. pos_num = 0
  3158. else:
  3159. pos_num = random.randint(0,len(moves)-1)
  3160. self.npcs[y][x].move_done = 1
  3161. self.npcs[y][x].num_special -= 1
  3162. tp_string = 'A ' + self.npcs[y][x].name + ' teleports.'
  3163. message.add(tp_string)
  3164. screen.write_hit_matrix(x,y,7)
  3165. sfx.play('teleport')
  3166. self.npcs[moves[pos_num][1]][moves[pos_num][0]] = self.npcs[y][x]
  3167. self.npcs[y][x] = 0
  3168. ran = random.randint(0,99)
  3169. if self.npcs[y][x] != 0:
  3170. if ran < self.npcs[y][x].def_flee and self.npcs[y][x].move_done != 1 and self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp:
  3171. flee_string = 'A ' + self.npcs[y][x].name + ' turns to flee.'
  3172. message.add(flee_string)
  3173. self.npcs[y][x].AI_style = 'flee'
  3174. self.npcs[y][x].move_done = 1
  3175. self.npcs[y][x].num_special -= 1
  3176. ran = random.randint(0,99)
  3177. if ran < self.npcs[y][x].def_potion and self.npcs[y][x].move_done != 1:
  3178. if self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp:
  3179. potion_string = 'A ' + self.npcs[y][x].name + ' quaffes a potion of healing.'
  3180. message.add(potion_string)
  3181. screen.write_hit_matrix(x,y,6)
  3182. lp = min(self.npcs[y][x].basic_attribute.max_lp, self.npcs[y][x].lp+7)
  3183. self.npcs[y][x].lp = lp
  3184. sfx.play('drink')
  3185. self.npcs[y][x].move_done = 1
  3186. self.npcs[y][x].num_special -= 1
  3187. if self.npcs[y][x] != 0:
  3188. if distances[0] > 1 and self.npcs[y][x].move_done != 1: #moves[0] is always the position of the monster right now, so distances 0 is always it's distance towards the player
  3189. ran = random.randint(0,99)
  3190. if ran < self.npcs[y][x].spawn_skeleton or ran < self.npcs[y][x].spawn_shadow or ran < self.npcs[y][x].spawn_spider or ran < self.npcs[y][x].spawn_crow:
  3191. coin = random.randint(0,1)
  3192. xlist = []
  3193. ylist = []
  3194. for yy in range(y-1,y+2):
  3195. for xx in range(x-1,x+2):
  3196. if self.tilemap[yy][xx].move_group == 'soil' and self.npcs[yy][xx] == 0:
  3197. xlist.append(xx)
  3198. ylist.append(yy)
  3199. if len(xlist) == len(ylist) and len(xlist) > 0:
  3200. if len(xlist) > 1:
  3201. num = random.randint(0,len(xlist)-1)
  3202. else:
  3203. num = 0
  3204. if self.npcs[y][x].spawn_skeleton > 0 and self.npcs[y][x].move_done != 1 and self.npcs[y][x].num_special > 0:
  3205. self.npcs[ylist[num]][xlist[num]] = deepcopy(ml.mlist['special'][7])
  3206. self.npcs[ylist[num]][xlist[num]].personal_id = self.npcs[y][x].personal_id + '_child'
  3207. self.set_monster_strength(xlist[num],ylist[num],player.pos[2])
  3208. mes = 'A ' + self.npcs[y][x].name + ' summons a skeleton.'
  3209. message.add(mes)
  3210. sfx.play('teleport')
  3211. screen.write_hit_matrix(xlist[num],ylist[num],7)
  3212. self.npcs[y][x].move_done = 1
  3213. self.npcs[y][x].num_special -= 1
  3214. if self.npcs[y][x].spawn_shadow > 0 and self.npcs[y][x].move_done != 1 and self.npcs[y][x].num_special > 0:
  3215. self.npcs[ylist[num]][xlist[num]] = deepcopy(ml.mlist['special'][8])
  3216. self.npcs[ylist[num]][xlist[num]].personal_id = self.npcs[y][x].personal_id + '_child'
  3217. self.set_monster_strength(xlist[num],ylist[num],player.pos[2])
  3218. mes = 'A ' + self.npcs[y][x].name + ' summons a shadow.'
  3219. message.add(mes)
  3220. sfx.play('teleport')
  3221. screen.write_hit_matrix(xlist[num],ylist[num],7)
  3222. self.npcs[y][x].move_done = 1
  3223. self.npcs[y][x].num_special -= 1
  3224. if self.npcs[y][x].spawn_crow > 0 and self.npcs[y][x].move_done != 1 and self.npcs[y][x].num_special > 0 and coin == 0:
  3225. self.npcs[ylist[num]][xlist[num]] = deepcopy(ml.mlist['special'][12])
  3226. self.npcs[ylist[num]][xlist[num]].personal_id = self.npcs[y][x].personal_id + '_child'
  3227. self.set_monster_strength(xlist[num],ylist[num],player.pos[2])
  3228. mes = 'A ' + self.npcs[y][x].name + ' summons a crow.'
  3229. message.add(mes)
  3230. sfx.play('teleport')
  3231. screen.write_hit_matrix(xlist[num],ylist[num],7)
  3232. self.npcs[y][x].move_done = 1
  3233. self.npcs[y][x].num_special -= 1
  3234. if self.npcs[y][x].spawn_spider > 0 and self.npcs[y][x].move_done != 1 and self.npcs[y][x].num_special > 0:
  3235. self.npcs[ylist[num]][xlist[num]] = deepcopy(ml.mlist['special'][13])
  3236. self.npcs[ylist[num]][xlist[num]].personal_id = self.npcs[y][x].personal_id + '_child'
  3237. self.set_monster_strength(xlist[num],ylist[num],player.pos[2])
  3238. mes = 'A ' + self.npcs[y][x].name + ' summons a spider.'
  3239. message.add(mes)
  3240. sfx.play('teleport')
  3241. screen.write_hit_matrix(xlist[num],ylist[num],7)
  3242. self.npcs[y][x].move_done = 1
  3243. self.npcs[y][x].num_special -= 1
  3244. elif ran < self.npcs[y][x].blink and self.npcs[y][x].move_done != 1 and self.npcs[y][x].num_special > 0:
  3245. xlist = []
  3246. ylist = []
  3247. for yy in range(player.pos[1]-3,player.pos[1]+4):
  3248. for xx in range(player.pos[0]-3,player.pos[0]+4):
  3249. if self.tilemap[yy][xx].move_group in self.npcs[y][x].move_groups and self.npcs[yy][xx] == 0:
  3250. if yy != player.pos[1] or xx != player.pos[0]:
  3251. xlist.append(xx)
  3252. ylist.append(yy)
  3253. if len(xlist) != 0:
  3254. try:
  3255. rand = random.randint(0,len(xlist)-1)
  3256. except:
  3257. rand = 0
  3258. screen.write_hit_matrix(x,y,7)
  3259. screen.write_hit_matrix(xlist[rand],ylist[rand],7)
  3260. mes = 'A '+self.npcs[y][x].name+' blinks!'
  3261. message.add(mes)
  3262. self.npcs[ylist[rand]][xlist[rand]] = self.npcs[y][x]
  3263. self.npcs[y][x] = 0
  3264. self.npcs[ylist[rand]][xlist[rand]].num_special -= 1
  3265. self.npcs[ylist[rand]][xlist[rand]].move_done = 1
  3266. if x == player.pos[0] or y == player.pos[1]:
  3267. straight_line = True
  3268. else:
  3269. straight_line = False
  3270. if self.npcs[y][x] != 0 and straight_line == True and (self.npcs[y][x].range_shoot != 0 or self.npcs[y][x].range_throw_stone !=0 or self.npcs[y][x].range_throw_dart !=0 or self.npcs[y][x].range_throw_knife !=0) and distances[0] < 5:
  3271. #Step 0: Random
  3272. ran = random.randint(0,99)
  3273. if (ran < self.npcs[y][x].range_shoot or ran < self.npcs[y][x].range_throw_stone or ran < self.npcs[y][x].range_throw_dart or ran < self.npcs[y][x].range_throw_knife) and self.npcs[y][x].num_special > 0 and self.npcs[y][x].move_done != 1:
  3274. #Step 1: find the right direction
  3275. if y > player.pos[1]:
  3276. y_dir = -1
  3277. elif y < player.pos[1]:
  3278. y_dir = 1
  3279. else:
  3280. y_dir = 0
  3281. if x > player.pos[0]:
  3282. x_dir = -1
  3283. elif x < player.pos[0]:
  3284. x_dir = 1
  3285. else:
  3286. x_dir = 0
  3287. #Step 2: Check for borders
  3288. run = True
  3289. count = 1
  3290. fire_free = True
  3291. while run:
  3292. cx = x + (count*x_dir)
  3293. cy = y + (count*y_dir)
  3294. if self.tilemap[cy][cx].transparency == False:
  3295. fire_free = False
  3296. run = False
  3297. count +=1
  3298. if cx == player.pos[0] and cy == player.pos[1]:
  3299. run = False
  3300. #Step 3: Fire!
  3301. if fire_free == True:
  3302. run = True
  3303. count = 1
  3304. if self.npcs[y][x].range_shoot > 0:
  3305. sfx.play('fire')
  3306. else:
  3307. sfx.play('miss')
  3308. while run:
  3309. xx = x + (count*x_dir)
  3310. yy = y + (count*y_dir)
  3311. if xx != player.pos[0] or yy != player.pos[1]:
  3312. screen.write_hit_matrix(xx,yy,2)
  3313. if self.tilemap[yy][xx].transparency == False:
  3314. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3315. if (self.npcs[y][x].range_shoot != 0 or self.npcs[y][x].range_throw_stone !=0 or self.npcs[y][x].range_throw_dart !=0 or self.npcs[y][x].range_throw_knife !=0):
  3316. sfx.play('throw')
  3317. run = False
  3318. else:
  3319. if self.npcs[y][x].range_shoot > 0:
  3320. self.npcs[y][x].move_done = 1
  3321. player.monster_attacks(x,y)
  3322. elif self.npcs[y][x].range_throw_stone > 0:
  3323. self.npcs[y][x].move_done = 1
  3324. message.add('A '+self.npcs[y][x].name+' throws a stone!')
  3325. chance = 9 - count
  3326. coin = random.randint(0,9)
  3327. if coin < chance:
  3328. sfx.play('hit')
  3329. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  3330. message.add('The stone hits you.(1 damage)')
  3331. player.lp -= 1
  3332. else:
  3333. sfx.play('throw')
  3334. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3335. message.add('The stone misses you.')
  3336. elif self.npcs[y][x].range_throw_dart > 0:
  3337. self.npcs[y][x].move_done = 1
  3338. message.add('A '+self.npcs[y][x].name+' throws a dart!')
  3339. chance = 9 - count
  3340. coin = random.randint(0,9)
  3341. if coin < chance:
  3342. sfx.play('hit')
  3343. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  3344. message.add('The dart hits you.(2 damage)')
  3345. player.lp -= 2
  3346. else:
  3347. sfx.play('throw')
  3348. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3349. message.add('The dart misses you.')
  3350. elif self.npcs[y][x].range_throw_knife > 0:
  3351. self.npcs[y][x].move_done = 1
  3352. message.add('A '+self.npcs[y][x].name+' throws a throwing knife')
  3353. chance = 9 - count
  3354. coin = random.randint(0,9)
  3355. if coin < chance:
  3356. sfx.play('hit')
  3357. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  3358. message.add('The throwing knife hits you.(3 damage)')
  3359. player.lp -= 3
  3360. else:
  3361. sfx.play('throw')
  3362. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3363. message.add('The throwing knife misses you.')
  3364. run = False
  3365. count += 1
  3366. self.npcs[y][x].move_done = 1
  3367. if (self.npcs[y][x].range_throw_stone !=0 or self.npcs[y][x].range_throw_dart !=0 or self.npcs[y][x].range_throw_knife !=0):
  3368. self.npcs[y][x].num_special -= 1
  3369. if self.npcs[y][x] != 0 and self.npcs[y][x].move_done == 0:
  3370. if len(moves) > 0:#if no move is possible at least the 'move' of stay still must remain
  3371. good_moves = []
  3372. for k in range (0, len(moves)):
  3373. if distances[k] < distances[0]:#if the possible move makes the distance between player and monster smaller
  3374. good_moves.append(moves[k])
  3375. else:
  3376. good_moves = moves
  3377. if len(good_moves) == 0:
  3378. good_moves = moves
  3379. if len(good_moves) > 1:
  3380. ran = random.randint(0,len(good_moves)-1)
  3381. else:
  3382. ran = 0
  3383. do_move = good_moves[ran]
  3384. else:
  3385. if self.npcs[y][x].move_done == 0:
  3386. #the most important thing about stealing monsters is that their default corps_style has to be 'thief' and their corps_lvl has to be 0. Otherwise they would not work proper.
  3387. if player.inventory.materials.gem > 0:
  3388. ran = random.randint(0,99)
  3389. if ran < self.npcs[y][x].close_steal:
  3390. player.inventory.materials.gem -= 1
  3391. self.npcs[y][x].corps_lvl += 1
  3392. screen.write_hit_matrix(player.pos[0],player.pos[1],8)
  3393. screen.write_hit_matrix(x,y,9)
  3394. sfx.play('steal')
  3395. steal_string = 'A ' + self.npcs[y][x].name + ' steals a gem from you.'
  3396. message.add(steal_string)
  3397. self.npcs[y][x].move_done = 1#set the move_done switch on
  3398. if self.npcs[y][x].move_done == 0:
  3399. #casting flames
  3400. ran = random.randint(0,99)
  3401. if ran < self.npcs[y][x].close_flame and self.npcs[y][x].num_special > 0:
  3402. #Step 0: Check if any (other) monsters are near by
  3403. sfx.play('flame')
  3404. monster_num = 0
  3405. for yy in range(y-1,y+2):
  3406. for xx in range(x-1,x+2):
  3407. if self.npcs[yy][xx] != 0:
  3408. monster_num += 1
  3409. if monster_num == 1:#there is no other monster near by
  3410. num_flames = 0
  3411. for yyy in range(y-1,y+2):
  3412. for xxx in range(x-1,x+2):
  3413. if xxx != x or yyy != y:
  3414. if self.tilemap[yyy][xxx].replace == None and self.tilemap[yyy][xxx].move_group != 'solid' and self.tilemap[yyy][xxx].move_group != 'low_liquid' and self.tilemap[yyy][xxx].move_group != 'swim':
  3415. replace = self.tilemap[yyy][xxx]
  3416. self.tilemap[yyy][xxx] = deepcopy(tl.tlist['effect'][4])
  3417. self.tilemap[yyy][xxx].replace = replace
  3418. self.countdowns.append(countdown('flame',xxx,yyy,3))
  3419. num_flames+=1
  3420. if num_flames > 0:
  3421. flame_string = 'A '+ self.npcs[y][x].name + ' casts a flame spell!'
  3422. message.add(flame_string)
  3423. self.npcs[y][x].num_special -= 1
  3424. self.npcs[y][x].move_done = 1
  3425. if self.npcs[y][x].move_done == 0 and self.npcs[y][x].num_special > 0:
  3426. #vampirism
  3427. ran = random.randint(0,99)
  3428. if ran < self.npcs[y][x].close_vampirism:
  3429. player.lp -= 1
  3430. self.npcs[y][x].lp += 1
  3431. screen.write_hit_matrix(player.pos[0],player.pos[1],18)
  3432. screen.write_hit_matrix(x,y,19)
  3433. sfx.play('vampire')
  3434. vamp_string = 'A ' + self.npcs[y][x].name +' sucks your blood.'
  3435. message.add(vamp_string)
  3436. self.npcs[y][x].num_special -= 1
  3437. self.npcs[y][x].move_done = 1
  3438. if self.npcs[y][x].move_done == 0 and self.npcs[y][x].num_special > 0:
  3439. #steal items
  3440. ran = random.randint(0,99)
  3441. if ran < self.npcs[y][x].close_stealItem:
  3442. #0: Find parent
  3443. parent_pos = False
  3444. parent_id = self.npcs[y][x].personal_id.replace('_child','')
  3445. for yy in range(0,max_map_size):
  3446. for xx in range(0,max_map_size):
  3447. if self.npcs[yy][xx] != 0 and self.npcs[yy][xx].personal_id == parent_id:
  3448. parent_pos = (xx,yy)
  3449. if parent_pos != False:
  3450. if len(self.containers[parent_pos[1]][parent_pos[0]].items) < 7:
  3451. p_check = True
  3452. else:
  3453. p_check = False
  3454. if p_check == True:
  3455. all_bp = ('Head','Body','Legs','Feet','Hold(R)','Hold(L)','Neck','Axe','Pickaxe','Hand')
  3456. final_bp = ['None',]
  3457. for i in range(0,len(all_bp)-1):
  3458. if player.inventory.wearing[all_bp[i]] != player.inventory.nothing:
  3459. final_bp.append(all_bp[i])
  3460. del final_bp[0]
  3461. if len(final_bp) > 0:
  3462. if len(final_bp) == 1:
  3463. ran = 0
  3464. else:
  3465. ran = random.randint(0,len(final_bp)-1)
  3466. item = player.inventory.wearing[final_bp[ran]]
  3467. player.inventory.wearing[final_bp[ran]] = player.inventory.nothing
  3468. self.containers[parent_pos[1]][parent_pos[0]].items.append(item)
  3469. mes = 'A '+self.npcs[y][x].name+' steals your '+item.name+'!'
  3470. message.add(mes)
  3471. sfx.play('steal')
  3472. screen.write_hit_matrix(player.pos[0],player.pos[1],21)
  3473. screen.write_hit_matrix(parent_pos[0],parent_pos[1],22)
  3474. self.npcs[y][x].lp = 0
  3475. if self.npcs[y][x].move_done == 0 and self.npcs[y][x].num_special > 0:
  3476. #throw explosives
  3477. ran = random.randint(0,99)
  3478. if ran < self.npcs[y][x].close_throwExplosive:
  3479. positions = []
  3480. for yy in range(player.pos[1]-1,player.pos[1]+2):
  3481. for xx in range(player.pos[0]-1,player.pos[0]+2):
  3482. if self.tilemap[yy][xx].replace == None and self.tilemap[yy][xx].move_group == 'soil' and self.tilemap[yy][xx].use_group == 'None':
  3483. positions.append((xx,yy))
  3484. if len(positions) > 0:
  3485. sfx.play('throw')
  3486. screen.write_hit_matrix(x,y,20)
  3487. ran = random.randint(0,len(positions)-1)
  3488. pos = positions[ran]
  3489. screen.write_hit_matrix(pos[0],pos[1],16)
  3490. coin = random.randint(0,3)
  3491. if coin == 0:
  3492. message.add('A '+self.npcs[y][x].name+' throws a bomb!')
  3493. replace = self.tilemap[pos[1]][pos[0]]
  3494. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['effect'][0])
  3495. self.countdowns.append(countdown('bomb3',pos[0],pos[1],1))
  3496. self.tilemap[pos[1]][pos[0]].replace = replace
  3497. else:
  3498. message.add('A '+self.npcs[y][x].name+' throws an explosive!')
  3499. replace = self.tilemap[pos[1]][pos[0]]
  3500. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['effect'][7])
  3501. self.tilemap[pos[1]][pos[0]].replace = replace
  3502. self.npcs[y][x].move_done = 1
  3503. self.npcs[y][x].num_special -= 1
  3504. if self.npcs[y][x].move_done == 0:
  3505. player.monster_attacks(x,y)
  3506. self.npcs[y][x].move_done = 1#set the move_done switch on
  3507. elif self.npcs[y][x].AI_style == 'flee':
  3508. if distances[0] < 2: #moves[0] is always the position of the monster right now, so distances 0 is always it's distance towards the player
  3509. if len(moves) > 1:
  3510. ran = random.randint(0,len(moves)-1)
  3511. else:
  3512. ran = 0
  3513. do_move = moves[ran]
  3514. else:
  3515. if len(moves) > 0:#if no move is possible at least the 'move' of stay still must remain
  3516. good_moves = []
  3517. for k in range (0, len(moves)):
  3518. if distances[k] > distances[0] or distances[k] == distances[0]:#if the possible move makes the distance between player and monster bigger or at least the same
  3519. good_moves.append(moves[k])
  3520. else:
  3521. good_moves = moves
  3522. if len(good_moves) == 0:
  3523. good_moves = moves
  3524. if len(good_moves) > 1:
  3525. ran = random.randint(0,len(good_moves)-1)
  3526. else:
  3527. ran = 0
  3528. do_move = good_moves[ran]
  3529. elif self.npcs[y][x].AI_style == 'ignore':
  3530. if len(moves) > 1:
  3531. ran = random.randint(0,len(moves)-1)
  3532. else:
  3533. ran = 0
  3534. do_move = moves[ran]
  3535. #IV. Move the monster
  3536. if do_move != 'foo':
  3537. border = random.randint(1,9)
  3538. if border > self.npcs[y][x].move_border:
  3539. self.npcs[y][x].move_done = 1#set the move_done switch on
  3540. helper = self.npcs[y][x]#copy the monster
  3541. self.npcs[y][x] = 0 #del the monster at the old position
  3542. self.npcs[do_move[1]][do_move[0]] = helper# set monster to the new position
  3543. def monster_die(self,x,y,xp = None):
  3544. #this function is called when the player kills a monster. the x and the y variables are to define the location of the monster
  3545. monster_x = x
  3546. monster_y = y
  3547. real_drop = False
  3548. if self.tilemap[y][x].replace == None:
  3549. test_replace = True
  3550. else:
  3551. test_replace = False
  3552. if self.npcs[monster_y][monster_x].corps_style == 'make_blobs':
  3553. test_replace = True
  3554. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' vanishes!'
  3555. if test_replace != True or self.tilemap[y][x].drops_here != True:
  3556. location_list = [(monster_x,monster_y),]
  3557. for yy in range(y-1,y+2):
  3558. for xx in range(x-1,x+2):
  3559. if self.tilemap[yy][xx].replace == None and self.npcs[yy][xx] == 0:
  3560. test_replace = True
  3561. else:
  3562. test_replace = False
  3563. if test_replace == True and self.tilemap[yy][xx].drops_here and self.tilemap[yy][xx].move_group == 'soil':
  3564. location_list.append((xx,yy))
  3565. if len(location_list) > 1:
  3566. del location_list[0]
  3567. if len(location_list) == 1:
  3568. x = location_list[0][0]
  3569. y = location_list[0][1]
  3570. else:
  3571. ran = random.randint(0,len(location_list)-1)
  3572. x = location_list[ran][0]
  3573. y = location_list[ran][1]
  3574. if test_replace == True and self.tilemap[y][x].drops_here: #only on empty fields corps can be spawned
  3575. if self.npcs[monster_y][monster_x].corps_style == 'dryade' and self.tilemap[y][x].techID != tl.tlist['misc'][0].techID and self.tilemap[y][x].can_grown: #dryades can leave behind a seppling when they are killed(corpse_lvl dosn't matter)/low water isn't allowed
  3576. coin = random.randint(0,99)
  3577. if coin < 50:#there is a chance of 50%
  3578. replace = self.tilemap[y][x]
  3579. self.tilemap[y][x] = tl.tlist['local'][10]#<---sepling
  3580. self.tilemap[y][x].replace = replace
  3581. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' turns into a new tree!'
  3582. elif self.npcs[monster_y][monster_x].corps_style == 'troll' and self.tilemap[y][x].techID != tl.tlist['misc'][0]: #trolls can leave behind a rock when they are killed(corpse_lvl dosn't matter)/low water isn't allowed
  3583. coin = random.randint(0,99)
  3584. if coin < 50:#there is a chance of 50%
  3585. replace = self.tilemap[y][x]
  3586. self.tilemap[y][x] = deepcopy(tl.tlist['local'][14])#<---rock
  3587. self.tilemap[y][x].replace = replace
  3588. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' turns to stone!'
  3589. elif self.npcs[monster_y][monster_x].corps_style == 'human': #humanoid monsters can leave behind humanoid remains when they die. the corps_lvl says how much items are stored inside them
  3590. coin = random.randint(0,99)
  3591. if coin < 15:#there is a chance of 15%
  3592. real_drop = True
  3593. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' dies!'
  3594. replace = self.tilemap[y][x]
  3595. self.tilemap[y][x] = deepcopy(tl.tlist['functional'][6])#<--humanoid remains
  3596. self.tilemap[y][x].replace = replace
  3597. items = []
  3598. max_items = max(1,self.npcs[monster_y][monster_x].corps_lvl)
  3599. for i in range (0, max_items):
  3600. #possible drops of a humanoid monster are equipment items and food items
  3601. coin = random.randint(0,99)
  3602. if coin < 65: #there is a chance of 65% that a item becomes a eqipment item
  3603. material = random.randint(0,20) #all materials are allowed
  3604. classes = ('spear','sword','axe','hammer','shoes','cuisse','helmet','armor','wand','rune','rune staff','artefact','ring','amulet','necklace','talisman','pickaxe')
  3605. kind = classes[random.randint(0,len(classes)-1)]#all classes of objects are allowed
  3606. plus = random.randint(-2,+2)# a plus between -2 and +2 is possible
  3607. state = random.randint(10,85)#the state of this used objects will always be between 10% and 80%
  3608. curse_chance = random.randint(0,30)
  3609. if curse_chance < material:
  3610. curse = 0
  3611. elif curse_chance == material:
  3612. curse = 2
  3613. else:
  3614. curse = 1
  3615. item = item_wear(kind,material,plus,state,curse)
  3616. elif coin < 68: #there is a chance of 3% to drop a simple blueprint
  3617. blueprint = random.randint(15,20)
  3618. item = deepcopy(il.ilist['misc'][blueprint])
  3619. elif coin < 80: #there is a chance of 12% to drop a torch or a throwable:
  3620. item_list = (il.ilist['misc'][44],il.ilist['misc'][44],il.ilist['misc'][44],il.ilist['misc'][78],il.ilist['misc'][79],il.ilist['misc'][80])
  3621. ran = random.randint(0,len(item_list)-1)
  3622. item = deepcopy(item_list[ran])
  3623. else:
  3624. coin2 = random.randint(0,1)
  3625. if coin == 1:
  3626. item = deepcopy(il.ilist['food'][random.randint(0,len(il.ilist['food'])-1)])
  3627. else:
  3628. item_list = (il.ilist['misc'][74],il.ilist['misc'][75],il.ilist['misc'][76],il.ilist['misc'][77])
  3629. ran = random.randint(0,len(item_list)-1)
  3630. item = deepcopy(item_list[ran])
  3631. items.append(item)
  3632. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  3633. elif self.npcs[monster_y][monster_x].corps_style == 'animal': #humanoid monsters can leave behind humanoid remains when they die. the corps_lvl says how much items are stored inside them
  3634. coin = random.randint(0,99)
  3635. if coin < 15:#there is a chance of 15%
  3636. real_drop = True
  3637. replace = self.tilemap[y][x]
  3638. self.tilemap[y][x] = deepcopy(tl.tlist['functional'][21])#<--animal remains
  3639. self.tilemap[y][x].replace = replace
  3640. items = []
  3641. max_items = max(1,self.npcs[monster_y][monster_x].corps_lvl)
  3642. for i in range (0, max_items):
  3643. #animals drop flesh. the corpslvl says how much
  3644. items.append(deepcopy(il.ilist['food'][9]))#<---raw meat
  3645. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  3646. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' dies!'
  3647. elif self.npcs[monster_y][monster_x].corps_style == 'scrollkeeper': #scrollkeepers can leave behind humanoid remains with scrolls and spellbooks when they die. the corps_lvl says how much items are stored inside them
  3648. coin = random.randint(0,99)
  3649. if coin < 10:#there is a chance of 10%
  3650. real_drop = True
  3651. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' dies!'
  3652. replace = self.tilemap[y][x]
  3653. self.tilemap[y][x] = deepcopy(tl.tlist['functional'][6])#<--humanoid remains
  3654. self.tilemap[y][x].replace = replace
  3655. items = []
  3656. max_items = max(1,self.npcs[monster_y][monster_x].corps_lvl)
  3657. for i in range (0, max_items):
  3658. #possible drops of a scrollkeeper are scrolls and spellbooks
  3659. coin = random.randint(0,99)
  3660. if coin < 75: #there is a chance of 75% that a item becomes a scroll
  3661. scrolls = (il.ilist['misc'][25],il.ilist['misc'][27],il.ilist['misc'][29],il.ilist['misc'][31],il.ilist['misc'][33],il.ilist['misc'][35],il.ilist['misc'][37],il.ilist['misc'][45])
  3662. ran = random.randint(0,len(scrolls)-1)
  3663. item = deepcopy(scrolls[ran])
  3664. else:
  3665. books = (il.ilist['misc'][26],il.ilist['misc'][30],il.ilist['misc'][32],il.ilist['misc'][34],il.ilist['misc'][36],il.ilist['misc'][38],il.ilist['misc'][46])
  3666. ran = random.randint(0,len(books)-1)
  3667. item = deepcopy(books[ran])
  3668. items.append(item)
  3669. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  3670. elif self.npcs[monster_y][monster_x].corps_style == 'miner':
  3671. if self.npcs[monster_y][monster_x].techID == ml.mlist['special'][0].techID:#this is a vase
  3672. die_mess = 'The vase shatters.'
  3673. ran = random.randint(0,99)
  3674. if ran <= self.npcs[monster_y][monster_x].corps_lvl: #for miners the corps_lvl determinates the chance of getting a gem
  3675. real_drop = True
  3676. replace = self.tilemap[y][x]
  3677. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][9])#set a lost gem
  3678. self.tilemap[y][x].replace = replace
  3679. elif ran <= self.npcs[monster_y][monster_x].corps_lvl*4:#for miners the corps_lvl determinates the chance of getting some ore. Its the chance to get a gem * 3
  3680. real_drop = True
  3681. replace = self.tilemap[y][x]
  3682. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][11])#set a lost ore
  3683. self.tilemap[y][x].replace = replace
  3684. elif self.npcs[monster_y][monster_x].corps_style == 'thief':
  3685. if self.tilemap[y][x].replace == None and self.npcs[monster_y][monster_x].corps_lvl > 0:
  3686. real_drop = True
  3687. replace = self.tilemap[y][x]
  3688. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][9])#set a lost gem
  3689. self.tilemap[y][x].replace = replace
  3690. self.tilemap[y][x].conected_resources = ('gem',self.npcs[monster_y][monster_x].corps_lvl)#for thiefs the corps lvl determinates the number of gems they are dropping
  3691. elif self.npcs[monster_y][monster_x].corps_style == 'reset_parent':
  3692. parent_id = self.npcs[monster_y][monster_x].personal_id.replace('_child','')
  3693. for yy in range(0,max_map_size):
  3694. for xx in range(0,max_map_size):
  3695. if self.npcs[yy][xx] != 0:
  3696. if self.npcs[yy][xx].personal_id == parent_id:
  3697. self.npcs[yy][xx].num_special += 1
  3698. elif self.npcs[monster_y][monster_x].corps_style == 'kill_childs':
  3699. child_id = self.npcs[monster_y][monster_x].personal_id + '_child'
  3700. for yy in range(0,max_map_size):
  3701. for xx in range(0,max_map_size):
  3702. if self.npcs[yy][xx] != 0:
  3703. if self.npcs[yy][xx].personal_id == child_id:
  3704. self.npcs[yy][xx] = 0
  3705. elif self.npcs[monster_y][monster_x].corps_style == 'kobold_fear':
  3706. for yy in range(y-7,y+8):
  3707. for xx in range(x-7,x+8):
  3708. try:
  3709. if self.npcs[yy][xx].techID == ml.mlist['kobold'][1].techID and self.npcs[yy][xx].name != 'frightened kobold':
  3710. self.npcs[yy][xx] = deepcopy(self.npcs[yy][xx])#only to be sure
  3711. self.npcs[yy][xx].name = 'frightened kobold'
  3712. self.npcs[yy][xx].sprite_pos = (5,3)
  3713. self.npcs[yy][xx].basic_attribute.p_strength = int(self.npcs[yy][xx].basic_attribute.p_strength*0.6)
  3714. self.npcs[yy][xx].basic_attribute.m_strength = int(self.npcs[yy][xx].basic_attribute.m_strength*0.6)
  3715. self.npcs[yy][xx].basic_attribute.p_defense = int(self.npcs[yy][xx].basic_attribute.p_defense*0.6)
  3716. self.npcs[yy][xx].basic_attribute.m_defense = int(self.npcs[yy][xx].basic_attribute.m_defense*0.6)
  3717. screen.write_hit_matrix(xx,yy,17)
  3718. coin = random.randint(0,1)
  3719. if coin == 1:
  3720. self.npcs[yy][xx].AI_style = 'flee'
  3721. except:
  3722. None
  3723. elif self.npcs[monster_y][monster_x].corps_style == 'vase':
  3724. die_mess = 'The vase shatters and monsters jump out.'
  3725. monster_count = 0
  3726. for yy in range(y-1,y+2):
  3727. for xx in range(x-1,x+2):
  3728. if yy != player.pos[1] or xx!= player.pos[0]:
  3729. if self.npcs[yy][xx] == 0 and self.tilemap[yy][xx].move_group == 'soil' and self.tilemap[yy][xx].damage == 0:
  3730. self.npcs[yy][xx] = deepcopy(ml.mlist['special'][2])#set vase monsters
  3731. self.set_monster_strength(xx,yy,player.pos[2])
  3732. if player.difficulty == 4:
  3733. self.npcs[yy][xx].AI_style = 'ignore'
  3734. monster_count += 1
  3735. if monster_count > 0:
  3736. die_mess = 'The vase shatters and '+str(monster_count)+' monsters jump out.'
  3737. else:
  3738. die_mess = 'The vase shatters.'
  3739. elif self.npcs[monster_y][monster_x].corps_style == 'mimic':
  3740. die_mess = 'The mimic wakes up.'
  3741. elif self.npcs[monster_y][monster_x].corps_style == 'cage_low' or self.npcs[monster_y][monster_x].corps_style == 'cage_medium' or self.npcs[monster_y][monster_x].corps_style == 'cage_high':
  3742. die_mess = 'You smash the cage!'
  3743. sfx.play('destroy_cage')
  3744. elif self.npcs[monster_y][monster_x].corps_style == 'make_blobs':
  3745. counter = 0
  3746. blob_lvl = max(self.npcs[monster_y][monster_x].lvl-1,0)
  3747. for yy in range(y-1,y+2):
  3748. for xx in range(x-1,x+2):
  3749. if yy != y or xx != x:
  3750. not_player_pos = yy != player.pos[1] or xx != player.pos[0]
  3751. if self.tilemap[yy][xx].move_group == 'soil' and not_player_pos == True and self.npcs[yy][xx] == 0:
  3752. self.npcs[yy][xx] = deepcopy(ml.mlist['overworld'][3])#set a green blob
  3753. self.set_monster_strength(xx,yy,player.pos[2],preset_lvl=blob_lvl)
  3754. if player.difficulty == 4:
  3755. self.npcs[yy][xx].AI_style = 'ignore'
  3756. counter += 1
  3757. if counter == 1:
  3758. die_mess = 'The giant blob leaves behind a small blob.'
  3759. elif counter > 1:
  3760. die_mess = 'The giant blob bursts into '+str(counter)+' small blobs.'
  3761. elif self.npcs[monster_y][monster_x].corps_style == 'vanish':
  3762. ran = random.randint(0,99)
  3763. if ran <= self.npcs[monster_y][monster_x].corps_lvl: #the corps_lvl determinates the chance of getting a present
  3764. real_drop = True
  3765. replace = self.tilemap[y][x]
  3766. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][13])#set a present
  3767. self.tilemap[y][x].replace = replace
  3768. item_ran = random.randint(0,99)
  3769. if item_ran < 25:
  3770. items = [il.ilist['misc'][43]]#set a heavy bag
  3771. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  3772. elif item_ran < 50:
  3773. choose_ran = random.randint(0,len(il.ilist['clothe'])-1)
  3774. items = [il.ilist['clothe'][choose_ran]]
  3775. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  3776. elif item_ran < 95:
  3777. r = random.randint(3,7)
  3778. items = [il.ilist['misc'][r]]#set a workbench
  3779. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  3780. else:
  3781. items = [il.ilist['misc'][70]]#set a book of skill
  3782. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  3783. ############ADD MORE HERE###############
  3784. if real_drop == True:
  3785. screen.write_hit_matrix(x,y,16)
  3786. if self.npcs[monster_y][monster_x].move_border < 10:
  3787. screen.write_hit_matrix(monster_x,monster_y,13)
  3788. if self.npcs[monster_y][monster_x].corps_style == 'mimic':
  3789. self.npcs[monster_y][monster_x] = deepcopy(ml.mlist['special'][4])#set a mimic
  3790. self.set_monster_strength(monster_x,monster_y,player.pos[2])
  3791. if player.difficulty == 4:
  3792. self.npcs[monster_y][monster_x].AI_style = 'ignore'
  3793. elif self.npcs[monster_y][monster_x].corps_style == 'cage_low' or self.npcs[monster_y][monster_x].corps_style == 'cage_medium' or self.npcs[monster_y][monster_x].corps_style == 'cage_high':
  3794. list_name = self.npcs[monster_y][monster_x].corps_style.replace('cage_','')
  3795. player.villager[list_name].append(self.npcs[monster_y][monster_x].corps_lvl)
  3796. self.npcs[monster_y][monster_x] = deepcopy(ml.mlist['rescued'][self.npcs[monster_y][monster_x].corps_lvl])
  3797. self.set_monster_strength(monster_x,monster_y,player.pos[2])
  3798. else:
  3799. self.npcs[monster_y][monster_x] = 0 #always del the monster if it is no mimic or cage
  3800. self.make_monsters_angry(monster_x,monster_y,'kill')
  3801. self.monster_count -= 1
  3802. if xp != None:
  3803. die_mess = die_mess + ' [+' + str(xp) + 'xp]'
  3804. message.add(die_mess)
  3805. return True
  3806. def make_shops(self):
  3807. num = int((max_map_size*max_map_size) / (50*50))
  3808. for i in range (0,num):
  3809. run = True
  3810. while run:
  3811. poses = self.find_all_moveable(False,False)
  3812. ran = random.randint(0,len(poses)-1)
  3813. pos = poses[ran]
  3814. if min(pos[0],pos[1]) > 4 and max(pos[0],pos[1]) < max_map_size-4:
  3815. run = False
  3816. x = pos[0]
  3817. y = pos[1]
  3818. for yy in range(y-2,y+3):
  3819. for xx in range(x-2,x+3):
  3820. self.npcs[yy][xx] = 0 #always del the monsters
  3821. if xx == x-2 or xx == x+2 or yy == y-2 or yy == y+2:
  3822. self.tilemap[yy][xx] = deepcopy(tl.tlist['shop'][1])
  3823. else:
  3824. self.tilemap[yy][xx] = deepcopy(tl.tlist['shop'][0])
  3825. self.tilemap[y][x-2] = deepcopy(tl.tlist['shop'][2])
  3826. self.tilemap[y][x+2] = deepcopy(tl.tlist['shop'][2])
  3827. self.tilemap[y-2][x] = deepcopy(tl.tlist['shop'][2])
  3828. self.tilemap[y+2][x] = deepcopy(tl.tlist['shop'][2])
  3829. if self.map_type == 'orcish_mines':
  3830. self.npcs[y][x] = deepcopy(ml.mlist['shop'][1])
  3831. elif self.map_type == 'grot':
  3832. self.npcs[y][x] = deepcopy(ml.mlist['shop'][2])
  3833. else:
  3834. self.npcs[y][x] = deepcopy(ml.mlist['shop'][0])#the elfish shopkeeper is only for fallback...In the elfish fortress the shops are spawned on a other way
  3835. def make_monsters_angry(self,x,y,style):
  3836. for yy in range(y-3,y+4):
  3837. for xx in range(x-3,x+4):
  3838. try:
  3839. if self.npcs[yy][xx] != 0:
  3840. if self.npcs[yy][xx].anger == style:
  3841. lvl = self.npcs[yy][xx].lvl
  3842. self.npcs[yy][xx] = deepcopy(ml.mlist['angry_monster'][self.npcs[yy][xx].anger_monster])
  3843. self.set_monster_strength(xx,yy,player.pos[2],lvl)
  3844. if player.difficulty == 4:
  3845. self.npcs[yy][xx].AI_style = 'ignore'
  3846. except:
  3847. None
  3848. def time_pass(self):
  3849. #This function refresches the map for every day that past since players last visit... make plants growing etc.
  3850. if self.last_visit != time.day_total:
  3851. screen.render_load(10)
  3852. past_time = time.day_total - self.last_visit
  3853. if past_time < 0:
  3854. past_time = 364 - past_time
  3855. for c in range (0,past_time):
  3856. for y in range (0,max_map_size):
  3857. for x in range(0,max_map_size):
  3858. tile = self.tilemap[y][x]
  3859. #######Life of plants######
  3860. #1. Scrub
  3861. if tile.grow_group == 'scrub':
  3862. rand = random.randint(0,99)
  3863. if rand < 50:
  3864. replace = self.tilemap[y][x].replace
  3865. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  3866. self.tilemap[y][x].replace = replace
  3867. if tile.grow_group == 'scrub_buds':
  3868. rand = random.randint(0,99)
  3869. if rand < 90:
  3870. replace = self.tilemap[y][x].replace
  3871. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  3872. self.tilemap[y][x].replace = replace
  3873. if tile.grow_group == 'scrub_blossom':
  3874. rand = random.randint(0,99)
  3875. if rand < 80:
  3876. scrubs = random.randint(0,2)
  3877. replace = self.tilemap[y][x].replace
  3878. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[scrubs][0]][tile.conected_tiles[scrubs][1]])
  3879. self.tilemap[y][x].replace = replace
  3880. if tile.grow_group == 'scrub_berries':
  3881. rand = random.randint(0,99)
  3882. if rand < 50:
  3883. replace = self.tilemap[y][x].replace
  3884. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  3885. self.tilemap[y][x].replace = replace
  3886. elif rand > 49 and rand < 75:
  3887. numbers =(-1,1)
  3888. for yy in numbers:
  3889. for xx in numbers:
  3890. try:
  3891. if self.tilemap[y+yy][x+xx].can_grown == True:
  3892. coin = random.randint(0,99)
  3893. if coin < 25: #25%
  3894. replace = self.tilemap[y+yy][x+xx]
  3895. self.tilemap[y+yy][x+xx] = deepcopy([tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  3896. self.tilemap[y+yy][x+xx].replace = replace
  3897. except:
  3898. None
  3899. if tile.grow_group == 'scrub_scruffy':
  3900. rand = random.randint(0,99)
  3901. if rand < 90:
  3902. replace = self.tilemap[y][x].replace
  3903. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  3904. self.tilemap[y][x].replace = replace
  3905. else:
  3906. replace = self.tilemap[y][x].replace
  3907. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  3908. self.tilemap[y][x].replace = replace
  3909. if tile.grow_group == 'scrub_grow':
  3910. rand = random.randint(0,99)
  3911. if rand < 90:
  3912. replace = self.tilemap[y][x].replace
  3913. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  3914. self.tilemap[y][x].replace = replace
  3915. #2.Tree
  3916. if tile.grow_group == 'tree_grow':
  3917. rand = random.randint(0,99)
  3918. if rand < 80 and self.npcs[y][x] == 0:
  3919. replace = self.tilemap[y][x].replace
  3920. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  3921. self.tilemap[y][x].replace = replace
  3922. if tile.grow_group == 'tree':
  3923. rand = random.randint(0,99)
  3924. if rand < 5:
  3925. replace = self.tilemap[y][x].replace
  3926. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  3927. self.tilemap[y][x].replace = replace
  3928. elif rand > 69:
  3929. numbers =(-2,2)
  3930. for yy in numbers:
  3931. for xx in numbers:
  3932. try:
  3933. if self.tilemap[y+yy][x+xx].can_grown == True:
  3934. coin = random.randint(0,3)
  3935. if coin == 0:
  3936. replace = self.tilemap[y+yy][x+xx]
  3937. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  3938. self.tilemap[y+yy][x+xx].replace = replace
  3939. except:
  3940. None
  3941. #3.Herb
  3942. if tile.grow_group == 'herblike':
  3943. rand = random.randint(0,99)
  3944. if rand < 20:
  3945. replace = self.tilemap[y][x].replace
  3946. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  3947. self.tilemap[y][x].replace = replace
  3948. #4. Blue Mushrooms
  3949. if tile.grow_group == 'mushroom_mud':
  3950. rand = random.randint(0,99)
  3951. if rand < 5:
  3952. for yy in range(-1,1):
  3953. for xx in range(-1,1):
  3954. try:
  3955. if self.tilemap[y+yy][x+xx].techID == tl.tlist['misc'][1].techID:#here is mud
  3956. cent = random.randint(0,99)
  3957. if cent < 25 :
  3958. replace = self.tilemap[y+yy][x+xx]
  3959. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  3960. self.tilemap[y+yy][x+xx].replace = replace
  3961. except:
  3962. None
  3963. #5. Brown Mushrooms
  3964. if tile.grow_group == 'mushroom_treelike':
  3965. rand = random.randint(0,99)
  3966. if rand < 5:
  3967. for yy in range(-1,1):
  3968. for xx in range(-1,1):
  3969. try:
  3970. if self.tilemap[y+yy][x+xx].techID == tl.tlist['global_caves'][0].techID:#here is cave ground
  3971. cent = random.randint(0,99)
  3972. if cent < 25 :
  3973. replace = self.tilemap[y+yy][x+xx]
  3974. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  3975. self.tilemap[y+yy][x+xx].replace = replace
  3976. except:
  3977. None
  3978. elif rand < 30:#make a giant mushroom
  3979. replace = self.tilemap[y][x].replace
  3980. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  3981. self.tilemap[y][x].replace = replace
  3982. #6. Purple Mushrooms
  3983. if tile.grow_group == 'mushroom': #let grow new mushrooms and let the old ones die(5%)
  3984. rand = random.randint(0,99)
  3985. if rand < 5:
  3986. for yy in range(-1,1):
  3987. for xx in range(-1,1):
  3988. try:
  3989. if self.tilemap[y+yy][x+xx].techID == tl.tlist['global_caves'][0].techID:#here is cave ground
  3990. cent = random.randint(0,99)
  3991. if cent < 25 :
  3992. replace = self.tilemap[y+yy][x+xx]
  3993. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  3994. self.tilemap[y+yy][x+xx].replace = replace
  3995. except:
  3996. None
  3997. #7. Agriculture
  3998. if tile.grow_group == 'agri0':
  3999. rand = random.randint(0,99)
  4000. if rand < 50:
  4001. if self.map_type == 'overworld':
  4002. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]]
  4003. elif self.map_type == 'cave' or self.map_type == 'desert_cave':
  4004. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]]
  4005. elif self.map_type == 'desert':
  4006. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[2][0]][tile.conected_tiles[2][1]]
  4007. if tile.grow_group == 'agri1': #let something grow on a acriculture (final, at the overworld) (50%)
  4008. rand = random.randint(0,99)
  4009. if rand < 50:
  4010. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]]
  4011. #8. Vanish
  4012. if tile.grow_group == 'vanish':
  4013. rand = random.randint(0,99)
  4014. if rand < 50:
  4015. self.tilemap[y][x] = self.tilemap[y][x].replace
  4016. self.containers[y][x] = 0
  4017. #9. Magic shops
  4018. if tile.techID == tl.tlist['shop'][4].techID and player.on_map != 'shop_0_0':
  4019. self.tilemap[y][x] = self.tilemap[y][x].replace
  4020. #######Misc#######
  4021. #0. Rubble
  4022. if tile.techID == tl.tlist['functional'][26].techID:
  4023. rand = random.randint(0,99)
  4024. if rand < 20:
  4025. count_rubble = 0
  4026. count_sand = 0
  4027. count_grass = 0
  4028. count_cave = 0
  4029. for yy in range(y-1,y+2):
  4030. for xx in range(x-1,x+2):
  4031. if self.tilemap[yy][xx].techID == tl.tlist['functional'][26]:#this is rubble
  4032. count_rubble += 1
  4033. elif self.tilemap[yy][xx].techID == tl.tlist['local'][0]:#this is grass
  4034. count_grass += 1
  4035. elif self.tilemap[yy][xx].techID == tl.tlist['extra'][0]:#this is sand
  4036. count_sand += 1
  4037. elif self.tilemap[yy][xx].techID == tl.tlist['global_caves'][0]:#this is cave
  4038. count_cave +=1
  4039. if count_rubble < 8: #this tile isnt surrounded by rubble
  4040. if count_cave > 1:
  4041. self.tilemap[y][x] = deepcopy(tl.tlist['global_caves'][0])
  4042. elif count_grass >= count_sand:
  4043. self.tilemap[y][x] = deepcopy(tl.tlist['local'][0])
  4044. else:
  4045. self.tilemap[y][x] = deepcopy(tl.tlist['extra'][0])
  4046. #########add other events for growing plants etc here########
  4047. self.last_visit = time.day_total #change the day of last visit to today to prevent the map of changed a second time for this day
  4048. for i in range(0,len(player.inventory.food)):#let the food rot in the players inventory
  4049. if player.inventory.food[i] != player.inventory.nothing:
  4050. player.inventory.food[i].rot()
  4051. if player.on_map != 'shop_0_0':
  4052. shop_num = int((max_map_size**2)/(50**2))
  4053. self.spawn_magic_shops(shop_num)
  4054. screen.render_load(5)
  4055. save(world,player,time,gods,save_path,os.sep)
  4056. def exchange(self,old_tile,new_tile,use_deepcopy=False):
  4057. for y in range (0,max_map_size):
  4058. for x in range (0,max_map_size):
  4059. if self.tilemap[y][x].techID == old_tile.techID:
  4060. if use_deepcopy == False:
  4061. self.tilemap[y][x] = new_tile
  4062. else:
  4063. self.tilemap[y][x] = deepcopy(new_tile)
  4064. def find_first(self,tile):
  4065. for y in range (0,max_map_size):
  4066. for x in range (0,max_map_size):
  4067. if self.tilemap[y][x].techID == tile.techID:
  4068. return [x,y]
  4069. if self.tilemap[y][x].name == tile.name:#fallback
  4070. return [x,y] #
  4071. return False
  4072. def find_any(self,tile):
  4073. found = []
  4074. for y in range(0,max_map_size):
  4075. for x in range(0,max_map_size):
  4076. if self.tilemap[y][x].techID == tile.techID and self.npcs[y][x] == 0:
  4077. found.append((x,y))
  4078. if found == []:
  4079. return False
  4080. elif len(found) == 1:
  4081. return found[0]
  4082. else:
  4083. ran = random.randint(0,len(found)-1)
  4084. return found[ran]
  4085. def find_all_moveable(self,ignore_water = True,ignore_player_pos = False, ignore_no_spawn = True):
  4086. cordinates_list = []
  4087. for y in range (0, max_map_size):
  4088. for x in range (0,max_map_size):
  4089. moveable = False
  4090. if ignore_water == True:
  4091. if self.tilemap[y][x].move_group == 'soil':
  4092. moveable = True
  4093. else:
  4094. if self.tilemap[y][x].move_group == 'soil' or self.tilemap[y][x].move_group == 'low_liquid':
  4095. moveable = True
  4096. if ignore_player_pos == True:
  4097. player_pos_check = False
  4098. else:
  4099. if (x - entrance_x < -7) or (y - entrance_y < -7) or (x - entrance_x > 7) or (y - entrance_y > 7):
  4100. player_pos_check = False
  4101. else:
  4102. player_pos_check = True
  4103. spawn_check = True
  4104. if ignore_no_spawn == False:
  4105. if self.tilemap[y][x].no_spawn == True:
  4106. spawn_check = False
  4107. if (moveable == True) and (self.tilemap[y][x].damage == False) and (player_pos_check == False) and (spawn_check == True) and self.npcs[y][x] == 0:
  4108. cordinates_list.append((x,y))
  4109. if len(cordinates_list) > 0:
  4110. return cordinates_list
  4111. else:
  4112. return False
  4113. def add_container(self, inventory, x, y, deep_copy = True, checkIt = False):
  4114. self.containers[y][x] = container(inventory,deep_copy)
  4115. if checkIt == True:
  4116. if self.check_container(x,y) != True:
  4117. print('Container creation failed!')
  4118. self.containers[y][x] = 0
  4119. self.tilemap[y][x] = self.tilemap[y][x].replace
  4120. def check_container(self,x,y):
  4121. if self.tilemap[y][x].replace != None and len(self.containers[y][x].items) > 0:
  4122. return True
  4123. else:
  4124. return False
  4125. def special_check(self,x,y):
  4126. sfx_flame = False
  4127. sfx_vapor = False
  4128. for yy in range(y-7,y+8):
  4129. for xx in range(x-7,x+8):
  4130. try:
  4131. if (self.tilemap[yy][xx].special_group == 'flamable' or self.tilemap[yy][xx].special_group == 'highly flamable') and self.tilemap[yy][xx].replace != None:
  4132. heat_source = 0
  4133. for yyy in range(yy-1,yy+2):
  4134. for xxx in range(xx-1,xx+2):
  4135. try:
  4136. if self.tilemap[yyy][xxx].special_group == 'hot':
  4137. heat_source += 1
  4138. except:
  4139. None
  4140. if heat_source > 0:
  4141. if self.tilemap[yy][xx].special_group == 'flamable':
  4142. ran = random.randint(0,9)
  4143. else:
  4144. ran = 9
  4145. if ran > 5:
  4146. sfx_flame = True
  4147. self.containers[yy][xx] = 0
  4148. self.countdowns.append(countdown('flame',xx,yy,self.tilemap[yy][xx].special_num))
  4149. replace = self.tilemap[yy][xx].replace
  4150. self.tilemap[yy][xx] = deepcopy(tl.tlist['effect'][4])
  4151. self.tilemap[yy][xx].replace = replace
  4152. elif self.tilemap[yy][xx].special_group == 'explosive' or self.tilemap[yy][xx].special_group == 'highly explosive':
  4153. heat_sources = 0
  4154. for yyy in range(yy-1,yy+2):
  4155. for xxx in range(xx-1,xx+2):
  4156. try:
  4157. if self.tilemap[yyy][xxx].special_group == 'hot':
  4158. heat_sources += 1
  4159. except:
  4160. None
  4161. if heat_sources > 0:
  4162. if self.tilemap[yyy][xxx].special_group == 'explosive':
  4163. ran = random.randint(0,9)
  4164. else:
  4165. ran = 9
  4166. if ran > 5:
  4167. self.countdowns.append(countdown('bomb1',xx,yy,1))
  4168. for yyy in range(yy-1,yy+2):
  4169. for xxx in range(xx-1,xx+2):
  4170. try:
  4171. if self.tilemap[yyy][xxx].special_group == 'explosive' or elf.tilemap[yyy][xxx].special_group == 'highly explosive':
  4172. self.countdowns.append(countdown('bomb1',xxx,yyy,1))
  4173. except:
  4174. None
  4175. elif self.tilemap[yy][xx].special_group == 'vaporable':
  4176. heat_sources = 0
  4177. for yyy in range(yy-1,yy+2):
  4178. for xxx in range(xx-1,xx+2):
  4179. try:
  4180. if self.tilemap[yyy][xxx].special_group == 'hot':
  4181. heat_sources += 1
  4182. except:
  4183. None
  4184. if heat_sources >= self.tilemap[yy][xx].special_num:
  4185. sfx.vapor = True
  4186. self.tilemap[yy][xx] = deepcopy(tl.tlist['misc'][1])#mud
  4187. except:
  4188. None
  4189. if sfx_flame == True:
  4190. sfx.play('flame')
  4191. if sfx_vapor == True:
  4192. sfx.play('steam')
  4193. def spawn_monster_groups(self,leader,follower,max_group_size):
  4194. for y in range(0,max_map_size):
  4195. for x in range(0,max_map_size):
  4196. if self.npcs[y][x] != 0 and self.npcs[y][x].techID == leader.techID:
  4197. m_count = 1
  4198. for yy in range(y-1,y+2):
  4199. for xx in range(x-1,x+2):
  4200. if m_count < max_group_size and self.npcs[yy][xx] == 0 and self.tilemap[yy][xx].move_group in follower.move_groups:
  4201. self.npcs[yy][xx] = deepcopy(follower)
  4202. self.set_monster_strength(xx,yy,max(self.npcs[y][x].lvl-5,1))
  4203. if player.difficulty == 4:
  4204. self.npcs[yy][xx].AI_style = 'ignore'
  4205. m_count += 1
  4206. def make_special_monsters(self, min_no, max_no, on_tile, depth, monster_type='vase'):
  4207. size = int((max_map_size*max_map_size)/(50*50))
  4208. for i in range(0,size):
  4209. num_monster = random.randint(min_no,max_no)
  4210. if num_monster > 0:
  4211. for z in range (0,num_monster):
  4212. pos = self.find_any(on_tile)
  4213. if monster_type == 'vase':
  4214. ran = random.randint(0,99)
  4215. if ran < 10:
  4216. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][1]) #spawn a monster vase
  4217. self.npcs[pos[1]][pos[0]].attribute = attribute(0,0,0,0,0,1,0)
  4218. else:
  4219. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][0]) #spawn a vase
  4220. self.npcs[pos[1]][pos[0]].attribute = attribute(0,0,0,0,0,1,0)
  4221. elif monster_type == 'mimic':
  4222. pos = self.find_any(on_tile)
  4223. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][3]) #spawn a sleeping mimic
  4224. self.npcs[pos[1]][pos[0]].attribute = attribute(0,0,0,0,0,1,0)
  4225. elif monster_type == 'demonic chest':
  4226. pos = self.find_any(on_tile)
  4227. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][4])#cest
  4228. self.tilemap[pos[1]][pos[0]].replace = deepcopy(on_tile)
  4229. sb = (il.ilist['misc'][26],il.ilist['misc'][30],il.ilist['misc'][32],il.ilist['misc'][34],il.ilist['misc'][36],il.ilist['misc'][38])
  4230. ran1 = random.randint(0,len(sb)-1)
  4231. ran2 = random.randint(0,len(sb)-1)
  4232. items = [sb[ran1],sb[ran2]]
  4233. self.containers[pos[1]][pos[0]] = container(items,True)
  4234. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][14])
  4235. self.set_monster_strength(pos[0],pos[1],depth)
  4236. #set monsters personal_id
  4237. self.npcs[pos[1]][pos[0]].personal_id = str(self.npcs[pos[1]][pos[0]].techID)+'_'+str(pos[0])+'_'+str(pos[1])+'_'+str(random.randint(0,9999))
  4238. def make_containers(self, min_no, max_no, on_tile, item_min, item_max, container_type='remains'):
  4239. size = int((max_map_size*max_map_size)/(50*50))
  4240. for i in range(0,size):
  4241. num_container = random.randint(min_no,max_no)
  4242. if num_container > 0:
  4243. for z in range (0,num_container):
  4244. c_type = container_type
  4245. if c_type == 'chest':
  4246. ch = random.randint(0,99)
  4247. if ch < 5:
  4248. c_type = 'fridge'
  4249. place = self.find_any(on_tile)
  4250. inventory = []
  4251. num_items = random.randint(item_min,item_max)##############item_min,item_max
  4252. for t in range (0,num_items):
  4253. if c_type == 'chest':
  4254. coin = random.randint(0,1)
  4255. if coin == 0:#add equipmen
  4256. classes = ['sword', 'axe', 'hammer', 'spear', 'helmet', 'armor', 'cuisse', 'shoes', 'wand', 'rune', 'rune staff', 'artefact', 'amulet', 'ring', 'talisman', 'necklace', 'pickaxe']
  4257. class_num = random.randint(0,len(classes)-1)
  4258. material = random.randint(0,20)
  4259. plus = random.randint(-3,3)
  4260. state = random.randint(80,100)
  4261. curse_chance = random.randint(0,30)
  4262. if curse_chance < material:
  4263. curse = 0
  4264. elif curse_chance == material:
  4265. curse = 2
  4266. else:
  4267. curse = 1
  4268. item = item_wear(classes[class_num], material, plus, state, curse, False)
  4269. inventory.append(item)
  4270. elif coin == 1:
  4271. items = []
  4272. for i in range(14,21):
  4273. items.append(il.ilist['misc'][i])
  4274. for i in range(22,40):
  4275. items.append(il.ilist['misc'][i])
  4276. for i in range(44,47):
  4277. items.append(il.ilist['misc'][i])
  4278. for j in range(6,9):
  4279. items.append(il.ilist['food'][j])
  4280. for j in range(13,25):
  4281. items.append(il.ilist['food'][j])
  4282. for j in range(29,32):
  4283. items.append(il.ilist['food'][j])
  4284. ran = random.randint(0,len(items)-1)
  4285. inventory.append(deepcopy(items[ran]))
  4286. elif c_type == 'remains':
  4287. classes = ['sword', 'axe', 'hammer', 'spear', 'helmet', 'armor', 'cuisse', 'shoes', 'wand', 'rune', 'rune staff', 'artefact', 'amulet', 'ring', 'talisman', 'necklace', 'pickaxe']
  4288. class_num = random.randint(0,len(classes)-1)
  4289. material = random.randint(0,20)
  4290. plus = random.randint(-3,3)
  4291. state = random.randint(20,60)
  4292. curses = (0,1,2)
  4293. curse_num = random.randint(0,2)
  4294. item = item_wear(classes[class_num], material, plus, state, curses[curse_num], False)
  4295. inventory.append(item)
  4296. elif c_type == 'fridge':
  4297. ran = random.randint(0,len(il.ilist['food'])-1)
  4298. inventory.append(deepcopy(il.ilist['food'][ran]))
  4299. if c_type == 'chest':
  4300. self.add_container(inventory, place[0], place[1])
  4301. replace = self.tilemap[place[1]][place[0]]
  4302. self.tilemap[place[1]][place[0]] = deepcopy(tl.tlist['functional'][4])#chest
  4303. self.tilemap[place[1]][place[0]].replace = replace
  4304. elif c_type == 'remains':
  4305. replace_tile = self.tilemap[place[1]][place[0]]
  4306. self.add_container(inventory, place[0], place[1])
  4307. self.tilemap[place[1]][place[0]] = deepcopy(tl.tlist['functional'][6])#remains
  4308. self.tilemap[place[1]][place[0]].replace = replace_tile
  4309. elif c_type == 'fridge':
  4310. replace_tile = self.tilemap[place[1]][place[0]]
  4311. self.add_container(inventory, place[0], place[1])
  4312. self.tilemap[place[1]][place[0]] = deepcopy(tl.tlist['functional'][25])#fridge
  4313. self.tilemap[place[1]][place[0]].replace = replace_tile
  4314. def exchange_when_surrounded(self, tile_check, tile_replace, number_neighbors):
  4315. #check all cordinates for their neighbors(including them self) and exchange th tile when the number of neighbors with the same techID => number_neighbors
  4316. for y in range (0,max_map_size):
  4317. for x in range (0,max_map_size):
  4318. count = 0
  4319. for yy in range (-1,2):
  4320. for xx in range (-1,2):
  4321. try:
  4322. if self.tilemap[y+yy][x+xx].techID == tile_check.techID or self.tilemap[y+yy][x+xx].techID == tile_replace.techID:
  4323. count += 1
  4324. except:
  4325. None
  4326. if count >= number_neighbors:
  4327. self.tilemap[y][x] = tile_replace
  4328. def sget(self):
  4329. string = ''
  4330. for c in range (0,max_map_size):
  4331. for d in range (0,max_map_size):
  4332. if d != player.pos[0] or c != player.pos[1]:
  4333. if self.known[c][d] != 0:
  4334. string = string + self.tilemap[c][d].char
  4335. else:
  4336. string += '\033[0;30;40m '
  4337. else:
  4338. string = string + player.char
  4339. string = string + '\n'
  4340. return string
  4341. def spawn_magic_shops(self,num=1):
  4342. if self.name == 'shop_0_0':
  4343. return False
  4344. pos = []
  4345. for i in range(0,num):
  4346. for y in range(0,max_map_size):
  4347. for x in range(0,max_map_size):
  4348. if self.tilemap[y][x].move_group == 'solid':
  4349. num_soil = 0
  4350. try:
  4351. if self.tilemap[y-1][x].move_group == 'soil':
  4352. num_soil += 1
  4353. except:
  4354. None
  4355. try:
  4356. if self.tilemap[y+1][x].move_group == 'soil':
  4357. num_soil += 1
  4358. except:
  4359. None
  4360. try:
  4361. if self.tilemap[y][x-1].move_group == 'soil':
  4362. num_soil += 1
  4363. except:
  4364. None
  4365. try:
  4366. if self.tilemap[y][x+1].move_group == 'soil':
  4367. num_soil += 1
  4368. except:
  4369. None
  4370. if num_soil > 0:
  4371. pos.append((x,y))
  4372. if len(pos) < 1:
  4373. return False
  4374. ran = random.randint(0,len(pos)-1)
  4375. replace = deepcopy(self.tilemap[pos[ran][1]][pos[ran][0]])
  4376. self.tilemap[pos[ran][1]][pos[ran][0]] = deepcopy(tl.tlist['shop'][4])
  4377. self.tilemap[pos[ran][1]][pos[ran][0]].replace = replace
  4378. #print('Shop at: '+str(pos[ran][0])+','+str(pos[ran][1]))
  4379. def set_sanctuary(self,startx,starty):
  4380. for y in range (starty-2, starty+3):
  4381. for x in range (startx-2, startx+3):
  4382. self.tilemap[y][x] = deepcopy(tl.tlist['sanctuary'][0])#sanctuary floor
  4383. if x == startx-2 or x == startx or x == startx+2:
  4384. if y == starty-2 or y == starty or y == starty+2:
  4385. self.tilemap[y][x] = deepcopy(tl.tlist['sanctuary'][1])#sanctuary pilar
  4386. self.tilemap[starty][startx] = deepcopy(tl.tlist['sanctuary'][2])#sanctuary spawn point
  4387. self.tilemap[starty-1][startx] = deepcopy(tl.tlist['functional'][20])#divine gift
  4388. self.tilemap[starty-1][startx].replace = tl.tlist['sanctuary'][0]
  4389. self.countdowns.append(countdown('gift_to_workbench',startx,starty-1,1))
  4390. material_pick = random.randint(0,10)
  4391. material_axe = random.randint(0,10)
  4392. material_amo = random.randint(0,10)
  4393. amo_classes = ('shoes','cuisse','armor','helmet')
  4394. ran = random.randint(0,3)
  4395. amo_class = amo_classes[ran]
  4396. pick = item_wear('pickaxe', material_pick,0)
  4397. axe = item_wear('axe',material_axe,0)
  4398. amo = item_wear(amo_class,material_amo,0)
  4399. ran_tunica = random.randint(0,2)
  4400. #original
  4401. self.add_container([pick,axe,amo,il.ilist['misc'][53],il.ilist['misc'][2],il.ilist['misc'][51],il.ilist['clothe'][ran_tunica]],startx,starty-1)
  4402. #/original
  4403. # statue demo:
  4404. #list_t = [pick,axe]
  4405. #for f in range(55,70):
  4406. # list_t.append(il.ilist['misc'][f])
  4407. #self.add_container(list_t,startx,starty-1)
  4408. # build demo: self.add_container([pick,axe,amo,il.ilist['misc'][3],il.ilist['misc'][16],il.ilist['misc'][22],il.ilist['misc'][23],il.ilist['clothe'][ran_tunica]],startx,starty-1)
  4409. # cloth demo: self.add_container([il.ilist['clothe'][8],il.ilist['clothe'][1],il.ilist['clothe'][2],il.ilist['clothe'][3],il.ilist['clothe'][4],il.ilist['clothe'][5],il.ilist['clothe'][6],il.ilist['clothe'][7]],startx,starty-1)
  4410. # magic demo: self.add_container([pick,axe,amo,il.ilist['misc'][81],il.ilist['misc'][24],il.ilist['misc'][24],il.ilist['misc'][24],il.ilist['clothe'][ran_tunica]],startx,starty-1)
  4411. self.tilemap[starty+1][startx] = deepcopy(tl.tlist['functional'][1])#stair down
  4412. self.tilemap[starty+1][startx].damage = -1
  4413. self.tilemap[starty+1][startx].damage_mes = 'Your wounds are cured.'
  4414. self.tilemap[starty+1][startx].build_here = False
  4415. self.tilemap[starty+1][startx].move_group = 'holy'
  4416. class world_class():
  4417. def __init__(self,tilelist):
  4418. global max_map_size
  4419. screen.render_load(0)
  4420. name = save_path + os.sep + 'world.data'
  4421. self.map_size = 52
  4422. self.startx = 0
  4423. self.starty = 0
  4424. try:
  4425. f = open(name, 'rb')
  4426. temp = p.load(f)
  4427. screen.render_load(1)
  4428. self.maplist = temp.maplist
  4429. self.map_size = temp.map_size
  4430. max_map_size = self.map_size
  4431. self.startx = temp.startx
  4432. self.starty = temp.starty
  4433. except:
  4434. screen.render_load(2)
  4435. if force_small_worlds == False:
  4436. self.choose_size()
  4437. self.maplist = []
  4438. for x in range (0,7):
  4439. self.maplist.append({})
  4440. screen.render_load(3)
  4441. pos = self.grassland_generator(0,0,30,80,5,int((max_map_size*max_map_size)/20))
  4442. self.startx = pos[0]
  4443. self.starty = pos[1]
  4444. self.cave_generator(4)
  4445. self.border_generator(6)
  4446. screen.render_load(5)
  4447. def default_map_generator(self, name, tiles, tilelist): #check if tilelist can be deleted
  4448. tilemap = []
  4449. for i in range (0,max_map_size):
  4450. tilemap.append([])
  4451. a = 0
  4452. for b in range (0,max_map_size):
  4453. ran_num = random.randint(0,len(tl.tlist[tiles])-1)
  4454. tilemap[a].append(tl.tlist[tiles][ran_num])
  4455. b = 0
  4456. for a in range (1,max_map_size):
  4457. ran_num = random.randint(0,len(tl.tlist[tiles])-1)
  4458. tilemap[a].append(tl.tlist[tiles][ran_num])
  4459. for a in range (1,max_map_size):
  4460. for b in range (1,max_map_size):
  4461. ran_same = random.randint(0,9)
  4462. if ran_same < 5 :
  4463. tilemap[a].append(tilemap[a-1][b])
  4464. elif ran_same < 8:
  4465. tilemap[a].append(tilemap[a][b-1])
  4466. else:
  4467. ran_num = random.randint(0,len(tl.tlist[tiles])-1)
  4468. tilemap[a].append(tl.tlist[tiles][ran_num])
  4469. m = maP(name ,tilemap)
  4470. return m
  4471. def border_generator(self,layer,style='default'):
  4472. if style == 'default':
  4473. cave_name = 'local_0_0'
  4474. elif style == 'desert':
  4475. cave_name = 'desert_0_0'
  4476. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  4477. m.map_type = 'border'
  4478. m.fill(tl.tlist['functional'][0])#fill with border
  4479. self.maplist[layer][cave_name] = m
  4480. def grot_generator(self,layer):
  4481. screen.render_load(15,1)
  4482. cave_name = 'dungeon_0_0'
  4483. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  4484. m.map_type = 'grot'
  4485. m.set_music('grot','grot',True)
  4486. m.build_type = 'None'
  4487. m.fill(tl.tlist['global_caves'][3])#fill with hard rock
  4488. m.drunken_walker(int(max_map_size/2),int(max_map_size/2),tl.tlist['misc'][0],(((max_map_size*max_map_size)/100)*40))#set low water
  4489. m.set_frame(tl.tlist['functional'][0])
  4490. chance_ore = layer*5
  4491. chance_gem = layer*3
  4492. screen.render_load(15,10)
  4493. for y in range (0,max_map_size):
  4494. for x in range (0,max_map_size):
  4495. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  4496. replace = m.tilemap[y][x].replace
  4497. coin = random.randint(0,1)
  4498. percent = random.randint(1,100)
  4499. if coin == 0 and percent <= chance_ore:
  4500. m.tilemap[y][x] = tl.tlist['misc'][4]#set ore here
  4501. m.tilemap[y][x].replace = replace
  4502. elif coin == 1 and percent <= chance_gem:
  4503. m.tilemap[y][x] = tl.tlist['misc'][5]#set gem here
  4504. m.tilemap[y][x].replace = replace
  4505. screen.render_load(15,40)
  4506. for y in range (0,max_map_size):
  4507. for x in range (0,max_map_size):
  4508. if m.tilemap[y][x].techID == tl.tlist['misc'][1].techID:#this is mud
  4509. cent = random.randint(0,99)
  4510. if cent < 10: #its a chance of 10% that a blue mushroom spawns here
  4511. replace = m.tilemap[y][x]
  4512. m.tilemap[y][x] = tl.tlist['misc'][6]
  4513. m.tilemap[y][x].replace = replace
  4514. m.containers[y][x] = container([deepcopy(il.ilist['food'][1])])
  4515. screen.render_load(15,75)
  4516. num_lilys = int(((max_map_size*max_map_size)/100)*3)
  4517. for i in range (0,num_lilys):
  4518. pos = m.find_any(tl.tlist['misc'][0])#find low wather
  4519. try:
  4520. coin = random.randint(0,1)
  4521. if coin == 0:
  4522. m.tilemap[pos[1]][pos[0]] = tl.tlist['misc'][10]#set a water lily
  4523. else:
  4524. m.tilemap[pos[1]][pos[0]] = tl.tlist['misc'][14]#set a water lily with blossom
  4525. except:
  4526. None
  4527. screen.render_load(15,90)
  4528. pos = m.find_any(tl.tlist['misc'][0])#find any low water tile
  4529. m.tilemap[pos[1]][pos[0]] = tl.tlist['dungeon'][15]#set stair up
  4530. entrance_x = pos[0]
  4531. entrance_y = pos[1]
  4532. for sy in range(pos[1]-4,pos[1]+5):
  4533. for sx in range(pos[0]-4,pos[0]+5):
  4534. try:
  4535. if m.tilemap[sy][sx].move_group == 'soil':
  4536. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  4537. m.tilemap[sy][sx].move_group == 'dry_entrance'
  4538. elif m.tilemap[sy][sx].move_group == 'low_liquid':
  4539. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  4540. m.tilemap[sy][sx].move_group == 'wet_entrance'
  4541. except:
  4542. None
  4543. m.make_shops()
  4544. m.spawn_monsters(3)
  4545. screen.render_load(15,99)
  4546. self.maplist[layer][cave_name] = m
  4547. def elfish_generator(self,layer):
  4548. screen.render_load(16,1)
  4549. map_name = 'fortress_0_0'
  4550. m = self.default_map_generator(map_name,'global_caves', tilelist)
  4551. m.map_type = 'elfish_fortress'
  4552. m.set_music('elfish_fortress','elfish_fortress',True)
  4553. m.no_monster_respawn = True
  4554. m.build_type = 'None'
  4555. m.fill(tl.tlist['elfish'][0])
  4556. for y in range (10, max_map_size-10,10):
  4557. ran = random.randint(0,3)
  4558. for yy in range (y-1,y+2):
  4559. if ran < 3:
  4560. m.imp_connect((0,max_map_size-1),(yy,yy),tl.tlist['elfish'][1],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4561. if ran < 3:
  4562. m.imp_connect((0,max_map_size-1),(y-2,y-2),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4563. m.imp_connect((0,max_map_size-1),(y+2,y+2),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4564. screen.render_load(16,10)
  4565. for x in range (10, max_map_size-10,10):
  4566. ran = random.randint(0,3)
  4567. for xx in range (x-1,x+2):
  4568. if ran < 3:
  4569. m.imp_connect((xx,xx),(0,max_map_size-1),tl.tlist['elfish'][1],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4570. if ran < 3:
  4571. m.imp_connect((x-2,x-2),(0,max_map_size-1),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4572. m.imp_connect((x+2,x+2),(0,max_map_size-1),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4573. m.cut(5,max_map_size-6,5,max_map_size-6,tl.tlist['elfish'][3])
  4574. building_count = 0
  4575. run = True
  4576. screen.render_load(16,30)
  4577. while run:
  4578. pos=m.find_first(tl.tlist['elfish'][0])
  4579. if pos != False:
  4580. m.floating(pos[0],pos[1],tl.tlist['elfish'][5],tl.tlist['elfish'][3])#fill with help passive
  4581. building_count += 1
  4582. else:
  4583. run = False
  4584. m.exchange(tl.tlist['elfish'][5],tl.tlist['elfish'][0])
  4585. screen.render_load(16,50)
  4586. if building_count < 6:
  4587. return False #return false to make a loop if there are to less buildings inside the map
  4588. num_temples = int((float(building_count)/100)*10)
  4589. if num_temples == 0:
  4590. num_temples = 1
  4591. num_agriculture = int((float(building_count)/100)*10)
  4592. if num_agriculture == 0:
  4593. num_agriculture=1
  4594. num_meetingarea = int((float(building_count)/100)*10)
  4595. if num_meetingarea == 0:
  4596. num_meetingarea = 1
  4597. num_marketplace = int((float(building_count)/100)*10)
  4598. if num_marketplace == 0:
  4599. num_marketplace = 1
  4600. num_libaries = int((float(building_count)/100)*10)
  4601. if num_libaries == 0:
  4602. num_libaries = 1
  4603. num_dwellings = building_count-num_temples-num_agriculture-num_meetingarea-num_marketplace-num_libaries
  4604. screen.render_load(16,60)
  4605. m.cut(5,max_map_size-6,5,max_map_size-6,tl.tlist['elfish'][1])
  4606. for i in range(0,num_agriculture):
  4607. pos = m.find_any(tl.tlist['elfish'][0])#find any elfish_floor_indoor
  4608. m.floating(pos[0],pos[1],tl.tlist['elfish'][2],tl.tlist['elfish'][1])#replace this building with elfish_agriculture
  4609. for y in range(0,max_map_size,2):
  4610. for x in range(0,max_map_size):
  4611. if m.tilemap[y][x].techID == tl.tlist['elfish'][2].techID:#this is elfish agriculture
  4612. m.tilemap[y][x] = tl.tlist['misc'][0]#set low water
  4613. screen.render_load(16,65)
  4614. m.cut(5,max_map_size-6,5,max_map_size-6,tl.tlist['elfish'][3])
  4615. for i in range(0,num_marketplace):#set marketplaces
  4616. pos = m.find_any(tl.tlist['elfish'][0])#find any elfish_floor_indoor
  4617. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  4618. pos = m.find_first(tl.tlist['elfish'][4])
  4619. size = m.get_quarter_size(pos[0],pos[1])
  4620. for y in range(pos[1]+1,pos[1]+size[1]-1,2):
  4621. for x in range(pos[0]+1,pos[0]+size[0]-1,3):
  4622. m.npcs[y][x] = ml.mlist['shop'][0]
  4623. m.exchange(tl.tlist['elfish'][4],tl.tlist['shop'][0])
  4624. screen.render_load(16,70)
  4625. for i in range(0,num_temples):
  4626. pos = m.find_any(tl.tlist['elfish'][0])#find any elfish_floor_indoor
  4627. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  4628. pos = m.find_first(tl.tlist['elfish'][4])
  4629. size = m.get_quarter_size(pos[0],pos[1])
  4630. for y in range(pos[1],pos[1]+size[1],2):
  4631. for x in range(pos[0],pos[0]+size[0],2):
  4632. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][22])
  4633. m.tilemap[y][x].replace = tl.tlist['elfish'][0]
  4634. m.tilemap[y][x].civilisation = False
  4635. m.tilemap[pos[1]+int(size[1]/2)][pos[0]+int(size[0]/2)] = deepcopy(tl.tlist['functional'][15])#set a altar
  4636. m.tilemap[pos[1]+int(size[1]/2)][pos[0]+int(size[0]/2)].replace = tl.tlist['elfish'][0]
  4637. m.tilemap[pos[1]+int(size[1]/2)][pos[0]+int(size[0]/2)].civilisation = False
  4638. m.exchange(tl.tlist['elfish'][4],tl.tlist['elfish'][5])
  4639. screen.render_load(16,75)
  4640. for i in range(0,num_meetingarea):
  4641. pos = m.find_any(tl.tlist['elfish'][0])
  4642. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  4643. pos = m.find_first(tl.tlist['elfish'][4])
  4644. size = m.get_quarter_size(pos[0],pos[1])
  4645. for y in range(pos[1]+2,pos[1]+size[1]-2):
  4646. for x in range(pos[0]+2,pos[0]+size[0]-1,4):
  4647. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][16]) #set table
  4648. m.tilemap[y][x].replace = tl.tlist['elfish'][0]
  4649. m.tilemap[y][x].civilisation = False
  4650. for xx in range(x-1,x+2):
  4651. if m.tilemap[y][xx].techID == tl.tlist['elfish'][4].techID:
  4652. m.tilemap[y][xx] = deepcopy(tl.tlist['functional'][18])
  4653. m.tilemap[y][xx].replace = tl.tlist['elfish'][0]
  4654. m.tilemap[y][xx].civilisation = False
  4655. for yy in range(y-1,y+2):
  4656. if m.tilemap[yy][x].techID == tl.tlist['elfish'][4].techID:
  4657. m.tilemap[yy][x] = deepcopy(tl.tlist['functional'][18])
  4658. m.tilemap[yy][x].replace = tl.tlist['elfish'][0]
  4659. m.tilemap[yy][x].civilisation = False
  4660. m.exchange(tl.tlist['elfish'][4],tl.tlist['elfish'][5])
  4661. screen.render_load(16,80)
  4662. for i in range(0,num_libaries):
  4663. pos = m.find_any(tl.tlist['elfish'][0])
  4664. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  4665. pos = m.find_first(tl.tlist['elfish'][4])
  4666. size = m.get_quarter_size(pos[0],pos[1])
  4667. for y in range(pos[1]+1,pos[1]+size[1]-1,2):
  4668. for x in range(pos[0]+1,pos[0]+size[0]-1,2):
  4669. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][19])
  4670. m.tilemap[y][x].civilisation = False
  4671. m.exchange(tl.tlist['elfish'][4],tl.tlist['elfish'][5])
  4672. screen.render_load(16,85)
  4673. for i in range(0,num_dwellings):
  4674. pos = m.find_any(tl.tlist['elfish'][0])
  4675. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  4676. pos = m.find_first(tl.tlist['elfish'][4])
  4677. pos_original = pos
  4678. size = m.get_quarter_size(pos[0],pos[1])
  4679. num_beds = int((size[0]*size[1])/9)
  4680. num_furniture = int((size[0]*size[1])/25)
  4681. for y in range(pos[1],pos[1]+size[1]):
  4682. for x in range(pos[0],pos[0]+size[0]):
  4683. m.tilemap[y][x] = tl.tlist['elfish'][5]
  4684. for y in range(pos[1]+1,pos[1]+size[1]-1):
  4685. for x in range(pos[0]+1,pos[0]+size[0]-1):
  4686. m.tilemap[y][x] = tl.tlist['elfish'][4]
  4687. for i in range(0,num_beds):#set beds
  4688. pos = m.find_any(tl.tlist['elfish'][4])
  4689. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][8])
  4690. m.tilemap[pos[1]][pos[0]].replace = deepcopy(tl.tlist['building'][9])
  4691. m.tilemap[pos[1]][pos[0]].civilisation = False
  4692. m.tilemap[pos[1]][pos[0]].replace.civilisation = False
  4693. for i in range(0,num_furniture):#set furnaces
  4694. pos = m.find_any(tl.tlist['elfish'][4])
  4695. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][14])
  4696. m.tilemap[pos[1]][pos[0]].replace = deepcopy(tl.tlist['building'][9])
  4697. m.tilemap[pos[1]][pos[0]].civilisation = False
  4698. m.tilemap[pos[1]][pos[0]].replace.civilisation = False
  4699. for i in range(0,num_furniture):#set wb's
  4700. pos = m.find_any(tl.tlist['elfish'][4])
  4701. ran = random.randint(9,13)
  4702. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][ran])
  4703. m.tilemap[pos[1]][pos[0]].replace = deepcopy(tl.tlist['building'][9])
  4704. m.tilemap[pos[1]][pos[0]].civilisation = False
  4705. m.tilemap[pos[1]][pos[0]].replace.civilisation = False
  4706. for y in range(pos_original[1]+1,pos_original[1]+size[1]-1):#set blue floor
  4707. for x in range(pos_original[0]+1,pos_original[0]+size[0]-1):
  4708. if m.tilemap[y][x].techID == tl.tlist['elfish'][4].techID:
  4709. m.tilemap[y][x] = deepcopy(tl.tlist['building'][9])
  4710. m.tilemap[y][x].civilisation = False
  4711. screen.render_load(16,90)
  4712. for yy in range(0,max_map_size,5):
  4713. for xx in range(0,max_map_size):
  4714. if m.tilemap[yy][xx].techID == tl.tlist['elfish'][3].techID:#this is elfish wall
  4715. m.tilemap[yy][xx] = deepcopy(tl.tlist['building'][2]) #set a open door here
  4716. m.tilemap[yy][xx].civilisation = False
  4717. for yyy in range(yy-1,yy+2):
  4718. for xxx in range(xx-1,xx+2):
  4719. if yyy >= 0 and xxx >= 0 and xxx < max_map_size and yyy < max_map_size:
  4720. if m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][0].techID and m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][1].techID and m.tilemap[yyy][xxx].techID != tl.tlist['shop'][0].techID and m.tilemap[yyy][xxx].techID != tl.tlist['building'][2].techID and m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][3].techID and m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][2].techID and m.tilemap[yyy][xxx].techID != tl.tlist['misc'][0].techID:
  4721. #if a field next to a door isn't elfish_indoor, elfish_wall or shop_floor set it to elfish_indoor
  4722. m.tilemap[yyy][xxx] = tl.tlist['elfish'][0]
  4723. screen.render_load(16,95)
  4724. for yy in range(0,max_map_size):
  4725. for xx in range(0,max_map_size,5):
  4726. if m.tilemap[yy][xx].techID == tl.tlist['elfish'][3].techID:#this is elfish wall
  4727. m.tilemap[yy][xx] = deepcopy(tl.tlist['building'][2]) #set a open door here
  4728. m.tilemap[yy][xx].civilisation = False
  4729. for yyy in range(yy-1,yy+2):
  4730. for xxx in range(xx-1,xx+2):
  4731. if yyy >= 0 and xxx >= 0 and xxx < max_map_size and yyy < max_map_size:
  4732. if m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][0].techID and m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][1].techID and m.tilemap[yyy][xxx].techID != tl.tlist['shop'][0].techID and m.tilemap[yyy][xxx].techID != tl.tlist['building'][2].techID and m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][3].techID and m.tilemap[yyy][xxx].techID != tl.tlist['elfish'][2].techID and m.tilemap[yyy][xxx].techID != tl.tlist['misc'][0].techID:
  4733. #if a field next to a door isn't elfish_indoor, elfish_wall or shop_floor set it to elfish_indoor
  4734. m.tilemap[yyy][xxx] = tl.tlist['elfish'][0]
  4735. screen.render_load(16,97)
  4736. m.cut(5,max_map_size-6,5,max_map_size-6,tl.tlist['elfish'][3])
  4737. m.set_frame(tl.tlist['functional'][0])
  4738. #set fontains
  4739. for y in range(10,max_map_size-10,10):
  4740. for x in range(10,max_map_size-10,10):
  4741. if m.tilemap[y][x].techID == tl.tlist['elfish'][1].techID:
  4742. coin = random.randint(0,1)
  4743. if coin == 0:
  4744. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][7])#set a fontain
  4745. m.tilemap[y][x].replace = tl.tlist['elfish'][1]
  4746. m.tilemap[y][x].civilisation = False #this is no players fontain
  4747. m.exchange(tl.tlist['elfish'][5],tl.tlist['elfish'][0])
  4748. pos = m.find_any(tl.tlist['functional'][7]) #set portal home
  4749. if pos == False:
  4750. pos = m.find_any(tl.tlist['elfish'][1])
  4751. replace = deepcopy(tl.tlist['elfish'][1])
  4752. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['portal'][2])
  4753. m.tilemap[pos[1]][pos[0]].replace = replace
  4754. m.spawn_monsters(6)
  4755. self.maplist[layer][map_name] = m
  4756. screen.render_load(16,00)
  4757. def mine_generator(self,layer):
  4758. screen.render_load(17,1)
  4759. cave_name = 'dungeon_0_0'
  4760. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  4761. m.map_type = 'orcish_mines'
  4762. m.set_music('orcish_mines','orcish_mines',True)
  4763. m.build_type = 'None'
  4764. m.monster_plus = 9
  4765. screen.render_load(17,10)
  4766. m.fill(tl.tlist['mine'][1])#fill with mine wall
  4767. screen.render_load(17,30)
  4768. m.drunken_walker(int(max_map_size/2),int(max_map_size/2),tl.tlist['mine'][0],((max_map_size**2/100)*45))
  4769. screen.render_load(17,50)
  4770. screen.render_load(17,60)
  4771. m.exchange_when_surrounded(tl.tlist['mine'][1],tl.tlist['global_caves'][3],8) #only the outer tiles become mine wall
  4772. screen.render_load(17,70)
  4773. for y in range (0, max_map_size):
  4774. for x in range(0,max_map_size):
  4775. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  4776. ran = random.randint(0,99)
  4777. if ran > 69:
  4778. m.tilemap[y][x] = tl.tlist['misc'][4]#set ore
  4779. m.tilemap[y][x].replace = tl.tlist['global_caves'][0]
  4780. elif ran < 10:
  4781. m.tilemap[y][x] = tl.tlist['misc'][5]#set gem
  4782. m.tilemap[y][x].replace = tl.tlist['global_caves'][0]
  4783. screen.render_load(17,80)
  4784. m.set_frame(tl.tlist['functional'][0])
  4785. m.make_shops()
  4786. m.make_containers(15,30,tl.tlist['mine'][0],1,4,'remains')
  4787. num_moss = int(((max_map_size*max_map_size)/100)*3)
  4788. for i in range (0,num_moss):
  4789. pos = m.find_any(tl.tlist['mine'][0])#find mine floor
  4790. try:
  4791. m.tilemap[pos[1]][pos[0]] = tl.tlist['mine'][2]#set blood moss
  4792. except:
  4793. None
  4794. screen.render_load(17,90)
  4795. pos = m.find_any(tl.tlist['mine'][0])#find any mine floor tile
  4796. m.tilemap[pos[1]][pos[0]] = tl.tlist['dungeon'][17]#set stair up
  4797. entrance_x = pos[0]
  4798. entrance_y = pos[1]
  4799. for sy in range(pos[1]-4,pos[1]+5):
  4800. for sx in range(pos[0]-4,pos[0]+5):
  4801. try:
  4802. if m.tilemap[sy][sx].move_group == 'soil':
  4803. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  4804. m.tilemap[sy][sx].move_group == 'dry_entrance'
  4805. elif m.tilemap[sy][sx].move_group == 'low_liquid':
  4806. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  4807. m.tilemap[sy][sx].move_group == 'wet_entrance'
  4808. except:
  4809. None
  4810. m.spawn_monsters(9)
  4811. screen.render_load(17,99)
  4812. self.maplist[layer][cave_name] = m
  4813. def cave_generator(self, deep, style='default'):
  4814. if style == 'desert':
  4815. cave_name='desert_0_0'
  4816. else:
  4817. cave_name = 'local_0_0'
  4818. p = 9
  4819. for d in range(1,deep+2):
  4820. screen.render_load(4,p+(d*20))
  4821. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  4822. if d < 4:
  4823. if style == 'desert':
  4824. m.map_type = 'desert_cave'
  4825. m.monster_plus = 7
  4826. else:
  4827. m.map_type = 'cave'
  4828. m.set_music('cave','cave',True)
  4829. else:
  4830. if style == 'desert':
  4831. m.map_type = 'desert_lava_cave'
  4832. m.monster_plus = 7
  4833. else:
  4834. m.map_type = 'lava_cave'
  4835. m.set_music('lava_cave','lava_cave',True)
  4836. m.thirst_multi_day = 2
  4837. m.thirst_multi_night = 2
  4838. if d > 3:
  4839. m.exchange(tl.tlist['global_caves'][4],tl.tlist['misc'][2])#exchange lava against hot cave ground
  4840. m.exchange(tl.tlist['global_caves'][1],tl.tlist['misc'][28])#exchange worn rock against obsidian
  4841. if d > 4:
  4842. m.exchange_when_surrounded(tl.tlist['misc'][2],tl.tlist['global_caves'][4],8)#make lava spots between hot cave ground
  4843. num = int((max_map_size*max_map_size)/(50*50))
  4844. for i in range(0,num):
  4845. ran = random.randint(0,1)
  4846. if ran > 0:
  4847. pos = m.find_any(tl.tlist['global_caves'][0]) #cave ground
  4848. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][23])# make master forges
  4849. else:
  4850. m.exchange(tl.tlist['global_caves'][4],tl.tlist['misc'][1])#exchange lava against mud
  4851. m.exchange_when_surrounded(tl.tlist['misc'][1],tl.tlist['misc'][0],8)#make low water spots between mud
  4852. #######set mushrooms, ore and gems
  4853. chance_ore = d
  4854. chance_gem = d/2
  4855. for y in range (0,max_map_size):
  4856. for x in range (0,max_map_size):
  4857. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  4858. replace = m.tilemap[y][x].replace
  4859. coin = random.randint(0,1)
  4860. percent = random.randint(1,100)
  4861. if coin == 0 and percent <= chance_ore:
  4862. m.tilemap[y][x] = tl.tlist['misc'][4]#set ore here
  4863. m.tilemap[y][x].replace = replace
  4864. elif coin == 1 and percent <= chance_gem:
  4865. m.tilemap[y][x] = tl.tlist['misc'][5]#set gem here
  4866. m.tilemap[y][x].replace = replace
  4867. if m.tilemap[y][x].techID == tl.tlist['misc'][1].techID:#this is mud
  4868. cent = random.randint(0,99)
  4869. if cent < 10: #its a chance of 10% that a blue mushroom spawns here
  4870. replace = m.tilemap[y][x]
  4871. m.tilemap[y][x] = tl.tlist['misc'][6]
  4872. m.tilemap[y][x].replace = replace
  4873. if m.tilemap[y][x].techID == tl.tlist['global_caves'][0].techID:#this is cave ground
  4874. cent = random.randint(0,99)
  4875. if cent < 10: #its a chance of 10% that a brown mushroom spawns here
  4876. replace = m.tilemap[y][x]
  4877. m.tilemap[y][x] = tl.tlist['misc'][7]
  4878. m.tilemap[y][x].replace = replace
  4879. elif cent < 15: #its a chance of 5% that a purple mushroom spawns here
  4880. replace = m.tilemap[y][x]
  4881. m.tilemap[y][x] = tl.tlist['misc'][8]
  4882. m.tilemap[y][x].replace = replace
  4883. m.set_frame(tl.tlist['functional'][0])
  4884. if d == 1 and style == 'default':#set stair up on lvl 1
  4885. pos = (int(max_map_size/2),int(max_map_size/2))
  4886. m.tilemap[pos[1]+1][pos[0]] = deepcopy(tl.tlist['functional'][2])#stair down
  4887. m.tilemap[pos[1]+1][pos[0]].damage = -1
  4888. m.tilemap[pos[1]+1][pos[0]].damage_mes = 'Your wounds are cured.'
  4889. m.tilemap[pos[1]+1][pos[0]].build_here = False
  4890. for yy in range(pos[1]-3,pos[1]+4):
  4891. for xx in range(pos[0]-3,pos[0]+4):
  4892. m.tilemap[yy][xx].no_spawn = True
  4893. for x in range(0,max_map_size):
  4894. if m.tilemap[x][pos[0]].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  4895. ran = random.randint(1,2)
  4896. m.tilemap[x][pos[0]] = deepcopy(tl.tlist['global_caves'][ran])
  4897. for y in range(0,max_map_size):
  4898. if m.tilemap[pos[1]+1][y].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  4899. ran = random.randint(1,2)
  4900. m.tilemap[pos[1]+1][y] = deepcopy(tl.tlist['global_caves'][ran])
  4901. #set vaults
  4902. for i in range(0,int(max_map_size**2/50**2)):
  4903. m.make_vault(tl.tlist['global_caves'][0],d)
  4904. #set grot/mine at lvl 1 and 3
  4905. if style == 'default':
  4906. if d == 1:
  4907. ran_pos = m.find_any(tl.tlist['global_caves'][0])
  4908. m.tilemap[ran_pos[1]][ran_pos[0]] = tl.tlist['dungeon'][14]
  4909. if style == 'desert':
  4910. if d == 3:
  4911. ran_pos = m.find_any(tl.tlist['global_caves'][0])
  4912. m.tilemap[ran_pos[1]][ran_pos[0]] = tl.tlist['dungeon'][16]
  4913. m.make_containers(1,2,tl.tlist['global_caves'][0],2,5,'chest')#set some chests
  4914. m.make_special_monsters(0,1,tl.tlist['global_caves'][0],d,'mimic')#maybe set some mimics
  4915. m.make_special_monsters(15,25,tl.tlist['global_caves'][0],d,'vase')#set some vases
  4916. if m.map_type == 'desert_lava_cave':
  4917. m.make_special_monsters(1,2,tl.tlist['global_caves'][0],d,'demonic chest')#maybe set some demonic chests
  4918. m.spawn_monsters(d)
  4919. if style == 'desert': #replace rock etc.
  4920. for y in range(0,max_map_size):
  4921. for x in range(0,max_map_size):
  4922. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID: #this is hard rock
  4923. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][24])
  4924. elif m.tilemap[y][x].techID == tl.tlist['global_caves'][1].techID: #this is worn rock
  4925. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][23])
  4926. elif m.tilemap[y][x].techID == tl.tlist['global_caves'][2].techID: #this is soft soil
  4927. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][23])
  4928. elif m.tilemap[y][x].techID == tl.tlist['misc'][4].techID: #this is ore
  4929. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][21])
  4930. elif m.tilemap[y][x].techID == tl.tlist['misc'][5].techID: #this is gem
  4931. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][22])
  4932. elif m.tilemap[y][x].techID == tl.tlist['misc'][7].techID: #this is a brown mushroom
  4933. replace = m.tilemap[y][x].replace
  4934. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][25])
  4935. m.tilemap[y][x].replace = replace
  4936. elif m.tilemap[y][x].techID == tl.tlist['misc'][8].techID: #this is a purple mushroom
  4937. replace = m.tilemap[y][x].replace
  4938. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][27])
  4939. m.tilemap[y][x].replace = replace
  4940. elif m.tilemap[y][x].techID == tl.tlist['misc'][6].techID: #this is a blue mushroom
  4941. replace = m.tilemap[y][x].replace
  4942. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][26])
  4943. m.tilemap[y][x].replace = replace
  4944. self.maplist[d][cave_name] = m
  4945. def grassland_generator(self,x,y,chance_scrubs, chance_trees, chance_herbs, number_rocks):
  4946. # chance_scrubs and chance_trees must be between 0 and 99
  4947. screen.render_load(3,1)
  4948. name = 'local_0_0'
  4949. helpmap = self.default_map_generator('1','help',tilelist)
  4950. tilemap = []
  4951. for a in range (0,max_map_size):
  4952. tilemap.append([])
  4953. for b in range (0,max_map_size):
  4954. tilemap[a].append(0)
  4955. m = maP(name,tilemap)
  4956. m.map_type = 'overworld'
  4957. m.set_music('overworld','night',True)
  4958. screen.render_load(3,2)
  4959. m.fill(tl.tlist['local'][0])#fill the map with grass
  4960. # set scrubs
  4961. for y in range (0,max_map_size):
  4962. for x in range (0,max_map_size):
  4963. if helpmap.tilemap[y][x].techID == tl.tlist['help'][0].techID: #<---scrub here
  4964. chance = random.randint(0,99)
  4965. if chance < chance_scrubs:
  4966. scrubs = (1,3,4,6,7,8,9)
  4967. coin = random.randint(0,len(scrubs)-1)
  4968. m.tilemap[y][x] = deepcopy(tl.tlist['local'][scrubs[coin]])
  4969. m.tilemap[y][x].replace = tl.tlist['local'][0]
  4970. screen.render_load(3,3)
  4971. #set trees
  4972. for y in range (0,max_map_size):
  4973. for x in range (0,max_map_size):
  4974. if helpmap.tilemap[y][x].techID == tl.tlist['help'][1].techID: #<---tree here
  4975. chance = random.randint(0,99)
  4976. if chance < chance_trees:
  4977. coin = random.randint(10,13)
  4978. m.tilemap[y][x] = tl.tlist['local'][coin]
  4979. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  4980. screen.render_load(3,4)
  4981. #set herbs
  4982. for y in range (0,max_map_size):
  4983. for x in range (0,max_map_size):
  4984. if helpmap.tilemap[y][x].techID == tl.tlist['help'][0].techID: #<---scrub here
  4985. chance = random.randint(0,99)
  4986. if chance < chance_herbs:
  4987. coin = random.randint(15,16)
  4988. m.tilemap[y][x] = tl.tlist['local'][coin]
  4989. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  4990. screen.render_load(3,5)
  4991. # set rocks
  4992. for n in range (0,number_rocks):
  4993. x = random.randint(0,max_map_size-1)
  4994. y = random.randint(0,max_map_size-1)
  4995. m.tilemap[y][x] = tl.tlist['local'][14]
  4996. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  4997. screen.render_load(3,6)
  4998. #set water
  4999. for y in range (0,max_map_size):
  5000. for x in range (0,max_map_size):
  5001. if helpmap.tilemap[y][x].techID == tl.tlist['help'][2].techID: #<---water here
  5002. m.tilemap[y][x] = tl.tlist['misc'][0] # set low water here
  5003. screen.render_load(3,7)
  5004. m.exchange_when_surrounded(tl.tlist['misc'][0],tl.tlist['misc'][3],8) # exchange low wather against deep water
  5005. pos = (int(max_map_size/2),int(max_map_size/2))
  5006. m.set_sanctuary(pos[0],pos[1])
  5007. m.set_frame(tl.tlist['functional'][0])
  5008. screen.render_load(3,8)
  5009. #set desert portal
  5010. y = max_map_size -2
  5011. x = random.randint(2,max_map_size-2)
  5012. m.tilemap[y][x] = tl.tlist['portal'][3]
  5013. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  5014. m.tilemap[y-1][x] = tl.tlist['local'][0]#grass
  5015. #set dungeon
  5016. ran_pos = m.find_any(tl.tlist['local'][0])
  5017. m.tilemap[ran_pos[1]][ran_pos[0]] = deepcopy(tl.tlist['dungeon'][7])
  5018. #set elfish portal
  5019. ran_pos = m.find_any(tl.tlist['local'][0])
  5020. replace = deepcopy(tl.tlist['local'][0])
  5021. m.tilemap[ran_pos[1]][ran_pos[0]] = deepcopy(tl.tlist['portal'][0])
  5022. m.tilemap[ran_pos[1]][ran_pos[0]].replace = replace
  5023. for q in range(0,int(max_map_size**2/50**2)*3):
  5024. m.make_orc_cave(tl.tlist['local'][0])#generate orc caves on grass
  5025. m.spawn_monsters(0)
  5026. self.maplist[0][name] = m
  5027. screen.render_load(3,9)
  5028. return pos
  5029. def shop_generator(self,style):
  5030. #0: Basic initializing
  5031. screen.render_load(19,0)
  5032. name = 'shop_0_0'
  5033. tilemap = []
  5034. for a in range (0,max_map_size):
  5035. tilemap.append([])
  5036. for b in range (0,max_map_size):
  5037. tilemap[a].append(0)
  5038. m = maP(name,tilemap)
  5039. m.map_type = style
  5040. m.build_type = 'None'
  5041. m.monster_plus = 0
  5042. m.monster_num = 0
  5043. m.set_music('shop','shop',True)
  5044. m.fill(tl.tlist['functional'][0])
  5045. screen.render_load(19,10)
  5046. center_x = int(max_map_size/2)
  5047. center_y = int(max_map_size/2)
  5048. for y in range(center_y-4,center_y+5):
  5049. for x in range(center_x-4,center_x+5):
  5050. m.tilemap[y][x] = deepcopy(tl.tlist['shop'][1])#wall
  5051. screen.render_load(19,20)
  5052. for y in range(center_y-3,center_y+4):
  5053. for x in range(center_x-3,center_x+4):
  5054. m.tilemap[y][x] = deepcopy(tl.tlist['dungeon'][1])#corridor
  5055. screen.render_load(19,30)
  5056. for y in range(center_y-2,center_y+3):
  5057. for x in range(center_x-2,center_x+3):
  5058. m.tilemap[y][x] = deepcopy(tl.tlist['shop'][1])#shop wall
  5059. screen.render_load(19,50)
  5060. for y in range(center_y-1,center_y+2):
  5061. for x in range(center_x-1,center_x+2):
  5062. m.tilemap[y][x] = deepcopy(tl.tlist['shop'][0])#shop floor
  5063. screen.render_load(19,70)
  5064. m.tilemap[center_y-2][center_x] = deepcopy(tl.tlist['shop'][2])#shop door
  5065. m.tilemap[center_y-3][center_x-1] = deepcopy(tl.tlist['shop'][5])#sign
  5066. m.tilemap[center_y-3][center_x-1].replace = deepcopy(tl.tlist['dungeon'][1])
  5067. m.tilemap[center_y-3][center_x].techID = -9999#nothing shall spawn here
  5068. m.tilemap[center_y-4][center_x] = deepcopy(tl.tlist['shop'][3])#shop exit
  5069. if style == 'pharmacy':
  5070. m.tilemap[center_y-3][center_x-1].move_mes = '[Naeria\'s Pharmacy]'
  5071. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][3])
  5072. elif style == 'pickaxe':
  5073. m.tilemap[center_y-3][center_x-1].move_mes = '[Eklor\'s Pickaxe Empire]'
  5074. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][4])
  5075. elif style == 'hardware':
  5076. m.tilemap[center_y-3][center_x-1].move_mes = '[Grimork\'s Hardware Store]'
  5077. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][5])
  5078. elif style == 'deco':
  5079. m.tilemap[center_y-3][center_x-1].move_mes = '[Larosa\'s Decoration Store]'
  5080. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][6])
  5081. elif style == 'book':
  5082. m.tilemap[center_y-3][center_x-1].move_mes = '[Xirazzzia\'s Bookshelf]'
  5083. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][7])
  5084. elif style == 'bomb':
  5085. m.tilemap[center_y-3][center_x-1].move_mes = '[Torguly\'s eXplozives Of al kinD]'
  5086. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][8])
  5087. elif style == 'general':
  5088. m.tilemap[center_y-3][center_x-1].move_mes = '[Arialu\'s General Store]'
  5089. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][9])
  5090. screen.render_load(19,90)
  5091. coin = random.randint(0,1)
  5092. if coin == 1:
  5093. pos = m.find_any(tl.tlist['dungeon'][1])
  5094. coin2 = random.randint(0,3)
  5095. if coin2 == 0:
  5096. replace = m.tilemap[pos[1]][pos[0]]
  5097. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['misc'][9])
  5098. m.tilemap[pos[1]][pos[0]].replace = replace
  5099. elif coin2 == 1:
  5100. replace = m.tilemap[pos[1]][pos[0]]
  5101. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['misc'][11])
  5102. m.tilemap[pos[1]][pos[0]].replace = replace
  5103. elif coin2 == 2:
  5104. m.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['cave'][2])
  5105. m.set_monster_strength(pos[0],pos[1],1)
  5106. else:
  5107. m.make_special_monsters(1,2,tl.tlist['dungeon'][1],1,'vase')
  5108. self.maplist[1][name] = m
  5109. screen.render_load(19,99)
  5110. def dungeon_generator(self,monster_plus,stair_down=True,num_traps=10,style='Dungeon'):#possible other style = 'Tomb'
  5111. #0: Basic initializing
  5112. screen.render_load(19,0)#Render progress bar 0%
  5113. if style == 'Tomb': #Set the graphics
  5114. tl.tlist['dungeon'][1].tile_pos = (4,6) #
  5115. tl.tlist['dungeon'][6].tile_pos = (4,7) #Sandstone walls,hidden doors and corridors for the acient tomb
  5116. tl.tlist['dungeon'][9].tile_pos = (4,7) #
  5117. else: #
  5118. tl.tlist['dungeon'][1].tile_pos = (10,6) #
  5119. tl.tlist['dungeon'][6].tile_pos = (2,6) #Default walls,hidden doors and corridors for the default dungeon
  5120. tl.tlist['dungeon'][9].tile_pos = (2,6) #
  5121. name = 'dungeon_0_0'#map name
  5122. tilemap = [] #Initializing a empty tilemap
  5123. for a in range (0,max_map_size): #
  5124. tilemap.append([]) #
  5125. for b in range (0,max_map_size): #
  5126. tilemap[a].append(0) #
  5127. m = maP(name,tilemap) #Generate a Map-object
  5128. if style == 'Tomb': #
  5129. m.map_type = 'tomb' #
  5130. m.set_music('tomb','tomb',True) #
  5131. else: #
  5132. m.map_type = 'dungeon' #and set a few constants for the new map
  5133. m.set_music('dungeon','dungeon',True)#
  5134. m.build_type = 'None' #
  5135. m.monster_plus = monster_plus #
  5136. m.monster_num = 0.3 #
  5137. m.no_monster_respawn = True #
  5138. m.fill(tl.tlist['dungeon'][9])#fill the map with dungeon wall tiles
  5139. screen.render_load(19,10)#Render progress bar 10%
  5140. #1: Set rooms
  5141. #Important fact: No matter how big the mapsize is set,
  5142. #dundeons only use the 52x52 tiles in the upper left connor.
  5143. #Thats as big as a small map.
  5144. test_build = True #Seperate the dungeon in a 3x3 grit.
  5145. while test_build: #Every part of the grit has a 66% chance to be a room
  5146. parts_with_rooms = [] #
  5147. #
  5148. for part_y in range(0,3): #
  5149. for part_x in range(0,3): #
  5150. ran = random.randint(0,9) #
  5151. if ran > 3: #
  5152. pick = (part_x,part_y) #
  5153. parts_with_rooms.append(pick) #
  5154. if len(parts_with_rooms) > 5: #every dungeon level needs at least 5 rooms
  5155. test_build = False #
  5156. coord_x = [] #transform the coordinates from the 3x3 grit into
  5157. coord_y = [] #real coordinates on the tilemap(center of the rooms)
  5158. #
  5159. for c in parts_with_rooms: #
  5160. x_offset = random.randint(0,5) #
  5161. y_offset = random.randint(0,5) #
  5162. #
  5163. real_x = 9+(15*c[0])+x_offset #
  5164. real_y = 9+(15*c[1])+y_offset #
  5165. #
  5166. coord_x.append(real_x) #
  5167. coord_y.append(real_y) #
  5168. m.imp_connect(coord_x,coord_y,tl.tlist['dungeon'][1],tl.tlist['dungeon'][0],tl.tlist['dungeon'][0])#connect the room cooardinathe with corridor
  5169. for i in range(0,len(coord_x)-1):#set variable roome size for all rooms
  5170. x_minus = random.randint(2,4)#
  5171. x_plus = random.randint(3,5) #
  5172. y_minus = random.randint(2,4)#
  5173. y_plus = random.randint(3,5) #
  5174. for yy in range(coord_y[i]-y_minus-1,coord_y[i]+y_plus+1): #draw walls around the rooms
  5175. for xx in range(coord_x[i]-x_minus-1,coord_x[i]+x_plus+1): #
  5176. m.tilemap[yy][xx] = deepcopy(tl.tlist['dungeon'][9]) #
  5177. for yy in range(coord_y[i]-y_minus,coord_y[i]+y_plus): #draw the room floor
  5178. for xx in range(coord_x[i]-x_minus,coord_x[i]+x_plus): #
  5179. m.tilemap[yy][xx] = tl.tlist['dungeon'][0] #
  5180. screen.render_load(19,25) #progress bar 25%
  5181. #2: Set doors
  5182. for yyy in range(0,52):
  5183. for xxx in range(0,52): #the 52 is hard scripted to safe performance
  5184. if m.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][9].techID: #Set all tiles that are surrounded by two moveable tiles on two opponent sides as doors
  5185. if m.tilemap[yyy-1][xxx].move_group == 'soil' and m.tilemap[yyy+1][xxx].move_group == 'soil': #
  5186. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][3] #
  5187. elif m.tilemap[yyy][xxx-1].move_group == 'soil' and m.tilemap[yyy][xxx+1].move_group == 'soil': #
  5188. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][3] #
  5189. for yyy in range(0,52):
  5190. for xxx in range(0,52): #the 52 is hard scripted to safe performance
  5191. if m.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][3].techID: #Remove all doors that are next to another door.
  5192. size = m.get_quarter_size(xxx,yyy) #Only spare one door per wall
  5193. if size[0] > 1: #
  5194. for rx in range(xxx,xxx+size[0]+1): #
  5195. m.tilemap[yyy][rx] = deepcopy(tl.tlist['dungeon'][9]) #
  5196. rrx = int(xxx+((rx-xxx)/2)) #
  5197. m.tilemap[yyy][rrx] = tl.tlist['dungeon'][3] #
  5198. #
  5199. if m.tilemap[yyy-1][rrx].move_group != 'soil': #
  5200. m.tilemap[yyy-1][rrx] = tl.tlist['dungeon'][1] #
  5201. if m.tilemap[yyy+1][rrx].move_group != 'soil': #
  5202. m.tilemap[yyy+1][rrx] = tl.tlist['dungeon'][1] #
  5203. #
  5204. if size[1] > 1: #
  5205. for ry in range(yyy,yyy+size[1]+1): #
  5206. m.tilemap[ry][xxx] = deepcopy(tl.tlist['dungeon'][9]) #
  5207. rry = int(yyy+((ry-yyy)/2)) #
  5208. m.tilemap[rry][xxx] = tl.tlist['dungeon'][3] #
  5209. #
  5210. if m.tilemap[rry][xxx-1].move_group != 'soil': #
  5211. m.tilemap[rry][xxx-1] = tl.tlist['dungeon'][1] #
  5212. if m.tilemap[rry][xxx+1].move_group != 'soil': #
  5213. m.tilemap[rry][xxx+1] = tl.tlist['dungeon'][1] #
  5214. screen.render_load(19,40)#Render progress bar 40%
  5215. test = deepcopy(m) #Make a copy of the map as is
  5216. pos = test.find_first(tl.tlist['dungeon'][0]) #and performe a float test,
  5217. test.floating(pos[0],pos[1],tl.tlist['misc'][0],tl.tlist['dungeon'][9]) #in order to find not conected parts.
  5218. screen.render_load(19,50) #Render progress bar 50%
  5219. for yyy in range(0,52): #Remove not connected parts
  5220. for xxx in range(0,52): #
  5221. if test.tilemap[yyy][xxx].techID != tl.tlist['dungeon'][9].techID and test.tilemap[yyy][xxx].techID != tl.tlist['misc'][0].techID: #
  5222. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][9] #
  5223. screen.render_load(19,60)#Render progress bar 60%
  5224. for yyy in range(0,52): #Randomize doors:
  5225. for xxx in range(0,52): #-normal door
  5226. #-resisting door
  5227. if m.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][3].techID: #-etc.
  5228. ran = random.randint(3,6) #
  5229. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][ran] #
  5230. if m.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][9].techID: #Randomize wall design
  5231. ran_test = random.randint(0,99) #
  5232. if ran_test > 75: #
  5233. if style == 'Dungeon': #
  5234. ran = random.randint(0,2) #
  5235. m.tilemap[yyy][xxx].tile_pos = (11,0+ran) #
  5236. if style == 'Tomb': #
  5237. ran = random.randint(0,2) #
  5238. m.tilemap[yyy][xxx].tile_pos = (12,0+ran) #
  5239. screen.render_load(19,70)#Render progress bar 70%
  5240. #3: Make stairs
  5241. stair_up_pos = m.find_any(tl.tlist['dungeon'][0]) #Set a up leading stair on any floor tile.
  5242. entrance_x = stair_up_pos[0] #
  5243. entrance_y = stair_up_pos[1] #
  5244. if style == 'Tomb': #
  5245. m.tilemap[stair_up_pos[1]][stair_up_pos[0]] = tl.tlist['dungeon'][19] #
  5246. else: #
  5247. m.tilemap[stair_up_pos[1]][stair_up_pos[0]] = tl.tlist['dungeon'][8] #
  5248. for sy in range(stair_up_pos[1]-4,stair_up_pos[1]+5):
  5249. for sx in range(stair_up_pos[0]-4,stair_up_pos[0]+5):
  5250. try:
  5251. if m.tilemap[sy][sx].move_group == 'soil':
  5252. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  5253. m.tilemap[sy][sx].move_group = 'dry_entrance'
  5254. elif m.tilemap[sy][sx].move_group == 'low_liquid':
  5255. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  5256. m.tilemap[sy][sx].move_group = 'wet_entrance'
  5257. except:
  5258. None
  5259. if stair_down == True: #If we are not on the deepest lvl:
  5260. stair_down_pos = m.find_any(tl.tlist['dungeon'][0]) #Set a down leading stair on any floor tile.
  5261. if style == 'Tomb': #
  5262. m.tilemap[stair_down_pos[1]][stair_down_pos[0]] = tl.tlist['dungeon'][18] #
  5263. else: #
  5264. m.tilemap[stair_down_pos[1]][stair_down_pos[0]] = tl.tlist['dungeon'][7] #
  5265. else: #Make a chest whit a reward on the deepest lvl instead
  5266. chest_pos = m.find_any(tl.tlist['dungeon'][0]) #
  5267. m.tilemap[chest_pos[1]][chest_pos[0]] = tl.tlist['dungeon'][20] #
  5268. m.tilemap[chest_pos[1]][chest_pos[0]].replace = tl.tlist['dungeon'][0] #
  5269. if style == 'Tomb':
  5270. m.add_container([il.ilist['special_clothe'][0],il.ilist['misc'][33],il.ilist['misc'][40]],chest_pos[0],chest_pos[1])# set the interior of the chest
  5271. else: #
  5272. m.add_container([il.ilist['special_clothe'][1],il.ilist['misc'][33],il.ilist['misc'][41]],chest_pos[0],chest_pos[1])#
  5273. for h in range(0,len(ml.mlist['vip_cage'])): #set vip_cages
  5274. p = m.find_any(tl.tlist['dungeon'][0]) #
  5275. m.npcs[p[1]][p[0]] = deepcopy(ml.mlist['vip_cage'][h]) #
  5276. m.set_monster_strength(p[0],p[1],1,lvl_bonus = 9) #
  5277. screen.render_load(19,80)#Render progress bar 80%
  5278. #4: Make Traps
  5279. for i in range(0,num_traps): #Set hidden traps on random floor tiles.
  5280. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5281. replace = m.tilemap[pos[1]][pos[0]] #
  5282. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['dungeon'][10]) #Traps have to be deepcopied to work proper.
  5283. m.tilemap[pos[1]][pos[0]].replace = replace #
  5284. screen.render_load(19,90) #Render Progress bar 90%
  5285. #5: Make interior
  5286. num_rooms = len(parts_with_rooms) #Make chests with random loot
  5287. m.make_containers(int(num_rooms/3),int(num_rooms/2),tl.tlist['dungeon'][0],1,3,'chest') #
  5288. for c in range(0,num_rooms): #Set random fontains on floor tiles
  5289. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5290. ran = random.randint(0,99) #
  5291. if ran < 15: #
  5292. tile = deepcopy(tl.tlist['dungeon'][12]) #acid fontain
  5293. elif ran > 84: #
  5294. tile = deepcopy(tl.tlist['dungeon'][13]) #healing fontain
  5295. else: #
  5296. tile = deepcopy(tl.tlist['functional'][7]) #fontain
  5297. tile.civilisation = False #
  5298. tile.build_here = False #
  5299. tile.can_grown = False #
  5300. tile.replace = tl.tlist['dungeon'][0] #
  5301. m.tilemap[pos[1]][pos[0]] = tile #
  5302. coin = random.randint(0,1) #Set a Altar on 50% of all maps
  5303. if coin == 1: #that are generated with this function
  5304. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5305. tile = deepcopy(tl.tlist['functional'][15]) #
  5306. tile.civilisation = False #
  5307. tile.build_here = False #
  5308. tile.can_grown = False #
  5309. tile.replace = tl.tlist['dungeon'][0] #
  5310. m.tilemap[pos[1]][pos[0]] = tile #
  5311. num_statue = random.randint(4,6) #generate random statues
  5312. for l in range(0,num_statue): #
  5313. kind = random.randint(0,len(tl.tlist['statue'])-1) #
  5314. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5315. tile = deepcopy(tl.tlist['statue'][kind]) #
  5316. tile.replace = tl.tlist['dungeon'][0] #
  5317. m.tilemap[pos[1]][pos[0]] = tile #
  5318. num_deco = random.randint(8,10) #generate random deco
  5319. for l in range(0,num_deco): #
  5320. if style == 'Tomb': #
  5321. kind = random.randint(3,5) #
  5322. else: #
  5323. kind = random.randint(0,2) #
  5324. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5325. tile = deepcopy(tl.tlist['deco'][kind]) #
  5326. tile.replace = tl.tlist['dungeon'][0] #
  5327. m.tilemap[pos[1]][pos[0]] = tile #
  5328. num_cage = random.randint(1,2) #spawn cages
  5329. for q in range(0,num_cage): #
  5330. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5331. m.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['cage'][random.randint(0,len(ml.mlist['cage'])-1)]) #
  5332. m.set_monster_strength(pos[0],pos[1],1,lvl_bonus=9) #
  5333. m.spawn_monsters(0) #Spawn initial monsters
  5334. m.make_special_monsters(10,20,tl.tlist['dungeon'][0],m.monster_plus,'vase') #
  5335. m.make_special_monsters(1,2,tl.tlist['dungeon'][0],m.monster_plus,'mimic') #
  5336. if style == 'Tomb': #
  5337. m.make_special_monsters(1,3,tl.tlist['dungeon'][0],m.monster_plus,'demonic chest') #
  5338. coin = random.randint(0,1)
  5339. if coin == 1:
  5340. m.spawn_magic_shops()
  5341. self.maplist[1][name] = m # Add map to world.maplist
  5342. screen.render_load(19,99) #Render progress bar 99%
  5343. def desert_generator(self,chance_object):
  5344. #chance_objects must be between 0 and 99
  5345. screen.render_load(18,1)
  5346. name = 'desert_0_0'
  5347. tilemap = []
  5348. for a in range (0,max_map_size):
  5349. tilemap.append([])
  5350. for b in range (0,max_map_size):
  5351. tilemap[a].append(0)
  5352. m = maP(name,tilemap)
  5353. m.map_type = 'desert'
  5354. m.build_type = 'Full'
  5355. m.monster_plus = 7
  5356. m.thirst_multi_day = 2
  5357. m.set_music('desert','night',True)
  5358. m.fill(tl.tlist['extra'][0])
  5359. y_river = random.randint((17),(max_map_size-17))
  5360. river_offset = random.randint(-3,3)
  5361. plus = 0
  5362. minus = 0
  5363. screen.render_load(18,20)
  5364. for c in range (0,max_map_size):
  5365. for g in range (-2,7):
  5366. m.tilemap[y_river+river_offset+g][c] = tl.tlist['local'][0]#set grass
  5367. for w in range (0,5):
  5368. m.tilemap[y_river+river_offset+w][c] = tl.tlist['misc'][0]#set low water
  5369. if river_offset < 4:
  5370. plus = 1
  5371. else:
  5372. plus = 0
  5373. if river_offset > -4:
  5374. minus = -1
  5375. else:
  5376. minus = 0
  5377. offset_change = random.randint(minus,plus)
  5378. river_offset += offset_change
  5379. m.exchange_when_surrounded(tl.tlist['misc'][0],tl.tlist['misc'][3],7)
  5380. screen.render_load(18,40)
  5381. for b in range(2,max_map_size-2,10):
  5382. #north side of the river
  5383. building_offset =random.randint(0,4)
  5384. number_beds = 0
  5385. for y in range(y_river-12,y_river-7):
  5386. for x in range(b+building_offset,b+building_offset+5):
  5387. if x == b+building_offset or x == b+building_offset+4:
  5388. if y == y_river-10:
  5389. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5390. else:
  5391. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5392. elif y == y_river-12 or y == y_river-8:
  5393. if x == b+building_offset+2:
  5394. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5395. else:
  5396. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5397. else:
  5398. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][1])
  5399. if x == b+building_offset+1 or x == b+building_offset+3:
  5400. if y == y_river-11 or y == y_river-9:
  5401. obj_here = random.randint(0,2) #0: nothing, 1:bed 2:workbench
  5402. if number_beds == 0:
  5403. obj_here = 1
  5404. if obj_here != 0:
  5405. if obj_here == 1:
  5406. obj = ('functional',8)
  5407. number_beds += 1
  5408. else:
  5409. ran = random.randint(9,15)
  5410. obj = ('functional',ran)
  5411. m.tilemap[y][x] = deepcopy(tl.tlist[obj[0]][obj[1]])
  5412. m.tilemap[y][x].replace = deepcopy(tl.tlist['extra'][1])
  5413. m.tilemap[y][x].civilisation = False
  5414. m.tilemap[y][x].build_here = False
  5415. m.tilemap[y][x].move_group = 'house'
  5416. #south side of the river
  5417. building_offset = random.randint(0,4)
  5418. number_beds = 0
  5419. screen.render_load(18,60)
  5420. for y in range(y_river+8,y_river+13):
  5421. for x in range(b+building_offset,b+building_offset+5):
  5422. if x == b+building_offset or x == b+building_offset+4:
  5423. if y == y_river+10:
  5424. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5425. else:
  5426. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5427. elif y == y_river+12 or y == y_river+8:
  5428. if x == b+building_offset+2:
  5429. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5430. else:
  5431. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5432. else:
  5433. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][1])
  5434. if x == b+building_offset+1 or x == b+building_offset+3:
  5435. if y == y_river+9 or y == y_river+11:
  5436. obj_here = random.randint(0,2) #0: nothing, 1:bed 2:workbench
  5437. if number_beds == 0:
  5438. obj_here = 1
  5439. if obj_here != 0:
  5440. if obj_here == 1:
  5441. obj = ('functional',8)
  5442. number_beds += 1
  5443. else:
  5444. ran = random.randint(9,15)
  5445. obj = ('functional',ran)
  5446. m.tilemap[y][x] = deepcopy(tl.tlist[obj[0]][obj[1]])
  5447. m.tilemap[y][x].replace = deepcopy(tl.tlist['extra'][1])
  5448. m.tilemap[y][x].civilisation = False
  5449. m.tilemap[y][x].build_here = False
  5450. m.tilemap[y][x].move_group = 'house'
  5451. make_bridges = True
  5452. num_bridges = 0
  5453. num_bridges_max = ((max_map_size/50)*3)+1
  5454. screen.render_load(18,80)
  5455. while num_bridges < num_bridges_max:
  5456. x_pos = random.randint(5,max_map_size-5)
  5457. num_wall = 0
  5458. for test in range(0,max_map_size):
  5459. if m.tilemap[test][x_pos].techID == tl.tlist['extra'][2].techID:
  5460. num_wall += 1
  5461. if num_wall == 0:
  5462. num_bridges += 1
  5463. for y in range(0,max_map_size):
  5464. if m.tilemap[y][x_pos].techID == tl.tlist['misc'][0].techID or m.tilemap[y][x_pos].techID == tl.tlist['misc'][3].techID: #this is low wather or deep water
  5465. replace = deepcopy(m.tilemap[y][x_pos])
  5466. m.tilemap[y][x_pos] = deepcopy(tl.tlist['extra'][8])
  5467. m.tilemap[y][x_pos].replace = replace
  5468. for y in range (0,max_map_size):
  5469. for x in range (0,max_map_size):
  5470. if m.tilemap[y][x].techID == tl.tlist['extra'][0].techID:
  5471. chance = random.randint(0,99)
  5472. if chance < chance_object:
  5473. obj_numbers = (3,4,5,14)
  5474. coin = random.randint(0,len(obj_numbers)-1)
  5475. m.tilemap[y][x] = tl.tlist['extra'][obj_numbers[coin]]
  5476. m.tilemap[y][x].replace = tl.tlist['extra'][0]#sand
  5477. elif m.tilemap[y][x].techID == tl.tlist['local'][0].techID:
  5478. chance = random.randint(0,99)
  5479. if chance < chance_object:
  5480. coin = random.randint(10,13)
  5481. m.tilemap[y][x] = tl.tlist['extra'][coin]
  5482. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  5483. elif m.tilemap[y][x].techID == tl.tlist['extra'][9].techID:
  5484. for yy in range(y-1,y+2):
  5485. if m.tilemap[yy][x].replace != None:
  5486. m.tilemap[yy][x] = m.tilemap[yy][x].replace
  5487. for xx in range(x-1,x+2):
  5488. if m.tilemap[y][xx].replace != None:
  5489. m.tilemap[y][xx] = m.tilemap[y][xx].replace
  5490. if m.tilemap[y][x].techID == tl.tlist['functional'][8].techID:#bed
  5491. ran = random.randint(5,6)
  5492. m.npcs[y][x] = deepcopy(ml.mlist['special'][ran])
  5493. m.set_monster_strength(x,y,0)
  5494. m.set_frame(tl.tlist['functional'][0])
  5495. screen.render_load(18,99)
  5496. #set portal
  5497. y = 2
  5498. x = random.randint(2,max_map_size-2)
  5499. m.tilemap[y][x] = tl.tlist['portal'][5]
  5500. m.tilemap[y][x].replace = tl.tlist['extra'][0]#sand
  5501. m.tilemap[y+1][x] = tl.tlist['extra'][0]#sand
  5502. #set tomb
  5503. ran_pos = m.find_any(tl.tlist['extra'][0])
  5504. m.tilemap[ran_pos[1]][ran_pos[0]] = tl.tlist['dungeon'][18]
  5505. m.spawn_monsters(0)
  5506. self.maplist[0][name] = m
  5507. def choose_size(self):
  5508. #this is a all in one function with render, choose and set
  5509. global max_map_size # I know its no good style
  5510. run = True
  5511. mms = 52 #this is a temp variable that is used to store the worth for the max_map_size till this function is called
  5512. num = 0
  5513. while run:
  5514. #Part 1: Render
  5515. if low_res == False:
  5516. s = pygame.Surface((640,360))
  5517. else:
  5518. s = pygame.Surface((320,240))
  5519. bg = pygame.Surface((480,360))
  5520. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  5521. if low_res == True:
  5522. bg = pygame.transform.scale(bg,(320,240))
  5523. s.blit(bg,(0,0))
  5524. text = '~Choose Map-Size~ [Press ['+key_name['e']+'] to choose]'
  5525. text_image = screen.font.render(text,1,(255,255,255))
  5526. s.blit(text_image,(5,2))#menue title
  5527. entries = ('Small (50x50)', 'Medium (100x100)', 'Big (150x150)')
  5528. messages = ('Everything on a very small space.', 'Perfect size for the most players.', 'A big world.')
  5529. mapsizes = (52,102,152)
  5530. for i in range (0,3):
  5531. entry_image = screen.font.render(entries[i],1,(0,0,0))
  5532. if low_res == False:
  5533. s.blit(entry_image,(21,150+i*30))#blit menu_items
  5534. else:
  5535. s.blit(entry_image,(21,66+i*25))#blit menu_items
  5536. if low_res == False:
  5537. s.blit(gra_files.gdic['display'][4],(0,145+num*30))#blit marker
  5538. else:
  5539. s.blit(gra_files.gdic['display'][4],(0,58+num*25))#blit marker
  5540. entry_image = screen.font.render(messages[num],1,(255,255,255))
  5541. if low_res == True:
  5542. s.blit(entry_image,(2,225))
  5543. else:
  5544. s.blit(entry_image,(5,335))
  5545. if game_options.mousepad == 1 and low_res == False:
  5546. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  5547. else:
  5548. s_help = pygame.Surface((160,360))
  5549. s_help.fill((48,48,48))
  5550. s.blit(s_help,(480,0))
  5551. if game_options.mousepad == 0 and low_res == False:
  5552. s_help = pygame.Surface((640,360))
  5553. s_help.fill((48,48,48))
  5554. s_help.blit(s,(80,0))
  5555. s = s_help
  5556. if low_res == False:
  5557. s = pygame.transform.scale(s,(screen.displayx,screen.displayy))
  5558. screen.screen.blit(s,(0,0))
  5559. pygame.display.flip()
  5560. #Step 2: Choose
  5561. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  5562. if ui == 'w':
  5563. num -= 1
  5564. if num < 0:
  5565. num = 2
  5566. if ui == 's':
  5567. num += 1
  5568. if num > 2:
  5569. num = 0
  5570. if ui == 'e':
  5571. mms = mapsizes[num]
  5572. max_map_size = mms
  5573. self.map_size = mms
  5574. run = False
  5575. class mob():
  5576. def __init__(self, name, on_map, attribute, pos =[40,40,0],glob_pos=[0,0],build='Manual'):
  5577. self.name = name
  5578. self.on_map = on_map
  5579. self.attribute = attribute
  5580. self.lp = attribute.max_lp
  5581. self.mp = attribute.max_mp
  5582. self.pos = pos
  5583. self.glob_pos = glob_pos
  5584. self.last_map = 'Foo'
  5585. self.cur_map = 'Bar'
  5586. self.cur_z = self.pos[2]
  5587. self.last_z = 'Baz'
  5588. def move(self, x=0, y=0):
  5589. mc = self.move_check(x,y)
  5590. tile_move_group = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group
  5591. player_move_groups = ['soil','low_liquid','shop','house','wet_entrance','dry_entrance']
  5592. swim_check = True
  5593. for i in ('Head','Body','Legs','Feet'):
  5594. if player.inventory.wearing[i] != player.inventory.nothing:
  5595. swim_check = False
  5596. if swim_check == True:
  5597. player_move_groups.append('swim')
  5598. if player.buffs.hexed < 1:
  5599. player_move_groups.append('holy')
  5600. if self.buffs.immobilized > 0:
  5601. player_move_groups = ['not_existent_group1','not_existent_group2']
  5602. move_check2 = False
  5603. for j in player_move_groups:
  5604. if j == tile_move_group:
  5605. move_check2 = True
  5606. if mc == True:
  5607. if x > 0 and move_check2 == True and self.pos[0] < max_map_size - 1:
  5608. self.pos[0] += 1
  5609. if x < 0 and move_check2 == True and self.pos[0] > 0:
  5610. self.pos[0] -= 1
  5611. if y > 0 and move_check2 == True and self.pos[1] < max_map_size - 1:
  5612. self.pos[1] += 1
  5613. if y < 0 and move_check2 == True and self.pos[1] > 0:
  5614. self.pos[1] -= 1
  5615. self.stand_check()
  5616. def move_check(self,x,y):
  5617. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'door':
  5618. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID == tl.tlist['dungeon'][4].techID or world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID == tl.tlist['dungeon'][5].techID or world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID == tl.tlist['dungeon'][6].techID:
  5619. #this is a resisting door or a hidden door
  5620. sfx.play('locked')
  5621. else:
  5622. sfx.play('open')
  5623. message.add(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_mes)
  5624. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace
  5625. return False
  5626. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'shop_enter':
  5627. sfx.play('open')
  5628. screen.render_fade(True,False)
  5629. shop_types = ('pharmacy','pickaxe','hardware','deco','book','bomb','general')
  5630. ran = random.randint(0,len(shop_types)-1)
  5631. world.shop_generator(shop_types[ran])
  5632. self.save_pos=(self.pos[0],self.pos[1],self.pos[2],self.on_map)
  5633. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace
  5634. shop_pos = world.maplist[1]['shop_0_0'].find_first(tl.tlist['shop'][3])
  5635. self.pos[0] = shop_pos[0]
  5636. self.pos[1] = shop_pos[1]+1
  5637. self.pos[2] = 1
  5638. self.on_map = 'shop_0_0'
  5639. player.stand_check()
  5640. screen.render_fade(False,True)
  5641. return False
  5642. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'shop_exit':
  5643. sfx.play('open')
  5644. self.pos[0] = self.save_pos[0]
  5645. self.pos[1] = self.save_pos[1]
  5646. self.pos[2] = self.save_pos[2]
  5647. self.on_map = self.save_pos[3]
  5648. player.stand_check()
  5649. screen.render_fade(False,True)
  5650. return False
  5651. try:
  5652. if world.maplist[self.pos[2]][self.on_map].npcs[self.pos[1]+y][self.pos[0]+x] != 0:
  5653. player.attack_monster(self.pos[0]+x,self.pos[1]+y)
  5654. return False
  5655. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].destroy != False: #for digging
  5656. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID == tl.tlist['misc'][28].techID:#this is obsidian
  5657. heated_stone = True
  5658. else:
  5659. heated_stone = False
  5660. if player.pos[2] > 3 and heated_stone == False:
  5661. brimstone = True
  5662. else:
  5663. brimstone = False
  5664. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID != tl.tlist['misc'][28].techID and world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID != tl.tlist['global_caves'][2].techID:
  5665. #this is not obsidian or soft soil
  5666. stone = True
  5667. else:
  5668. stone = False
  5669. if self.attribute.pickaxe_power + player.inventory.wearing['Pickaxe'].attribute.pickaxe_power >= world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].destroy:
  5670. if self == player:
  5671. message.add(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_mes)
  5672. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID != tl.tlist['building'][3].techID: #this isn't a door
  5673. sfx.play('break')
  5674. try:
  5675. if self.skill.mining == 'Adept':
  5676. mat_addition = 2
  5677. elif self.skill.mining == 'Master':
  5678. mat_addition = 5
  5679. else:
  5680. mat_addition = 0
  5681. material = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[0]
  5682. mat_num = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[1] + mat_addition
  5683. mes = player.inventory.materials.add(material,mat_num)
  5684. message.add(mes)
  5685. if player.skill.mining != 'Master':
  5686. player.skill.mining_progress += 1
  5687. if player.skill.mining_progress == 200 and player.skill.mining != 'Adept':
  5688. player.skill.raise_skill('mining')
  5689. message.add('Your mining skill reaches adept level!')
  5690. sfx.play('lvl_up')
  5691. if player.skill.mining_progress == 1000 and player.skill.mining != 'Master':
  5692. player.skill.raise_skill('mining')
  5693. message.add('Your mining skill reaches master level!')
  5694. sfx.play('lvl_up')
  5695. except:
  5696. None
  5697. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID == tl.tlist['building'][3].techID: #this is a closed door
  5698. world.maplist[self.pos[2]][self.on_map].countdowns.append(countdown('door', self.pos[0]+x, self.pos[1]+y,3))
  5699. sfx.play('open')
  5700. stone = False
  5701. heated_stone = False
  5702. brimstone = False
  5703. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace)
  5704. if heated_stone == True:#drop heated stone
  5705. ran = random.randint(0,99)
  5706. if ran < 5:
  5707. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x]
  5708. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][28])
  5709. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  5710. elif brimstone == True:#drop brimstone
  5711. ran = random.randint(0,99)
  5712. if ran < 5:
  5713. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x]
  5714. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][29])
  5715. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  5716. elif stone == True:#drop stone
  5717. ran = random.randint(0,99)
  5718. if ran < 5:
  5719. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x]
  5720. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][30])
  5721. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  5722. if player.inventory.wearing['Pickaxe'] != player.inventory.nothing and world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID != tl.tlist['building'][3].techID:
  5723. player.inventory.wearing['Pickaxe'].take_damage()
  5724. if player.inventory.wearing['Pickaxe'].state > 0:
  5725. player.inventory.wearing['Pickaxe'].set_name()
  5726. else:
  5727. message.add('Your tool breaks into pieces.')
  5728. player.inventory.wearing['Pickaxe'] = player.inventory.nothing
  5729. sfx.play('item_break')
  5730. else:
  5731. if self == player:
  5732. message.add('You are unable to destroy this with the tool in your hand.')
  5733. return False
  5734. else:
  5735. None
  5736. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'tree':
  5737. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID == tl.tlist['local'][12].techID:#this is a ordenary tree
  5738. apple = True
  5739. else:
  5740. apple = False
  5741. if player.inventory.wearing['Axe'] != player.inventory.nothing: #if player has a axe in his hand
  5742. chop_success = True
  5743. player.inventory.wearing['Axe'].take_damage()
  5744. if player.inventory.wearing['Axe'].state > 0:
  5745. player.inventory.wearing['Axe'].set_name()
  5746. else:
  5747. message.add('Your axe breaks into pieces.')
  5748. player.inventory.wearing['Axe'] = player.inventory.nothing
  5749. sfx.play('item_break')
  5750. else:
  5751. message.add('That hurts!')
  5752. player.lp -= 1
  5753. sfx.play('hit')
  5754. if random.randint(0,9) != 0: #90% to fail chopping down the wood with bare hands
  5755. chop_success = False
  5756. else:
  5757. chop_success = True
  5758. if chop_success == True:
  5759. if self.skill.woodcutting == 'Adept':
  5760. mat_addition = 2
  5761. elif self.skill.woodcutting == 'Master':
  5762. mat_addition = 5
  5763. else:
  5764. mat_addition = 0
  5765. material = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[0]
  5766. mat_num = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[1] + mat_addition
  5767. mes = player.inventory.materials.add(material,mat_num)
  5768. message.add(mes)
  5769. sfx.play('chop')
  5770. if player.skill.woodcutting != 'Master':
  5771. player.skill.woodcutting_progress += 1
  5772. if player.skill.woodcutting_progress == 200 and player.skill.woodcutting != 'Adept':
  5773. player.skill.raise_skill('woodcutting')
  5774. message.add('Your woodcutting skill reaches adept level!')
  5775. sfx.play('lvl_up')
  5776. if player.skill.woodcutting_progress == 1000 and player.skill.woodcutting != 'Master':
  5777. player.skill.raise_skill('woodcutting')
  5778. message.add('Your woodcutting skill reaches master level!')
  5779. sfx.play('lvl_up')
  5780. world.maplist[self.pos[2]][self.on_map].make_monsters_angry(self.pos[0],self.pos[1],'tree')
  5781. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace) #let the tree disappear
  5782. if apple == True:
  5783. ran = random.randint(0,99)
  5784. if ran < 5:
  5785. ran2 = random.randint(0,99)
  5786. replace = deepcopy(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x])
  5787. if ran2 < 20:
  5788. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][32])
  5789. else:
  5790. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][31])
  5791. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  5792. return False
  5793. if self.buffs.immobilized == 0:
  5794. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'low_liquid' or world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'swim' or world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'wet_entrance':
  5795. sfx.play('walk_wet')
  5796. else:
  5797. sfx.play('walk_dry')
  5798. else:
  5799. sfx.play('immobilized')
  5800. return True
  5801. except:
  5802. None
  5803. def stand_check(self):
  5804. if self.on_map != 'shop_0_0':
  5805. if self.on_map != self.cur_map:
  5806. self.last_map = self.cur_map
  5807. self.cur_map = self.on_map
  5808. if self.pos[2] != self.cur_z:
  5809. self.last_z = self.cur_z
  5810. self.cur_z = self.pos[2]
  5811. world.maplist[self.pos[2]][self.on_map].special_check(self.pos[0],self.pos[1])
  5812. radius = 5
  5813. if player.pos[2] > 0:
  5814. radius = 2
  5815. elif player.pos[2] == 0:
  5816. if time.hour > 22 or time.hour < 4:
  5817. radius = 2
  5818. elif time.hour > 21 or time.hour < 5:
  5819. radius = 3
  5820. elif time.hour > 20 or time.hour < 6:
  5821. radius = 4
  5822. elif time.hour > 19 or time.hour < 7:
  5823. radius = 5
  5824. if player.buffs.light > 0 or player.buffs.nightvision > 0:
  5825. radius = 5
  5826. if player.buffs.blind > 0:
  5827. radius = 1
  5828. message.add(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].move_mes,True)
  5829. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage > 0 and player.buffs.fireresistance == 0:
  5830. self.lp = self.lp - world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage
  5831. if self == player:
  5832. try:
  5833. message.add(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage_mes + ' (' + str(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage) + ' Damage)')
  5834. except:
  5835. None
  5836. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage > 0 and world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].special_group == 'hot':
  5837. sfx_flame = False
  5838. body_list = ('Head','Body','Legs','Feet','Hold(R)','Hold(L)','Neck','Hand','Pickaxe','Axe')
  5839. for i in body_list:
  5840. if player.inventory.wearing[i] != player.inventory.nothing and player.inventory.wearing[i].material == 'wooden':
  5841. ran = random.randint(0,9)
  5842. if ran < 4:
  5843. message.add('Your '+player.inventory.wearing[i].name+' burns to ashes!')
  5844. player.inventory.wearing[i] = player.inventory.nothing
  5845. sfx_flame = True
  5846. if sfx_flame == True:
  5847. sfx.play('flame')
  5848. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage < 0:
  5849. if self.lp < self.attribute.max_lp:
  5850. self.lp = self.lp - world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage
  5851. luck = player.attribute.luck + player.inventory.wearing['Neck'].attribute.luck
  5852. for y in range(player.pos[1]-1,player.pos[1]+2):
  5853. for x in range(player.pos[0]-1,player.pos[0]+2):
  5854. if world.maplist[self.pos[2]][self.on_map].tilemap[y][x].techID == tl.tlist['dungeon'][6].techID:#this is a secret door
  5855. ran = random.randint(0,25)#check players luck
  5856. if ran < luck:
  5857. world.maplist[self.pos[2]][self.on_map].tilemap[y][x] = deepcopy(tl.tlist['dungeon'][3])
  5858. message.add('You notice a hidden door.')
  5859. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  5860. screen.write_hit_matrix(x,y,15)
  5861. sfx.play('found')
  5862. if world.maplist[self.pos[2]][self.on_map].tilemap[y][x].techID == tl.tlist['dungeon'][10].techID and world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos == (10,10):#this is a trap which isn't already found
  5863. ran = random.randint(0,25)#check players luck
  5864. if ran < luck:
  5865. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos = (10,8)
  5866. message.add('You notice a trap.')
  5867. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  5868. screen.write_hit_matrix(x,y,15)
  5869. sfx.play('found')
  5870. if world.maplist[self.pos[2]][self.on_map].tilemap[y][x].techID == tl.tlist['dungeon'][12].techID and world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos == (6,3,10,12):#this is a fontain that isn't already known
  5871. ran = random.randint(0,15)#check players luck
  5872. if ran < luck:
  5873. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos = (12,11,12,12)
  5874. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].use_group = 'dont_drink'
  5875. message.add('You notice a strange smell.')
  5876. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  5877. screen.write_hit_matrix(x,y,15)
  5878. sfx.play('found')
  5879. if world.maplist[self.pos[2]][self.on_map].tilemap[y][x].techID == tl.tlist['dungeon'][13].techID and world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos == (6,3,10,12):#this is a fontain that isn't already known
  5880. ran = random.randint(0,15)#check players luck
  5881. if ran < luck:
  5882. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos = (11,11,11,12)
  5883. message.add('You notice a strange sparkle.')
  5884. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  5885. screen.write_hit_matrix(x,y,15)
  5886. sfx.play('found')
  5887. for y in range (-radius,radius+1):#line of sight
  5888. for x in range (-radius,radius+1):
  5889. try:
  5890. dist = ((x)**2+(y)**2)**0.5
  5891. if dist <= radius+1 or dist >= radius-1:
  5892. run = True
  5893. c = 0
  5894. while run:
  5895. try:
  5896. yy = ((y*c)/dist)
  5897. except:
  5898. yy = 1
  5899. try:
  5900. xx = ((x*c)/dist)
  5901. except:
  5902. xx = 1
  5903. view_x = int(xx) + self.pos[0]
  5904. view_y = int(yy) + self.pos[1]
  5905. world.maplist[self.pos[2]][self.on_map].known[view_y][view_x] = 1
  5906. if world.maplist[self.pos[2]][self.on_map].tilemap[view_y][view_x].transparency == True and c < radius:
  5907. c+=1
  5908. else:
  5909. run = False
  5910. except:
  5911. None
  5912. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].techID == tl.tlist['dungeon'][10].techID:
  5913. kind =random.randint(0,3)
  5914. position = deepcopy(player.pos)#copy player pos before the trap is triggered because teleport traps could change it
  5915. if kind == 0:#dart trap
  5916. ran = random.randint(0,25)
  5917. if ran < luck:
  5918. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  5919. message.add('A flying dagger miss you.')
  5920. sfx.play('miss')
  5921. else:
  5922. player.lp -= 3
  5923. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  5924. message.add('A flying dagger hits you.')
  5925. sfx.play('hit')
  5926. elif kind == 1:#teleport trap
  5927. t=world.maplist[self.pos[2]][self.on_map].find_all_moveable()
  5928. if len(t) > 0:
  5929. rt = []
  5930. for i in t:
  5931. if world.maplist[self.pos[2]][self.on_map].npcs[i[1]][i[0]] == 0:
  5932. rt.append((i[0],i[1]))
  5933. if len(rt) > 0:
  5934. screen.render_fade(True,False)
  5935. ran = random.randint(0,len(rt)-1)
  5936. player.pos[0] = rt[ran][0]
  5937. player.pos[1] = rt[ran][1]
  5938. screen.reset_hit_matrix()
  5939. message.add('You are teleported randomly.')
  5940. sfx.play('teleport')
  5941. player.stand_check()
  5942. screen.render_fade(False,True)
  5943. else:
  5944. message.add('Nothing seems to happen.')
  5945. sfx.play('throw')
  5946. elif kind == 2:#blinding trap
  5947. ran = random.randint(10,30)
  5948. player.buffs.set_buff('blind',ran)
  5949. message.add('A garish flash blinds you.')
  5950. elif kind == 3:#magic trap
  5951. player.mp = 0
  5952. screen.write_hit_matrix(player.pos[0],player.pos[1],7)
  5953. message.add('You loose your focus.')
  5954. replace = world.maplist[self.pos[2]][self.on_map].tilemap[position[1]][position[0]].replace
  5955. world.maplist[self.pos[2]][self.on_map].tilemap[position[1]][position[0]] = deepcopy(tl.tlist['dungeon'][11])
  5956. world.maplist[self.pos[2]][self.on_map].tilemap[position[1]][position[0]].replace = replace
  5957. if player.lp <= 0:
  5958. screen.render_dead()
  5959. self.lp = int(self.lp)
  5960. bgm.check_for_song()
  5961. if time.hour%2 == 0 and time.minute == 0:
  5962. help_player = deepcopy(player)
  5963. help_player.on_map = 'local_0_0'
  5964. help_player.pos[0] = max_map_size/2
  5965. help_player.pos[1] = max_map_size/2
  5966. help_player.pos[2] = 0
  5967. save(None,help_player,time,gods,save_path,os.sep)
  5968. def enter(self):
  5969. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'stair_down':
  5970. if world.maplist[self.pos[2]+1][self.on_map].tilemap[self.pos[1]][self.pos[0]].techID == tl.tlist['functional'][2].techID: #if there is a stair up below this
  5971. screen.render_fade(True,False)
  5972. player.pos[2] += 1
  5973. player.stand_check()#to unveil the surroundings
  5974. screen.render_fade(False,True)
  5975. else:
  5976. message.add('This stair seem to be blocked.')
  5977. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'stair_up': #this is a stair up
  5978. if world.maplist[self.pos[2]-1][self.on_map].tilemap[self.pos[1]][self.pos[0]].techID == tl.tlist['functional'][1].techID: #if there is a stair down above
  5979. screen.render_fade(True,False)
  5980. player.pos[2] -= 1
  5981. player.stand_check()#to unveil the surroundings
  5982. screen.render_fade(False,True)
  5983. else:
  5984. message.add('This stair seem to be blocked.')
  5985. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'drink':#this is a low wather or a fontain
  5986. #drink water
  5987. if player.attribute.thirst < player.attribute.thirst_max:
  5988. sfx.play('no_fish')
  5989. message.add('You take a sip of water.')
  5990. player.attribute.thirst += 240 #this is 1/3 of the water te player needs per day
  5991. if player.attribute.thirst > player.attribute.thirst_max:
  5992. player.attribute.thirst = player.attribute.thirst_max+1#the +1 is because the player will lose one point at the same round so you would get just 99%
  5993. else:
  5994. message.add('You are not thirsty right now.')
  5995. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'drink_acid':#this is a acid fontain
  5996. #drink acid water
  5997. if player.attribute.thirst < player.attribute.thirst_max:
  5998. message.add('You take a sip of water.')
  5999. player.lp -= 5
  6000. message.add('It hurts like acid.')
  6001. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].tile_pos = (12,11,12,12)
  6002. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group = 'dont_drink'
  6003. else:
  6004. message.add('You are not thirsty right now.')
  6005. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'dont_drink':
  6006. message.add('You shouldn\'t drink this water!')
  6007. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'drink_heal':#this is a healing fontain
  6008. #drink healing water
  6009. if player.attribute.thirst < player.attribute.thirst_max:
  6010. message.add('You take a sip of water.')
  6011. if player.lp < player.attribute.max_lp:
  6012. player.lp += 5
  6013. if player.lp > player.attribute.max_lp:
  6014. player.lp = player.attribute.max_lp
  6015. message.add('Your wounds are cured.')
  6016. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6017. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = deepcopy(tl.tlist['functional'][7])
  6018. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].civilisation = False
  6019. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].build_here = False
  6020. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].can_grown = False
  6021. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace = replace
  6022. else:
  6023. message.add('You are not thirsty right now.')
  6024. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'resource':
  6025. res = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_resources[0]
  6026. num = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_resources[1]
  6027. try:
  6028. conected_tile = (world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_tiles[0],world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_tiles[1])
  6029. except:
  6030. None
  6031. test = player.inventory.materials.add(res,num)
  6032. if test != 'Full!':
  6033. sfx.play('pickup')
  6034. message.add(test)
  6035. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6036. try:
  6037. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = deepcopy(tl.tlist[conected_tile[0]][conected_tile[1]])
  6038. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace = replace
  6039. except:
  6040. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = replace
  6041. else:
  6042. message.add(test)
  6043. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'sleep':#this is a bed
  6044. #sleep a bit
  6045. sleep = True
  6046. lp = player.lp
  6047. while sleep:
  6048. screen.render_load(12)
  6049. time.tick()
  6050. player.attribute.tiredness += 5
  6051. if player.buffs.adrenalised_max > 0:
  6052. player.buffs.adrenalised_max -= 5
  6053. if player.buffs.adrenalised_max < 0:
  6054. player.buffs.adrenalised_max = 0
  6055. if player.lp < lp:
  6056. message.add('You were hurt!')
  6057. sleep = False
  6058. if player.attribute.tiredness >= player.attribute.tiredness_max:#wake up because you've slept enough
  6059. player.attribute.tiredness = player.attribute.tiredness_max +1 #the +1 is because the player will lose one point at the same round so you would get just 99%
  6060. message.add('You feel refreshed.')
  6061. sleep = False
  6062. if int((player.attribute.hunger_max*100)/max(player.attribute.hunger,1)) < 11:
  6063. message.add('You feel hungry.')
  6064. sleep = False
  6065. if int((player.attribute.thirst_max*100)/max(player.attribute.thirst,1)) < 11:
  6066. message.add('You feel thirsty.')
  6067. sleep = False
  6068. monster_test = False
  6069. for y in range (player.pos[1]-1, player.pos[1]+2):#check for a monster
  6070. for x in range (player.pos[0]-1, player.pos[0]+2):
  6071. try:
  6072. if world.maplist[self.pos[2]][self.on_map].npcs[self.pos[1]][self.pos[0]] != 0:#<-------change this so that friendly npcs are ignored
  6073. monster_test = True
  6074. except:
  6075. None
  6076. if monster_test == True:#wake up because a monster borders the players sleep
  6077. message.add('You wake up with a sense of danger.')
  6078. sleep = False
  6079. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'gather':
  6080. help_container = container([world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_items])
  6081. item_name = help_container.items[0].name
  6082. test_loot = help_container.loot(0)
  6083. if test_loot == True:
  6084. sfx.play('pickup')
  6085. string = '+[' + item_name + ']'
  6086. message.add(string)
  6087. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6088. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = 0
  6089. else:
  6090. message.add('Your inventory is full!')
  6091. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'gather_scrub':
  6092. help_container = container([world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_items])
  6093. item_name = help_container.items[0].name
  6094. test_loot = help_container.loot(0)
  6095. if test_loot == True:
  6096. sfx.play('pickup')
  6097. string = '+[' + item_name + ']'
  6098. message.add(string)
  6099. cat = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_tiles[2][0]
  6100. num = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_tiles[2][1]
  6101. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6102. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = tl.tlist[cat][num]
  6103. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace = replace
  6104. else:
  6105. message.add('Your inventory is full!')
  6106. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'carpenter':
  6107. #this is a carpenter's workbench
  6108. run = True
  6109. while run:
  6110. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6111. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6112. screen.render_request('['+key_name['e']+'] - produce something (-10 Wood)', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6113. else:
  6114. screen.render_request('['+key_name['e']+'] - XXXXXXXXXXXX ', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6115. else:
  6116. screen.render_request('['+key_name['e']+'] - produce something (-10 Wood)', '['+key_name['b']+'] - pick up workbench', '['+key_name['x']+'] - leave')
  6117. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6118. if ui == 'exit':
  6119. exitgame = True
  6120. screen.render_load(5)
  6121. save(world,player,time,gods,save_path,os.sep)
  6122. screen.save_tmp_png()
  6123. master_loop = False
  6124. playing = False
  6125. run = False
  6126. return('exit')
  6127. if ui == 'e':
  6128. test = False
  6129. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6130. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6131. test = True
  6132. else:
  6133. test = True
  6134. if test == True:
  6135. if player.inventory.materials.wood >= 10:
  6136. gc = screen.get_choice('What do you want to produce?', ('Carpenter\'s Workbench', 'Carver\'s Workbench', 'Stonecuter\'s Workbench', 'Forger\'s Workbench', 'Alchemist\'s Workshop', 'Furniture'),True)
  6137. if gc == 'Break':
  6138. run = False
  6139. elif gc < 5:# give the chosen workbench to the player
  6140. items = (il.ilist['misc'][3],il.ilist['misc'][4],il.ilist['misc'][5],il.ilist['misc'][6],il.ilist['misc'][7])
  6141. choose = gc
  6142. elif gc == 5:
  6143. items = (il.ilist['misc'][1], il.ilist['misc'][2],il.ilist['misc'][10],il.ilist['misc'][11],il.ilist['misc'][68],il.ilist['misc'][13])
  6144. #chest, bed, table, w. seat, bookshelf
  6145. gc2 = screen.get_choice('What do you want to produce exactly?', ('Chest', 'Bed', 'Table', 'Seat', 'Throne', 'Bookshelf'),True)
  6146. choose = gc2
  6147. try:
  6148. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] == 0:
  6149. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = container([items[choose]],False)
  6150. else:
  6151. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items.append(items[choose])
  6152. sfx.play('craft')
  6153. message_string = 'You produced a ' + items[choose].name + '.'
  6154. message.add(message_string)
  6155. player.inventory.materials.wood -= 10
  6156. except:
  6157. None
  6158. run = False
  6159. else:
  6160. message.add('You do not have enough wood!')
  6161. run = False
  6162. elif ui == 'b':
  6163. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6164. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].inventory(False)
  6165. run = False
  6166. else:
  6167. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace.techID != tl.tlist['sanctuary'][0].techID:
  6168. #this wb dosen't stand inside the sanctuary
  6169. helpc = container([il.ilist['misc'][3]],True)
  6170. item_name = helpc.items[0].name
  6171. test_loot = helpc.loot(0)
  6172. run = False
  6173. if test_loot == True:
  6174. sfx.play('pickup')
  6175. string = '+[' + item_name + ']'
  6176. message.add(string)
  6177. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6178. else:
  6179. message.add('This workbench seems to be attached to the floor.')
  6180. run = False
  6181. elif ui == 'x':
  6182. run = False
  6183. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'carver':
  6184. #this is a carvers's workbench
  6185. run = True
  6186. while run:
  6187. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6188. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6189. screen.render_request('['+key_name['e']+'] - produce something (-5 Wood)', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6190. else:
  6191. screen.render_request('['+key_name['e']+'] - XXXXXXXXXXXX ', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6192. else:
  6193. screen.render_request('['+key_name['e']+'] - produce something (-5 Wood)', '['+key_name['b']+'] - pick up workbench', '['+key_name['x']+'] - leave')
  6194. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6195. if ui == 'exit':
  6196. exitgame = True
  6197. screen.render_load(5)
  6198. save(world,player,time,gods,save_path,os.sep)
  6199. screen.save_tmp_png()
  6200. master_loop = False
  6201. playing = False
  6202. run = False
  6203. return('exit')
  6204. if ui == 'e':
  6205. test = False
  6206. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6207. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6208. test = True
  6209. else:
  6210. test = True
  6211. if test == True:
  6212. if player.inventory.materials.wood >= 5:
  6213. final_choice = 'Foo'
  6214. gc = screen.get_choice('What do you want to prodcuce?', ('Tool', 'Weapon', 'Armor','Jewelry'), True)
  6215. if gc == 0: #make a tool
  6216. items = (il.ilist['misc'][44], item_wear('axe',0,0), item_wear('pickaxe',0,0),il.ilist['misc'][14])
  6217. final_choice = screen.get_choice('What do you want to prodcuce exactly?', ('Torch','Axe','Pickaxe','Fishing rod'),True)
  6218. elif gc == 1: #make a weapon
  6219. items = (item_wear('spear',0,0), item_wear('sword',0,0), item_wear('hammer',0,0), item_wear('rune',0,0), item_wear('wand',0,0), item_wear('rune staff',0,0), item_wear('artefact',0,0))
  6220. class_choice = screen.get_choice('What do you want to prodcuce exactly?', ('Melee Weapon','Magic Weapon'), True)
  6221. if class_choice == 0:
  6222. ran = random.randint(0,99)
  6223. if player.skill.weapon_crafting == 'Novice':
  6224. if ran < 90:
  6225. final_choice = 0
  6226. else:
  6227. finnal_choice = 1
  6228. elif player.skill.weapon_crafting == 'Adept':
  6229. if ran < 10:
  6230. final_choice = 0
  6231. elif ran < 90:
  6232. final_choice = 1
  6233. else:
  6234. final_choice = 2
  6235. elif player.skill.weapon_crafting == 'Master':
  6236. if ran < 5:
  6237. final_choice = 0
  6238. elif ran < 15:
  6239. final_choice = 1
  6240. else:
  6241. final_choice = 2
  6242. else:
  6243. ran = random.randint(0,99)
  6244. if player.skill.weapon_crafting == 'Novice':
  6245. if ran < 90:
  6246. final_choice = 3
  6247. else:
  6248. finnal_choice = 4
  6249. elif player.skill.weapon_crafting == 'Adept':
  6250. if ran < 10:
  6251. final_choice = 3
  6252. elif ran < 90:
  6253. final_choice = 4
  6254. else:
  6255. final_choice = 5
  6256. elif player.skill.weapon_crafting == 'Master':
  6257. if ran < 5:
  6258. final_choice = 3
  6259. elif ran < 15:
  6260. final_choice = 4
  6261. else:
  6262. final_choice = 5
  6263. elif gc == 2: #make some armor
  6264. items = (item_wear('shoes',0,0), item_wear('cuisse',0,0), item_wear('helmet',0,0), item_wear('armor',0,0))
  6265. final_choice = screen.get_choice('What do you want to prodcuce exactly?', ('Shoes','Cuisse','Helmet','Armor'), True)
  6266. elif gc == 3:#make some jewlry
  6267. items = (item_wear('ring',0,0), item_wear('amulet',0,0), item_wear('necklace',0,0), item_wear('talisman',0,0))
  6268. final_choice = screen.get_choice('What do you want to prodcuce exactly?', ('Ring','Amulet','Necklace','Talisman'), True)
  6269. choose = final_choice
  6270. try:
  6271. if choose != 'Foo':
  6272. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] == 0:
  6273. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = container([items[choose]],False)
  6274. else:
  6275. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items.append(items[choose])
  6276. sfx.play('craft')
  6277. message_string = 'You produced a ' + items[choose].name + '.'
  6278. message.add(message_string)
  6279. if choose != 'Foo':
  6280. player.inventory.materials.wood -= 5
  6281. except:
  6282. None
  6283. run = False
  6284. else:
  6285. message.add('You do not have enough wood!')
  6286. run = False
  6287. elif ui == 'b':
  6288. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6289. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].inventory(False)
  6290. run = False
  6291. else:
  6292. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace.techID != tl.tlist['sanctuary'][0].techID:
  6293. #this wb dosen't stand inside the sanctuary
  6294. helpc = container([il.ilist['misc'][4]],True)
  6295. item_name = helpc.items[0].name
  6296. test_loot = helpc.loot(0)
  6297. run = False
  6298. if test_loot == True:
  6299. sfx.play('pickup')
  6300. string = '+[' + item_name + ']'
  6301. message.add(string)
  6302. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6303. else:
  6304. message.add('This workbench seems to be attached to the floor.')
  6305. run = False
  6306. elif ui == 'x':
  6307. run = False
  6308. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'stonecutter':
  6309. #this is a stonecutter's workbench
  6310. run = True
  6311. while run:
  6312. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6313. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6314. screen.render_request('['+key_name['e']+'] - produce something (-10 Stone)', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6315. else:
  6316. screen.render_request('['+key_name['e']+'] - XXXXXXXXXXXX ', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6317. else:
  6318. screen.render_request('['+key_name['e']+'] - produce something (-10 Stone)', '['+key_name['b']+'] - pick up workbench', '['+key_name['x']+'] - leave')
  6319. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6320. if ui == 'exit':
  6321. exitgame = True
  6322. screen.render_load(5)
  6323. save(world,player,time,gods,save_path,os.sep)
  6324. screen.save_tmp_png()
  6325. master_loop = False
  6326. playing = False
  6327. run = False
  6328. return('exit')
  6329. if ui == 'e':
  6330. test = False
  6331. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6332. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6333. test = True
  6334. else:
  6335. test = True
  6336. if test == True:
  6337. if player.inventory.materials.stone >= 10:
  6338. gc = screen.get_choice('What do you want to produce?' ,('Functional Things', 'Decorative Things'), True)
  6339. if gc == 0: #make something functional
  6340. items = (il.ilist['misc'][0], il.ilist['misc'][8], il.ilist['misc'][9])
  6341. #items: fontain, furnace, altar
  6342. gc2 = screen.get_choice('What do you want to produce exactly?' ,('Fountain','Furnace','Altar'), True)
  6343. else:#make something decorative
  6344. items = (il.ilist['misc'][12],il.ilist['misc'][21],il.ilist['misc'][69])
  6345. #items: stone seat, pilar, throne
  6346. gc2 = screen.get_choice('What do you want to produce?' ,('Seat','Pilar','Throne'), True)
  6347. choose = gc2
  6348. try:
  6349. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] == 0:
  6350. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = container([items[choose]],False)
  6351. else:
  6352. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items.append(items[choose])
  6353. sfx.play('craft')
  6354. message_string = 'You produced a ' + items[choose].name + '.'
  6355. message.add(message_string)
  6356. player.inventory.materials.stone -= 10
  6357. except:
  6358. None
  6359. run = False
  6360. else:
  6361. message.add('You do not have enough Stone!')
  6362. run = False
  6363. elif ui == 'b':
  6364. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6365. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].inventory(False)
  6366. run = False
  6367. else:
  6368. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace.techID != tl.tlist['sanctuary'][0].techID:
  6369. #this wb dosen't stand inside the sanctuary
  6370. helpc = container([il.ilist['misc'][5]],True)
  6371. item_name = helpc.items[0].name
  6372. test_loot = helpc.loot(0)
  6373. run = False
  6374. if test_loot == True:
  6375. sfx.play('pickup')
  6376. string = '+[' + item_name + ']'
  6377. message.add(string)
  6378. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6379. else:
  6380. message.add('This workbench seems to be attached to the floor.')
  6381. run = False
  6382. elif ui == 'x':
  6383. run = False
  6384. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'forger' or world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'masterforge':
  6385. #this is a forger's workbench or a master forge
  6386. run = True
  6387. while run:
  6388. price = 5
  6389. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].techID == tl.tlist['functional'][23].techID: #this is a master forge
  6390. price = 15
  6391. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6392. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6393. string = ('['+key_name['e']+'] - produce something (-' + str(price) + ' Ore)', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6394. screen.render_request(string[0],string[1],string[2])
  6395. else:
  6396. screen.render_request('['+key_name['e']+'] - XXXXXXXXXXXX ', '['+key_name['b']+'] - take a produced item', '['+key_name['x']+'] - leave')
  6397. else:
  6398. string = '['+key_name['e']+'] - produce something (-' + str(price) + ' Ore)', '['+key_name['b']+'] - pick up workbench', '['+key_name['x']+'] - leave'
  6399. screen.render_request(string[0],string[1],string[2])
  6400. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6401. if ui == 'exit':
  6402. exitgame = True
  6403. screen.render_load(5)
  6404. save(world,player,time,gods,save_path,os.sep)
  6405. screen.save_tmp_png()
  6406. master_loop = False
  6407. playing = False
  6408. run = False
  6409. return('exit')
  6410. if ui == 'e':
  6411. test = False
  6412. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6413. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6414. test = True
  6415. else:
  6416. test = True
  6417. if test == True:
  6418. if player.inventory.materials.ore >= price:
  6419. if player.skill.metallurgy == 'Novice':
  6420. material = random.randint(6,11)#tin to bronze
  6421. elif player.skill.metallurgy == 'Adept':
  6422. material = random.randint(11,18)#bronze to titan
  6423. elif player.skill.metallurgy == 'Master':
  6424. material = random.randint(18,20)#titan to magnicum
  6425. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].techID == tl.tlist['functional'][23].techID: #this is a master forge
  6426. material = 20 #magnicum only
  6427. final_choice = 'Foo'
  6428. gc = screen.get_choice('What do you want to procuce?', ('Tool', 'Weapon', 'Armor','Jewelry'), True)
  6429. if gc == 0: #make a tool
  6430. final_choice = screen.get_choice('What do you want to procuce exactly?', ('Axe', 'Pickaxe'), True)
  6431. items = (item_wear('axe',material,0), item_wear('pickaxe',material,0))
  6432. elif gc == 1: #make a weapon
  6433. items = (item_wear('spear',material,0), item_wear('sword',material,0), item_wear('hammer',material,0), item_wear('wand',material,0), item_wear('rune',material,0), item_wear('rune staff',material,0), item_wear('artefact',material,0))
  6434. class_choice = screen.get_choice('What do you want to prodcuce?', ('Melee Weapon','Magic Weapon'), True)
  6435. if class_choice == 0:
  6436. ran = random.randint(0,99)
  6437. if player.skill.weapon_crafting == 'Novice':
  6438. if ran < 90:
  6439. final_choice = 0
  6440. else:
  6441. finnal_choice = 1
  6442. elif player.skill.weapon_crafting == 'Adept':
  6443. if ran < 10:
  6444. final_choice = 0
  6445. elif ran < 90:
  6446. final_choice = 1
  6447. else:
  6448. final_choice = 2
  6449. elif player.skill.weapon_crafting == 'Master':
  6450. if ran < 5:
  6451. final_choice = 0
  6452. elif ran < 15:
  6453. final_choice = 1
  6454. else:
  6455. final_choice = 2
  6456. else:
  6457. ran = random.randint(0,99)
  6458. if player.skill.weapon_crafting == 'Novice':
  6459. if ran < 90:
  6460. final_choice = 3
  6461. else:
  6462. finnal_choice = 4
  6463. elif player.skill.weapon_crafting == 'Adept':
  6464. if ran < 10:
  6465. final_choice = 3
  6466. elif ran < 90:
  6467. final_choice = 4
  6468. else:
  6469. final_choice = 5
  6470. elif player.skill.weapon_crafting == 'Master':
  6471. if ran < 5:
  6472. final_choice = 3
  6473. elif ran < 15:
  6474. final_choice = 4
  6475. else:
  6476. final_choice = 5
  6477. elif gc == 2: #make some armor
  6478. final_choice = screen.get_choice('What do you want to procuce exactly?', ('Shoes', 'Cuisse', 'Helmet', 'Armor'), True)
  6479. items = (item_wear('shoes',material,0), item_wear('cuisse',material,0), item_wear('helmet',material,0), item_wear('armor',material,0))
  6480. elif gc == 3:#make some jewelry
  6481. items = (item_wear('ring',material,0), item_wear('amulet',material,0), item_wear('necklace',material,0), item_wear('talisman',material,0))
  6482. final_choice = screen.get_choice('What do you want to prodcuce?', ('Ring','Amulet','Necklace','Talisman'), True)
  6483. choose = final_choice
  6484. try:
  6485. if choose != 'Foo':
  6486. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] == 0:
  6487. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = container([items[choose]],False)
  6488. else:
  6489. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items.append(items[choose])
  6490. sfx.play('craft')
  6491. message_string = 'You produced a ' + items[choose].name + '.'
  6492. message.add(message_string)
  6493. if choose != 'Foo':
  6494. player.inventory.materials.ore -= price
  6495. except:
  6496. None
  6497. run = False
  6498. else:
  6499. message.add('You do not have enough ore!')
  6500. run = False
  6501. elif ui == 'b':
  6502. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6503. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].inventory(False)
  6504. run = False
  6505. else:
  6506. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace.techID != tl.tlist['sanctuary'][0].techID:
  6507. #this wb dosen't stand inside the sanctuary
  6508. helpc = container([il.ilist['misc'][6]],True)
  6509. item_name = helpc.items[0].name
  6510. test_loot = helpc.loot(0)
  6511. run = False
  6512. if test_loot == True:
  6513. sfx.play('pickup')
  6514. string = '+[' + item_name + ']'
  6515. message.add(string)
  6516. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6517. else:
  6518. message.add('This workbench seems to be attached to the floor.')
  6519. run = False
  6520. elif ui == 'x':
  6521. run = False
  6522. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'alchemist':
  6523. #this is a alchemists's workshop
  6524. run = True
  6525. while run:
  6526. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6527. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6528. screen.render_request('['+key_name['e']+'] - brew a potion (-5 Herbs)', '['+key_name['b']+'] - take a potion', '['+key_name['x']+'] - leave')
  6529. else:
  6530. screen.render_request('['+key_name['e']+'] - XXXXXXXXXXXX ', '['+key_name['b']+'] - take a potion', '['+key_name['x']+'] - leave')
  6531. else:
  6532. screen.render_request('['+key_name['e']+'] - brew a potion (-5 Herbs)', '['+key_name['b']+'] - pick up workshop', '['+key_name['x']+'] - leave')
  6533. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6534. if ui == 'exit':
  6535. exitgame = True
  6536. screen.render_load(5)
  6537. save(world,player,time,gods,save_path,os.sep)
  6538. screen.save_tmp_png()
  6539. master_loop = False
  6540. playing = False
  6541. run = False
  6542. return('exit')
  6543. if ui == 'e':
  6544. test = False
  6545. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6546. if len(world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items) < 7:
  6547. test = True
  6548. else:
  6549. test = True
  6550. if test == True:
  6551. if player.inventory.materials.herb >= 5:
  6552. ordenary_potions = (il.ilist['food'][13],il.ilist['food'][14],il.ilist['food'][15],il.ilist['food'][16],il.ilist['food'][32])
  6553. #ordenary potions are: p.o. healing, p.o. feeding, p.o. refreshing, p.o. vitalising
  6554. strong_potions = (il.ilist['food'][17],il.ilist['food'][18],il.ilist['food'][19],il.ilist['food'][20],il.ilist['food'][33],il.ilist['food'][34])
  6555. #strong potions are: s.p.o. healing, s.p.o. feeding, s.p.o. refreshing, s.p.o. vitalising
  6556. upgrade_potions = (il.ilist['food'][21],il.ilist['food'][22],il.ilist['food'][23],il.ilist['food'][24],il.ilist['food'][35])
  6557. #upgrade potions are: p.o. hunger, p.o. thirst, p.o. tiredness, p.o. life
  6558. choose = random.randint(0,99)
  6559. if player.skill.alchemy == 'Novice':
  6560. if choose < 85: #make a ordenary potion(85%)
  6561. items = ordenary_potions
  6562. elif choose < 95:#make a strong potion(10%)
  6563. items = strong_potions
  6564. else:#make a upgrade potion(5%)
  6565. items = upgrade_potions
  6566. elif player.skill.alchemy == 'Adept':
  6567. if choose < 70: #make a ordenary potion(70%)
  6568. items = ordenary_potions
  6569. elif choose < 90:#make a strong potion(20%)
  6570. items = strong_potions
  6571. else:#make a upgrade potion(10%)
  6572. items = upgrade_potions
  6573. elif player.skill.alchemy == 'Master':
  6574. if choose < 50: #make a ordenary potion(50%)
  6575. items = ordenary_potions
  6576. elif choose < 80:#make a strong potion(30%)
  6577. items = strong_potions
  6578. else:#make a upgrade potion(20%)
  6579. items = upgrade_potions
  6580. choose = random.randint(0, len(items)-1)
  6581. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] == 0:
  6582. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = container([items[choose]],False)
  6583. else:
  6584. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].items.append(items[choose])
  6585. sfx.play('alchemy')
  6586. message_string = 'You brewed a ' + items[choose].name + '.'
  6587. message.add(message_string)
  6588. player.inventory.materials.herb -= 5
  6589. run = False
  6590. else:
  6591. message.add('You do have not enough herbs!')
  6592. run = False
  6593. elif ui == 'b':
  6594. if world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:
  6595. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].inventory(False)
  6596. run = False
  6597. else:
  6598. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace.techID != tl.tlist['sanctuary'][0].techID:
  6599. #this ws dosen't stand inside the sanctuary
  6600. helpc = container([il.ilist['misc'][7]],True)
  6601. item_name = helpc.items[0].name
  6602. test_loot = helpc.loot(0)
  6603. run = False
  6604. if test_loot == True:
  6605. sfx.play('pickup')
  6606. string = '+[' + item_name + ']'
  6607. message.add(string)
  6608. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6609. else:
  6610. message.add('This workshop seems to be attached to the floor.')
  6611. run = False
  6612. elif ui == 'x':
  6613. run = False
  6614. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'furnace':
  6615. #this is a furnace
  6616. run = True
  6617. while run:
  6618. screen.render_request('['+key_name['e']+'] - fire up the furnace (-10 wood)', ' ', '['+key_name['x']+'] - leave')
  6619. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6620. if ui == 'exit':
  6621. exitgame = True
  6622. screen.render_load(5)
  6623. save(world,player,time,gods,save_path,os.sep)
  6624. screen.save_tmp_png()
  6625. master_loop = False
  6626. playing = False
  6627. run = False
  6628. return('exit')
  6629. if ui == 'e':
  6630. if player.inventory.materials. wood >= 10:
  6631. sfx.play('flame')
  6632. message.add('You ligth up a fire.')
  6633. for i in range (0,len(player.inventory.food)):
  6634. if player.inventory.food[i] != player.inventory.nothing and player.inventory.food[i].rotten == False:
  6635. if player.inventory.food[i].techID == il.ilist['food'][4].techID: #this is a fish
  6636. message.add('You grill a fish.')
  6637. player.inventory.food[i] = deepcopy(il.ilist['food'][5])#turn a fish into a grilled fish
  6638. elif player.inventory.food[i].techID == il.ilist['food'][6].techID: #this are crops
  6639. message.add('You bake a bread.')
  6640. player.inventory.food[i] = deepcopy(il.ilist['food'][7])#turn crops into bread
  6641. elif player.inventory.food[i].techID == il.ilist['food'][7].techID: #this is a bread
  6642. message.add('You bake a bread for a second time.')
  6643. player.inventory.food[i] = deepcopy(il.ilist['food'][8])#turn a bread into rusk
  6644. elif player.inventory.food[i].techID == il.ilist['food'][9].techID: #this is raw meat
  6645. message.add('You grill raw meat.')
  6646. player.inventory.food[i] = deepcopy(il.ilist['food'][10])#turn raw meat into a grilled meat
  6647. elif player.inventory.food[i].techID == il.ilist['food'][11].techID: #this is a cult. mushroom
  6648. message.add('You grill a mushroom.')
  6649. player.inventory.food[i] = deepcopy(il.ilist['food'][12])#turn a cult. mushroom into a grilled mushroom
  6650. elif player.inventory.food[i].techID == il.ilist['food'][25].techID: #this is a jellyfish
  6651. message.add('You grill a jellyfish.')
  6652. player.inventory.food[i] = deepcopy(il.ilist['food'][26])#turn a jellyfish into a grilled jellyfish
  6653. elif player.inventory.food[i].techID == il.ilist['food'][0].techID: #this are red berries
  6654. message.add('You make some red jelly.')
  6655. player.inventory.food[i] = deepcopy(il.ilist['food'][29])#turn red berries into red jelly
  6656. elif player.inventory.food[i].techID == il.ilist['food'][27].techID: #this are blue berries
  6657. message.add('You make some blue jelly.')
  6658. player.inventory.food[i] = deepcopy(il.ilist['food'][30])#turn blue berries into blue jelly
  6659. elif player.inventory.food[i].techID == il.ilist['food'][28].techID: #this are red berries
  6660. message.add('You make some yellow jelly.')
  6661. player.inventory.food[i] = deepcopy(il.ilist['food'][31])#turn yellow berries into yellow jelly
  6662. elif player.inventory.food[i].techID == il.ilist['food'][38].techID: #this is corn
  6663. message.add('You make some popcorn.')
  6664. player.inventory.food[i] = deepcopy(il.ilist['food'][39])#turn corn into popcorn
  6665. elif player.inventory.food[i].techID == il.ilist['food'][40].techID: #this is an apple
  6666. message.add('You grill an apple.')
  6667. player.inventory.food[i] = deepcopy(il.ilist['food'][41])#turn apple into grilled apple
  6668. elif player.inventory.food[i].techID == il.ilist['food'][42].techID: #this is a golden apple
  6669. message.add('You grill a golden apple.')
  6670. player.inventory.food[i] = deepcopy(il.ilist['food'][43])#turn apple into grilled golden apple
  6671. ####add more here
  6672. run = False
  6673. else:
  6674. message.add('You do not have enough wood!')
  6675. run = False
  6676. elif ui == 'x':
  6677. run = False
  6678. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'altar':
  6679. #this is a altar
  6680. run = True
  6681. while run:
  6682. if player.difficulty == 0 or player.difficulty == 4: #playing on easy or sandbox
  6683. if gods.judgement() == True:
  6684. pray_string = '['+key_name['e']+'] - pray (save)'
  6685. else:
  6686. pray_string = '['+key_name['e']+'] - pray (not save)'
  6687. else:
  6688. pray_string = '['+key_name['e']+'] - pray'
  6689. screen.render_request(pray_string, '['+key_name['b']+'] - identify ', '['+key_name['x']+'] - leave')
  6690. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6691. if ui == 'exit':
  6692. exitgame = True
  6693. screen.render_load(5)
  6694. save(world,player,time,gods,save_path,os.sep)
  6695. screen.save_tmp_png()
  6696. master_loop = False
  6697. playing = False
  6698. run = False
  6699. return('exit')
  6700. if ui == 'e':
  6701. judgement = gods.judgement() # see if the player is supported by the gods
  6702. if judgement == True:
  6703. cursed_items = 0
  6704. bodyparts = ('Hold(R)', 'Hold(L)', 'Head', 'Body', 'Legs', 'Feet', 'Hand', 'Neck', 'Axe', 'Pickaxe')
  6705. for i in bodyparts:#check if player wears some cursed equipment
  6706. if player.inventory.wearing[i].cursed < 1 and i != player.inventory.nothing:
  6707. cursed_items += 1
  6708. if (player.lp*100)/player.attribute.max_lp < 20:#player has less then 20% of lp -> heal
  6709. player.lp = player.attribute.max_lp
  6710. message.add('The gods heal your wounds.')
  6711. gods.mood -= 10
  6712. run = False
  6713. elif (player.attribute.hunger*100)/player.attribute.hunger_max < 20 or (player.attribute.thirst*100)/player.attribute.thirst_max < 20 or (player.attribute.tiredness*100)/player.attribute.tiredness_max < 20:
  6714. #player is very hungry,thirsty or tired -> refresh
  6715. player.attribute.hunger = player.attribute.hunger_max
  6716. player.attribute.thirst = player.attribute.thirst_max
  6717. player.attribute.tiredness = player.attribute.tiredness_max
  6718. message.add('The gods rerfresh you.')
  6719. gods.mood -= 10
  6720. run = False
  6721. elif cursed_items > 0:#player has some cursed items
  6722. bodyparts = ('Hold(R)', 'Hold(L)', 'Head', 'Body', 'Legs', 'Feet', 'Hand', 'Neck', 'Axe', 'Pickaxe')
  6723. for j in bodyparts:
  6724. if player.inventory.wearing[j].cursed < 1 and player.inventory.wearing[j] != player.inventory.nothing:
  6725. item = item_wear(player.inventory.wearing[j].classe, player.inventory.wearing[j].material, player.inventory.wearing[j].plus, player.inventory.wearing[j].state, 1, player.inventory.wearing[j].known)
  6726. player.inventory.wearing[j] = item
  6727. message.add('The gods remove curses from your equipment.')
  6728. gods.mood -= 10
  6729. run = False
  6730. else:
  6731. message.add('The gods are pleased about you.')
  6732. run = False
  6733. else:
  6734. uncursed_items = 0
  6735. bodyparts = ('Hold(R)', 'Hold(L)', 'Head', 'Body', 'Legs', 'Feet', 'Hand', 'Neck','Axe','Pickaxe')
  6736. for i in bodyparts:#check if player wears some cursed equipment
  6737. if player.inventory.wearing[i].cursed > 0 and player.inventory.wearing[i] != player.inventory.nothing:
  6738. uncursed_items += 1
  6739. if uncursed_items > 0:
  6740. for j in bodyparts:
  6741. if player.inventory.wearing[j].cursed > 0 and player.inventory.wearing[j] != player.inventory.nothing:
  6742. item = item_wear(player.inventory.wearing[j].classe,player.inventory.wearing[j].material,player.inventory.wearing[j].plus, player.inventory.wearing[j].state, 0, player.inventory.wearing[j].known)
  6743. player.inventory.wearing[j] = item
  6744. message.add('The gods are angry and curse your equipment.')
  6745. run = False
  6746. else:
  6747. player.lp -= 5
  6748. message.add('The gods are angry and hurt you')
  6749. run = False
  6750. elif ui == 'b':
  6751. if gods.judgement() == True:
  6752. num_ident = 0
  6753. bodyparts = ('Hold(R)', 'Hold(L)', 'Head', 'Body', 'Legs', 'Feet', 'Hand', 'Neck', 'Axe', 'Pickaxe')
  6754. for i in bodyparts:
  6755. if player.inventory.wearing[i] != player.inventory.nothing and player.inventory.wearing[i].known == False:
  6756. player.inventory.wearing[i].identification()
  6757. num_ident += 1
  6758. for j in range (0, len(player.inventory.equipment)):
  6759. if player.inventory.equipment[j] != player.inventory.nothing and player.inventory.equipment[j].known == False:
  6760. player.inventory.equipment[j].identification()
  6761. num_ident += 1
  6762. if num_ident > 0:
  6763. message.add('Now you are aware of your equipments attributes.')
  6764. gods.mood -= num_ident
  6765. else:
  6766. message.add('You have nothing that could be identified.')
  6767. run = False
  6768. else:
  6769. message.add('The gods deny to identify your equipment!')
  6770. run = False
  6771. elif ui == 'x':
  6772. run = False
  6773. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'activate_portal':
  6774. head_string = 'Portal (requires: LVL '+str(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].special_num)+' & '+ str(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_resources[1])+' gems)'
  6775. if player.lvl >= world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].special_num and player.inventory.materials.gem >= world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_resources[1]:
  6776. a_string = '['+key_name['e']+'] - activate'
  6777. activate = True
  6778. else:
  6779. a_string = ' '
  6780. activate = False
  6781. l_string = '['+key_name['x']+'] - leave'
  6782. run = True
  6783. while run:
  6784. screen.render_request(head_string,a_string,l_string)
  6785. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  6786. if ui == 'exit':
  6787. exitgame = True
  6788. screen.render_load(5)
  6789. save(world,player,time,gods,save_path,os.sep)
  6790. screen.save_tmp_png()
  6791. master_loop = False
  6792. playing = False
  6793. run = False
  6794. return('exit')
  6795. if ui == 'e' and activate == True:
  6796. player.inventory.materials.gem -= world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_resources[1]
  6797. if player.inventory.materials.gem < 0:#only to be sure
  6798. player.inventory.materials.gem = 0#
  6799. replace = deepcopy(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace)
  6800. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = deepcopy(tl.tlist[world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_tiles[0]][world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_tiles[1]])
  6801. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace = replace
  6802. sfx.play('portal')
  6803. run = False
  6804. if ui == 'x':
  6805. run = False
  6806. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'go_fortress':
  6807. screen.render_fade(True,False)
  6808. try:
  6809. pos = world.maplist[0]['fortress_0_0'].find_first(tl.tlist['portal'][2])
  6810. except:
  6811. test = False
  6812. while test == False:
  6813. test = world.elfish_generator(0)
  6814. pos = world.maplist[0]['fortress_0_0'].find_first(tl.tlist['portal'][2])
  6815. player.pos[0] = pos[0]
  6816. player.pos[1] = pos[1]
  6817. player.pos[2] = 0#only to be sure
  6818. player.on_map = 'fortress_0_0'
  6819. player.stand_check()
  6820. sfx.play('portal')
  6821. screen.render_fade(False,True)
  6822. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'return_fortress':
  6823. pos = world.maplist[self.pos[2]]['local_0_0'].find_first(tl.tlist['portal'][1])
  6824. screen.render_fade(True,False)
  6825. player.pos[0] = pos[0]
  6826. player.pos[1] = pos[1]
  6827. player.pos[2] = 0#only to be sure
  6828. player.on_map = 'local_0_0'
  6829. player.stand_check()
  6830. sfx.play('portal')
  6831. screen.render_fade(False,True)
  6832. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'go_desert':
  6833. screen.render_fade(True,False)
  6834. try:
  6835. pos = world.maplist[self.pos[2]]['desert_0_0'].find_first(tl.tlist['portal'][5])
  6836. except:
  6837. world.desert_generator(20)
  6838. world.cave_generator(5,'desert')
  6839. world.border_generator(6,'desert')
  6840. pos = world.maplist[self.pos[2]]['desert_0_0'].find_first(tl.tlist['portal'][5])
  6841. player.pos[0] = pos[0]
  6842. player.pos[1] = pos[1]
  6843. player.pos[2] = 0#only to be sure
  6844. player.on_map = 'desert_0_0'
  6845. player.stand_check()
  6846. screen.render_fade(False,True)
  6847. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'return_desert':
  6848. pos = world.maplist[self.pos[2]]['local_0_0'].find_first(tl.tlist['portal'][4])
  6849. screen.render_fade(True,False)
  6850. player.pos[0] = pos[0]
  6851. player.pos[1] = pos[1]
  6852. player.pos[2] = 0#only to be sure
  6853. player.on_map = 'local_0_0'
  6854. player.stand_check()
  6855. screen.render_fade(False,True)
  6856. elif world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] != 0:#interaction with a container eg.: a chest
  6857. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].inventory()
  6858. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'shop' or world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].techID == tl.tlist['shop'][0].techID:#this is shop floor
  6859. if world.maplist[self.pos[2]][self.on_map].map_type == 'grot':
  6860. list_items = ('Scroll of Return(1 Gem)','Enchanted Enhancement Powder(5 Gem)','Copper Pickaxe(3 Gem)','Copper Axe(3 Gem)', 'Grilled Fish(1 Gem)', 'Torch(1 Gem)')
  6861. prices = (1,5,3,3,1,1)
  6862. axe = item_wear('axe',11,0)
  6863. pickaxe = item_wear('pickaxe',11,0)
  6864. items = (il.ilist['misc'][33],il.ilist['misc'][42],pickaxe,axe,il.ilist['food'][5],il.ilist['misc'][44])
  6865. elif world.maplist[self.pos[2]][self.on_map].map_type == 'elfish_fortress':
  6866. list_items = ('Scroll of Return(1 Gem)','Mysterious Blue Crystal(10 Gem)','Steel Pickaxe(5 Gem)','Steel Axe(5 Gem)', 'Red Berries(1 Gem)', 'Torch(1 Gem)')
  6867. prices = (1,10,5,5,1,1)
  6868. axe = item_wear('axe',15,0)
  6869. pickaxe = item_wear('pickaxe',15,0)
  6870. items = (il.ilist['misc'][33],il.ilist['misc'][41],pickaxe,axe,il.ilist['food'][0],il.ilist['misc'][44])
  6871. elif world.maplist[self.pos[2]][self.on_map].map_type == 'orcish_mines':
  6872. list_items = ('Scroll of Return(1 Gem)','Bomb(1 Gem)','Titan Pickaxe(7 Gem)','Titan Axe(7 Gem)', 'Grilled Meat(1 Gem)', 'Torch(1 Gem)')
  6873. prices = (1,1,7,7,1,1)
  6874. axe = item_wear('axe',18,0)
  6875. pickaxe = item_wear('pickaxe',18,0)
  6876. items = (il.ilist['misc'][33],il.ilist['misc'][24],pickaxe,axe,il.ilist['food'][10],il.ilist['misc'][44])
  6877. elif world.maplist[self.pos[2]][self.on_map].map_type == 'pharmacy':
  6878. list_items = ('Bandage(1 Gem)','Eyedrops(1 Gem)','Antidote(1 Gem)','Holy Water(3 Gem)', 'Potion of Healing(1 Gem)', 'Strong Potion of Healing(5 Gem)')
  6879. prices = (1,1,1,3,1,5)
  6880. items = (il.ilist['misc'][74],il.ilist['misc'][75],il.ilist['misc'][76],il.ilist['misc'][77],il.ilist['food'][13],il.ilist['food'][17])
  6881. elif world.maplist[self.pos[2]][self.on_map].map_type == 'pickaxe':
  6882. list_items = ('Wooden Pickaxe(1 Gem)','Tin Pickaxe(2 Gem)','Bronze Pickaxe(3 Gem)','Steel Pickaxe(4 Gem)', 'Titan Pickaxe(5 Gem)', 'Magnicum Pickaxe(6 Gem)')
  6883. prices = (1,2,3,4,5,6)
  6884. pickaxe1 = item_wear('pickaxe',0,0)
  6885. pickaxe2 = item_wear('pickaxe',6,0)
  6886. pickaxe3 = item_wear('pickaxe',11,0)
  6887. pickaxe4 = item_wear('pickaxe',15,0)
  6888. pickaxe5 = item_wear('pickaxe',18,0)
  6889. pickaxe6 = item_wear('pickaxe',20,0)
  6890. items = (pickaxe1,pickaxe2,pickaxe3,pickaxe4,pickaxe5,pickaxe6)
  6891. elif world.maplist[self.pos[2]][self.on_map].map_type == 'hardware':
  6892. list_items = ('Steel Helmet(4 Gem)','Steel Armor(4 Gem)','Steel Cuisse(4 Gem)','Steel Shoes(4 Gem)', 'Steel Sword(4 Gem)', 'Steel Rune Staff(4 Gem)')
  6893. prices = (4,4,4,4,4,4)
  6894. item1 = item_wear('helmet',15,0)
  6895. item2 = item_wear('armor',15,0)
  6896. item3 = item_wear('cuisse',15,0)
  6897. item4 = item_wear('shoes',15,0)
  6898. item5 = item_wear('sword',15,0)
  6899. item6 = item_wear('rune staff',15,0)
  6900. items = (item1,item2,item3,item4,item5,item6)
  6901. elif world.maplist[self.pos[2]][self.on_map].map_type == 'deco':
  6902. list_items = ('Bonsai(1 Gem)','Houseplant(1 Gem)','Pendolum Clock(1 Gem)','Hourglass(1 Gem)', 'Neko Statue(1 Gem)', 'Orc Statue(1 Gem)')
  6903. prices = (1,1,1,1,1,1)
  6904. items = (il.ilist['misc'][66],il.ilist['misc'][67],il.ilist['misc'][60],il.ilist['misc'][63],il.ilist['misc'][59],il.ilist['misc'][56])
  6905. elif world.maplist[self.pos[2]][self.on_map].map_type == 'book':
  6906. list_items = ('Spellbook of Light(2 Gem)','Spellbook of Flames(5 Gem)','Scroll of Identify(1 Gem)','Scroll of Repair(2 Gem)', 'Spellbook of Teleport(2 Gem)', 'Spellbook of Healing(5 Gem)')
  6907. prices = (2,5,1,2,2,5)
  6908. items = (il.ilist['misc'][46],il.ilist['misc'][36],il.ilist['misc'][25],il.ilist['misc'][27],il.ilist['misc'][32],il.ilist['misc'][30])
  6909. elif world.maplist[self.pos[2]][self.on_map].map_type == 'bomb':
  6910. list_items = ('boMb(1 Gem)','eXplozive(1 Gem)','BriMstone(1 Gem)','HeAtet stOne(1 Gem)', 'darT(1 Gem)', 'Tork(1 Gem)')
  6911. prices = (1,1,1,1,1,1)
  6912. items = (il.ilist['misc'][24],il.ilist['misc'][72],il.ilist['misc'][73],il.ilist['misc'][71],il.ilist['misc'][79],il.ilist['misc'][44])
  6913. else:#only for fallback and general store
  6914. list_items = ('Scroll of Return(1 Gem)','Magic Map(5 Gem)','Wooden Pickaxe(1 Gem)','Wooden Axe(1 Gem)', 'Grilled Fish(1 Gem)', 'Torch(1 Gem)')
  6915. prices = (1,5,1,1,1,1)
  6916. axe = item_wear('axe',0,0)
  6917. pickaxe = item_wear('pickaxe',0,0)
  6918. items = (il.ilist['misc'][33],il.ilist['misc'][81],pickaxe,axe,il.ilist['food'][5],il.ilist['misc'][44])
  6919. headline = 'You have ' + str(player.inventory.materials.gem) + ' gems. What do you want to buy?'
  6920. choice = screen.get_choice(headline,list_items,True)
  6921. if choice != 'Break':
  6922. if prices[choice] <= player.inventory.materials.gem:
  6923. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = container([items[choice]])
  6924. test = world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]].loot(0)
  6925. world.maplist[self.pos[2]][self.on_map].containers[self.pos[1]][self.pos[0]] = 0#del the container to be sure
  6926. if test == True:
  6927. player.inventory.materials.gem -= prices[choice]
  6928. message.add('The shopkeeper thanks you for your purchacing.')
  6929. sfx.play('shop')
  6930. else:
  6931. message.add('Your bags are to full to buy this item.')
  6932. else:
  6933. message.add('You havn\'t got enough gems to buy this item.')
  6934. else:
  6935. message.add('Never Mind.')
  6936. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'grassland_down':#this is a grassland dungeon stair down
  6937. screen.render_fade(True,False)
  6938. plus = world.maplist[self.pos[2]][self.on_map].monster_plus
  6939. if plus < 5:
  6940. world.dungeon_generator(plus+1,True)
  6941. else:
  6942. world.dungeon_generator(plus+1,False)
  6943. if player.on_map != 'dungeon_0_0':
  6944. player.last_z = player.pos[2]
  6945. player.on_map = 'dungeon_0_0'
  6946. player.pos[2] = 1
  6947. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][8])
  6948. player.pos[0] = pos[0]
  6949. player.pos[1] = pos[1]
  6950. player.stand_check()
  6951. screen.render_fade(False,True)
  6952. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'grassland_up':#this is a grassland dungeon stair up
  6953. choose = screen.get_choice('Do you want to leave?',['No','Yes'],True)
  6954. if choose == 1:
  6955. screen.render_fade(True,False)
  6956. player.on_map = player.last_map
  6957. player.pos[2] = player.last_z
  6958. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][7])
  6959. player.pos[0] = pos[0]
  6960. player.pos[1] = pos[1]
  6961. player.stand_check()
  6962. screen.render_fade(False,True)
  6963. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'tomb_down':#this is a grassland dungeon stair down
  6964. screen.render_fade(True,False)
  6965. plus = world.maplist[self.pos[2]][self.on_map].monster_plus
  6966. if plus < 12:
  6967. world.dungeon_generator(plus+1,stair_down=True,style='Tomb')
  6968. else:
  6969. world.dungeon_generator(plus+1,stair_down=False,style='Tomb')
  6970. if player.on_map != 'dungeon_0_0':
  6971. player.last_z = player.pos[2]
  6972. player.on_map = 'dungeon_0_0'
  6973. player.pos[2] = 1
  6974. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][19])
  6975. player.pos[0] = pos[0]
  6976. player.pos[1] = pos[1]
  6977. player.stand_check()
  6978. screen.render_fade(False,True)
  6979. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'tomb_up':#this is a grassland dungeon stair up
  6980. choose = screen.get_choice('Do you want to leave?',['No','Yes'],True)
  6981. if choose == 1:
  6982. screen.render_fade(True,False)
  6983. player.on_map = player.last_map
  6984. player.pos[2] = player.last_z
  6985. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][18])
  6986. player.pos[0] = pos[0]
  6987. player.pos[1] = pos[1]
  6988. player.stand_check()
  6989. screen.render_fade(False,True)
  6990. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'grot_down':#this is a grassland dungeon stair down
  6991. screen.render_fade(True,False)
  6992. plus = world.grot_generator(1)
  6993. if player.on_map != 'dungeon_0_0':
  6994. player.last_z = player.pos[2]
  6995. player.on_map = 'dungeon_0_0'
  6996. player.pos[2] = 1
  6997. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][15])
  6998. player.pos[0] = pos[0]
  6999. player.pos[1] = pos[1]
  7000. player.stand_check()
  7001. screen.render_fade(False,True)
  7002. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'grot_up':#this is a grassland dungeon stair up
  7003. choose = screen.get_choice('Do you want to leave?',['No','Yes'],True)
  7004. if choose == 1:
  7005. screen.render_fade(True,False)
  7006. player.on_map = player.last_map
  7007. player.pos[2] = player.last_z
  7008. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][14])
  7009. player.pos[0] = pos[0]
  7010. player.pos[1] = pos[1]
  7011. player.stand_check()
  7012. screen.render_fade(False,True)
  7013. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'mine_down':#this is a grassland dungeon stair down
  7014. screen.render_fade(True,False)
  7015. plus = world.mine_generator(1)
  7016. if player.on_map != 'dungeon_0_0':
  7017. player.last_z = player.pos[2]
  7018. player.on_map = 'dungeon_0_0'
  7019. player.pos[2] = 1
  7020. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][17])
  7021. player.pos[0] = pos[0]
  7022. player.pos[1] = pos[1]
  7023. player.stand_check()
  7024. screen.render_fade(False,True)
  7025. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'mine_up':#this is a grassland dungeon stair up
  7026. choose = screen.get_choice('Do you want to leave?',['No','Yes'],True)
  7027. if choose == 1:
  7028. screen.render_fade(True,False)
  7029. player.on_map = player.last_map
  7030. player.pos[2] = player.last_z
  7031. pos = world.maplist[player.pos[2]][player.on_map].find_first(tl.tlist['dungeon'][16])
  7032. player.pos[0] = pos[0]
  7033. player.pos[1] = pos[1]
  7034. player.stand_check()
  7035. screen.render_fade(False,True)
  7036. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'loot':
  7037. message.add('You find nothing interesting.')
  7038. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace != None:
  7039. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = deepcopy(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace)
  7040. else:
  7041. wait_10m = '['+key_name['e']+'] - Wait 10 minute'
  7042. wait_30m = '['+key_name['b']+'] - Wait 30 minutes'
  7043. wait_1h = '['+key_name['i']+'] - Wait 1 hour'
  7044. screen.render_request(wait_10m,wait_30m,wait_1h)
  7045. run = True
  7046. while run:
  7047. turns = 0
  7048. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  7049. if ui == 'exit':
  7050. exitgame = True
  7051. screen.render_load(5)
  7052. save(world,player,time,gods,save_path,os.sep)
  7053. screen.save_tmp_png()
  7054. master_loop = False
  7055. playing = False
  7056. run = False