main.py 518 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485
  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. cheat_mode = False
  26. Time_ready = False
  27. entrance_x = 0
  28. entrance_y = 0
  29. basic_path = os.path.dirname(os.path.realpath('main.py')) #just get the execution path for resources
  30. for t in sys.argv:
  31. if t == '-m':
  32. p = os.path.expanduser(basic_path)
  33. lf = open('rba.desktop','w')
  34. lf.write('[Desktop Entry]\n')
  35. lf.write('Type=Application\n')
  36. lf.write('Name=RogueBox Adventures\n')
  37. lf.write('Comment=A RogueBox Game\n')
  38. lf.write('Exec=sh ' + p + os.sep + 'LIB' + os.sep + 'run.sh\n')
  39. lf.write('Icon=' + p + os.sep + 'icon_big.png\n')
  40. lf.write('Terminal=false\n')
  41. lf.write('Categories=Game;')
  42. lf.close()
  43. rf_path = p + os.sep + 'LIB' + os.sep + 'run.sh'
  44. rf = open(rf_path,'w')
  45. rf.write('#This file was generated automatically. Please don\'t change anything.\n')
  46. rf.write('cd ' + p + '\n')
  47. rf.write('python ' + p + os.sep + 'run.py')
  48. sys_com = 'chmod +x ' + p + os.sep + 'rba.desktop'
  49. os.system(sys_com)
  50. exit(0)
  51. if t == '-c':
  52. cheat_mode = True
  53. if t == '-g':
  54. gcwz_input = True
  55. if t == '-h':
  56. home_save = True
  57. lib_path = basic_path + os.sep + 'LIB'
  58. data_path = basic_path + os.sep + 'DATA'
  59. if home_save == False:
  60. save_path = basic_path + os.sep + 'SAVE' + os.sep + 'World0'
  61. else:
  62. save_path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures' + os.sep + 'SAVE' + os.sep + 'World0'
  63. path = save_path.replace(os.sep+'World0','')
  64. if os.path.exists(path) == False:
  65. for c in range(0,5):
  66. ph = path + os.sep + 'World' + str(c)
  67. os.makedirs(ph)
  68. del path
  69. playing = False
  70. sys.path.append(lib_path)
  71. max_map_size = 52
  72. monitor = [0,0]
  73. try:
  74. import cPickle as p
  75. except:
  76. import pickle as p
  77. try:
  78. p.DEFAULT_PROTOCOL=0
  79. except:
  80. p.HIGHEST_PROTOCOL=0
  81. import random
  82. if gcwz_input == True:
  83. from getch_gcwz import *
  84. else:
  85. from getch import *
  86. from tile import tile
  87. from attribute import attribute
  88. from item import *
  89. from countdown import *
  90. import pygame
  91. from gra_files import *
  92. from util import *
  93. from monster import monster
  94. from copy import deepcopy
  95. from buffs import buffs
  96. from itemlist import *
  97. from tilelist import *
  98. from monsterlist import *
  99. from text import texts
  100. from skill import *
  101. from dialog import *
  102. from version import *
  103. game_options = game_options(basic_path,home_save)
  104. if game_options.check_version == 1:
  105. ver_string = check_version()
  106. else:
  107. ver_string = ' '
  108. class g_screen():
  109. def __init__(self, mode = game_options.screenmode, show_logo = True):
  110. string = 'RogueBoxAdventures ' + version +' "'+version_name+'"'
  111. pygame.display.set_caption(string)
  112. icon = pygame.image.load('icon_small.png')
  113. pygame.display.set_icon(icon)
  114. global monitor
  115. self.fire_mode = 0 #0: normal, 1: fire
  116. self.win_mode = mode
  117. self.hit_matrix = []
  118. for y in range(0,12):
  119. self.hit_matrix.append([])
  120. for x in range(0,15):
  121. self.hit_matrix[y].append(0)
  122. pygame.init()
  123. display_info = pygame.display.Info()
  124. if monitor == [0,0]:
  125. monitor[0] = display_info.current_w
  126. monitor[1] = display_info.current_h
  127. self.displayx = monitor[0]
  128. self.displayy = monitor[1]
  129. #check if the screenmode is 16:9
  130. self.displayx = monitor[0]-monitor[0]%640
  131. self.displayy = monitor[1]-monitor[1]%360
  132. winstyle = pygame.FULLSCREEN
  133. if cheat_mode == True and self.win_mode == 2:
  134. self.win_mode = 1 #disable fullscreen in cheat mode
  135. if self.win_mode == 2:
  136. self.screen = pygame.display.set_mode((self.displayx,self.displayy),winstyle)
  137. pygame.mouse.set_visible(game_options.mousepad)
  138. elif self.win_mode == 0 and low_res == False:
  139. self.screen = pygame.display.set_mode((640,360))
  140. self.displayx = 640
  141. self.displayy = 360
  142. elif self.win_mode == 1 and low_res == False:
  143. self.screen = pygame.display.set_mode((1280,720))
  144. self.displayx = 1280
  145. self.displayy = 720
  146. font_path = basic_path + os.sep + 'FONT' + os.sep + 'PressStart2P.ttf'
  147. self.font = pygame.font.Font(font_path,8)
  148. if low_res == True:
  149. str_ext = '_low_res'
  150. else:
  151. str_ext = ''
  152. if __name__ == '__main__':
  153. show_logo = False
  154. if show_logo == True:
  155. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  156. ran = random.randint(0,4)
  157. i_name = display_path + 'logo' + str(ran) + str_ext + '.png'
  158. i = pygame.image.load(i_name)
  159. i = pygame.transform.scale(i,(self.displayx,self.displayy))
  160. self.screen.blit(i,(0,0))
  161. pygame.display.flip()
  162. getch(640,360,mode=1)
  163. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  164. ran = random.randint(0,4)
  165. i_name = display_path + 'logo_gpl' + str_ext + '.png'
  166. i = pygame.image.load(i_name)
  167. i = pygame.transform.scale(i,(self.displayx,self.displayy))
  168. self.screen.blit(i,(0,0))
  169. pygame.display.flip()
  170. getch(640,360,mode=1)
  171. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  172. i_name = display_path + 'oga' + str_ext + '.png'
  173. i = pygame.image.load(i_name)
  174. i = pygame.transform.scale(i,(self.displayx,self.displayy))
  175. self.screen.blit(i,(0,0))
  176. pygame.display.flip()
  177. getch(640,360,mode=1)
  178. def render_fade(self,fadeout,fadein,menu='default'):
  179. if menu == 'inventory':
  180. bg = player.inventory.render(0,0,simulate=True)
  181. elif menu == 'screen':
  182. bg = screen.screen
  183. elif menu == 'loot':
  184. bg = world.maplist[player.pos[2]][player.on_map].containers[player.pos[1]][player.pos[0]].inventory(simulated=True)
  185. elif menu == 'brake':
  186. bg = screen.render_brake(simulate=True)
  187. elif menu == 'main':
  188. bg = screen.render_main_menu(simulate=True)
  189. else:
  190. bg = self.render(0,True)
  191. clock = pygame.time.Clock()
  192. if fadein:
  193. for i in range(255,0,-15):
  194. helpsur = pygame.Surface((self.displayx,self.displayy))
  195. helpsur.fill((48,48,48))
  196. helpsur.set_alpha(i)
  197. self.screen.blit(bg,(0,0))
  198. self.screen.blit(helpsur,(0,0))
  199. pygame.display.flip()
  200. clock.tick(510)
  201. if fadeout:
  202. for i in range(0,255,15):
  203. helpsur = pygame.Surface((self.displayx,self.displayy))
  204. helpsur.fill((48,48,48))
  205. helpsur.set_alpha(i)
  206. self.screen.blit(bg,(0,0))
  207. self.screen.blit(helpsur,(0,0))
  208. pygame.display.flip()
  209. clock.tick(510)
  210. def reset_hit_matrix(self):
  211. self.hit_matrix = []
  212. for y in range(0,12):
  213. self.hit_matrix.append([])
  214. for x in range(0,15):
  215. self.hit_matrix[y].append(0)
  216. def write_hit_matrix(self,x,y,style):
  217. #style: 0:nothing
  218. # 1:fire_path
  219. # 2:fire_path_monster
  220. # 3:miss
  221. # 4:hit
  222. # 5:critical
  223. # 6:heal
  224. # 7:teleport
  225. # 8:minus_gem
  226. # 9:plus_gem
  227. # 10:plus_fish
  228. # 11:plus_shoe
  229. # 12:monster_lvl_up
  230. # 13:monster_die
  231. # 14:attention
  232. # 15:found
  233. # 16:drop
  234. # 17:fear
  235. # 18:blood_minus
  236. # 19:blood_plus
  237. # 20:throw
  238. # 21:minus_item
  239. # 22:plus_item
  240. # 23:spellwave
  241. xx = x - player.pos[0] + 8
  242. yy = y - player.pos[1] + 6
  243. try:
  244. if xx >= 0 and yy >= 0:
  245. self.hit_matrix[yy][xx] = style
  246. except:
  247. None
  248. def render_hits(self):
  249. s = pygame.Surface((480,360))
  250. s.fill((255,0,255))
  251. start = 0
  252. for y in range(start,len(self.hit_matrix)):
  253. for x in range(start,len(self.hit_matrix[0])):
  254. if self.hit_matrix[y][x] == 1:
  255. s.blit(gra_files.gdic['display'][11],(((x-start)*32),(y-start)*32))
  256. elif self.hit_matrix[y][x] == 2:
  257. s.blit(gra_files.gdic['display'][12],(((x-start)*32),(y-start)*32))
  258. elif self.hit_matrix[y][x] == 3:
  259. s.blit(gra_files.gdic['display'][13],(((x-start)*32),(y-start)*32))
  260. elif self.hit_matrix[y][x] == 4:
  261. s.blit(gra_files.gdic['display'][14],(((x-start)*32),(y-start)*32))
  262. elif self.hit_matrix[y][x] == 5:
  263. s.blit(gra_files.gdic['display'][15],(((x-start)*32),(y-start)*32))
  264. elif self.hit_matrix[y][x] == 6:
  265. s.blit(gra_files.gdic['display'][23],(((x-start)*32),(y-start)*32))
  266. elif self.hit_matrix[y][x] == 7:
  267. s.blit(gra_files.gdic['display'][24],(((x-start)*32),(y-start)*32))
  268. elif self.hit_matrix[y][x] == 8:
  269. s.blit(gra_files.gdic['display'][26],(((x-start)*32),(y-start)*32))
  270. elif self.hit_matrix[y][x] == 9:
  271. s.blit(gra_files.gdic['display'][27],(((x-start)*32),(y-start)*32))
  272. elif self.hit_matrix[y][x] == 10:
  273. s.blit(gra_files.gdic['display'][42],(((x-start)*32),(y-start)*32))
  274. elif self.hit_matrix[y][x] == 11:
  275. s.blit(gra_files.gdic['display'][43],(((x-start)*32),(y-start)*32))
  276. elif self.hit_matrix[y][x] == 12:
  277. s.blit(gra_files.gdic['display'][51],(((x-start)*32),(y-start)*32))
  278. elif self.hit_matrix[y][x] == 13:
  279. s.blit(gra_files.gdic['display'][58],(((x-start)*32),(y-start)*32))
  280. elif self.hit_matrix[y][x] == 14:
  281. s.blit(gra_files.gdic['display'][59],(((x-start)*32),(y-start)*32))
  282. elif self.hit_matrix[y][x] == 15:
  283. s.blit(gra_files.gdic['display'][60],(((x-start)*32),(y-start)*32))
  284. elif self.hit_matrix[y][x] == 16:
  285. s.blit(gra_files.gdic['display'][61],(((x-start)*32),(y-start)*32))
  286. elif self.hit_matrix[y][x] == 17:
  287. s.blit(gra_files.gdic['display'][62],(((x-start)*32),(y-start)*32))
  288. elif self.hit_matrix[y][x] == 18:
  289. s.blit(gra_files.gdic['display'][63],(((x-start)*32),(y-start)*32))
  290. elif self.hit_matrix[y][x] == 19:
  291. s.blit(gra_files.gdic['display'][64],(((x-start)*32),(y-start)*32))
  292. elif self.hit_matrix[y][x] == 20:
  293. s.blit(gra_files.gdic['display'][65],(((x-start)*32),(y-start)*32))
  294. elif self.hit_matrix[y][x] == 21:
  295. s.blit(gra_files.gdic['display'][66],(((x-start)*32),(y-start)*32))
  296. elif self.hit_matrix[y][x] == 22:
  297. s.blit(gra_files.gdic['display'][67],(((x-start)*32),(y-start)*32))
  298. elif self.hit_matrix[y][x] == 23:
  299. s.blit(gra_files.gdic['display'][70],(((x-start)*32),(y-start)*32))
  300. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  301. s = s.convert_alpha()
  302. return s
  303. def render_main_menu(self,simulate=False):
  304. if simulate == False:
  305. screen.render_fade(False,True,'main')
  306. if home_save == False:
  307. display_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  308. alt_path = display_path
  309. else:
  310. display_path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures' + os.sep
  311. alt_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep
  312. num = 0
  313. master_loop = True
  314. run = True
  315. while run:
  316. s = pygame.Surface((640,360))
  317. s.fill((48,48,48))
  318. try:
  319. i_name = display_path + 'tmp.png'
  320. i = pygame.image.load(i_name)
  321. i.set_colorkey((255,0,255),pygame.RLEACCEL)
  322. i = i.convert_alpha()
  323. s.blit(i,(0,0))
  324. except:
  325. i_name = alt_path + 'alt.png'
  326. i = pygame.image.load(i_name)
  327. i.set_colorkey((255,0,255),pygame.RLEACCEL)
  328. i = i.convert_alpha()
  329. s.blit(i,(0,0))
  330. s.blit(gra_files.gdic['display'][16],(0,0))
  331. menu_list = ('PLAY','OPTIONS','CREDITS','QUIT')
  332. for c in range(0,len(menu_list)):
  333. name_image = self.font.render(menu_list[c],1,(0,0,0))
  334. s.blit(name_image,(210,145+(c*45)))
  335. s.blit(gra_files.gdic['display'][4],(185,138+(num*45)))
  336. version_info = 'v'+version+' "'+version_name+'"'
  337. ver_info_image1 = self.font.render(version_info,1,(0,0,0))
  338. ver_info_image2 = self.font.render(version_info,1,(255,255,255))
  339. s.blit(ver_info_image1,(107,85))
  340. s.blit(ver_info_image2,(105,85))
  341. if game_options.check_version == 1:
  342. if ver_string == 'This version is up to date.':
  343. ver_image = self.font.render(ver_string,1,(0,255,0))
  344. elif ver_string == 'Old version!!! Please update.':
  345. ver_image = self.font.render(ver_string,1,(255,0,0))
  346. else:
  347. ver_image = self.font.render(ver_string,1,(255,255,255))
  348. ver_image2 = self.font.render(ver_string,1,(0,0,0))
  349. s.blit(ver_image2,(12,340))
  350. s.blit(ver_image,(10,340))
  351. if game_options.mousepad == 0:
  352. s_h = pygame.Surface((160,360))
  353. s_h.fill((48,48,48))
  354. s.blit(s_h,(480,0))
  355. s_help = pygame.Surface((640,360))
  356. s_help.fill((48,48,48))
  357. s_help.blit(s,(80,0))
  358. s = s_help
  359. else:
  360. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  361. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  362. if simulate == True:
  363. return s
  364. self.screen.blit(s,(0,0))
  365. pygame.display.flip()
  366. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  367. if ui == 'exit':
  368. master_loop = False
  369. run = False
  370. if ui == 'w':
  371. num -= 1
  372. if num < 0:
  373. num = 0
  374. elif ui == 's':
  375. num += 1
  376. if num > 3:
  377. num = 3
  378. elif ui == 'e':
  379. if num == 0:
  380. test = screen.choose_save_path()
  381. if test == 'exit':
  382. master_loop = False
  383. run = False
  384. elif num == 1:
  385. test = screen.render_options()
  386. if test == 'exit':
  387. master_loop = False
  388. run = False
  389. elif num == 2:
  390. test = screen.render_credits()
  391. if test == 'exit':
  392. master_loop = False
  393. run = False
  394. elif num == 3:
  395. master_loop = False
  396. run = False
  397. return master_loop
  398. def render_crash(self):
  399. run = True
  400. while run:
  401. self.screen.fill((48,48,48))
  402. string = []
  403. string.append('Sorry, something went wrong.')
  404. string.append('Check out debug.txt for more informations.')
  405. debug_location = '('+save_path+')'
  406. for c in range(0,6):
  407. debug_location = debug_location.replace('World'+str(c),'debug.txt')
  408. string.append(debug_location)
  409. st = []
  410. for i in string:
  411. st.append(self.font.render(i,1,(255,255,255)))
  412. for j in range(0,len(st)):
  413. self.screen.blit(st[j],(5,25+j*25))
  414. pygame.display.flip()
  415. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  416. if ui != 'none':
  417. run = False
  418. def choose_save_path(self):
  419. global save_path
  420. global playing
  421. global master_loop
  422. global gra_files
  423. gra_files = g_files()
  424. if home_save == True:
  425. path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures'
  426. else:
  427. path = basic_path
  428. run = True
  429. while run:
  430. menu_items = []
  431. for c in range(0,5):
  432. save_path = path + os.sep + 'SAVE' + os.sep + 'World' + str(c)
  433. p_attribute = attribute(2,2,2,2,2,10,10)
  434. p_inventory = inventory()
  435. player_help = player_class ('-EMPTY SLOT-', 'local_0_0', p_attribute,p_inventory, build= 'Auto')
  436. if player_help.name != '-EMPTY SLOT-':
  437. item_string = player_help.name + ' LVL:' + str(player_help.lvl)
  438. else:
  439. item_string = '-EMPTY SLOT-'
  440. menu_items.append(item_string)
  441. menu_items.append('~~ERASE~~')
  442. menu_items.append('~~BACK~~')
  443. choice = screen.get_choice('Choose a saved game',menu_items,False)
  444. if choice == 'exit':
  445. master_loop = False
  446. run = False
  447. return('exit')
  448. if choice < 5:
  449. save_path = path + os.sep + 'SAVE' + os.sep + 'World' + str(choice)
  450. playing = True
  451. run = False
  452. elif choice == 5:
  453. menu_items_erase = []
  454. for d in range(0,5):
  455. menu_items_erase.append(menu_items[d])
  456. menu_items_erase.append('~~BACK~~')
  457. choice2 = screen.get_choice('Choose a game to erase',menu_items_erase,False,'Warning')
  458. if choice2 < 5:
  459. save_path = path + os.sep + 'SAVE' + os.sep + 'World' + str(choice2)
  460. try:
  461. choice3 = screen.get_choice('Are you sure?',('No','Yes'),False,'Warning')
  462. if choice3 == 1:
  463. h = ('world.data','time.data','player.data','gods.data')
  464. for i in h:
  465. p = save_path + os.sep + i
  466. os.remove(p)
  467. except:
  468. None
  469. elif choice == 6:
  470. run = False
  471. def save_tmp_png(self):
  472. x = player.pos[0]
  473. if x-10 < 0:
  474. x += -1*(x-11)
  475. elif x+10 > max_map_size-2:
  476. x -= 10
  477. y = player.pos[1]
  478. if y-10 < 0:
  479. y += -1*(y-11)
  480. elif y+10 > max_map_size-2:
  481. y -= 10
  482. z = player.pos[2]
  483. s = pygame.Surface((480,360))
  484. for yy in range(-5,10):
  485. for xx in range(-7,8):
  486. t_pos = world.maplist[z][player.on_map].tilemap[y+yy][x+xx].tile_pos
  487. t_replace = world.maplist[z][player.on_map].tilemap[y+yy][x+xx].replace
  488. if t_replace == None:
  489. s.blit(gra_files.gdic['tile32'][t_pos[1]][t_pos[0]],((xx+7)*32,(yy+5)*32))
  490. else:
  491. try:
  492. #render the replaced tile under the replacing one. eg.: for stacks
  493. s.blit(gra_files.gdic['tile32'][t_replace.tile_pos[1]][t_replace.tile_pos[0]],((xx+7)*32,(yy+5)*32))
  494. s.blit(gra_files.gdic['tile32'][t_pos[1]][t_pos[0]],((xx+7)*32,(yy+5)*32))
  495. except:
  496. None
  497. if home_save == False:
  498. tmp_save_path = basic_path +os.sep + 'GRAPHIC' + os.sep + 'DISPLAY' + os.sep + 'tmp.png'
  499. else:
  500. tmp_save_path = os.path.expanduser('~') + os.sep + '.config' + os.sep + 'RogueBox-Adventures' + os.sep + 'tmp.png'
  501. pygame.image.save(s,tmp_save_path)
  502. def re_init(self): # For changing screenmode
  503. options_path = save_path.replace(os.sep + 'World0','')
  504. if game_options.screenmode == 2 and cheat_mode == True:
  505. game_options.screenmode = 0
  506. mode = game_options.screenmode
  507. if self.win_mode < 2:
  508. mode += 1
  509. else:
  510. mode = 0
  511. if mode == 2 and cheat_mode == True:
  512. mode = 0
  513. game_options.screenmode = mode
  514. save_options(game_options,options_path,os.sep)
  515. self.__init__(game_options.screenmode,False)
  516. def draw_player(self):
  517. s = pygame.Surface((32,32))
  518. s.fill((255,0,255))
  519. if player.inventory.wearing['Background'] != player.inventory.nothing:
  520. 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))
  521. skinstring = 'SKIN_' + player.gender + '_' + str(player.style +1)
  522. s.blit(gra_files.gdic['char'][skinstring],(0,0))
  523. if player.inventory.wearing['Clothing'] == player.inventory.nothing:
  524. underwear_string = player.gender + '_underwear'
  525. s.blit(gra_files.gdic['char'][underwear_string],(0,0))
  526. try:
  527. render_hair = (player.inventory.wearing['Hat'].override_hair == False)
  528. except:
  529. render_hair = True
  530. if player.inventory.wearing['Head'] == player.inventory.nothing and render_hair:
  531. hairstring = 'HAIR_' + player.gender + '_' + str(player.style +1)
  532. s.blit(gra_files.gdic['char'][hairstring],(0,0))
  533. if player.inventory.wearing['Hat'] != player.inventory.nothing:
  534. 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))
  535. else:
  536. if player.inventory.wearing['Hat'] == player.inventory.nothing:
  537. if player.inventory.wearing['Head'] != player.inventory.nothing:
  538. helmetstring = player.gender + '_' + player.inventory.wearing['Head'].material + '_' + player.inventory.wearing['Head'].classe
  539. s.blit(gra_files.gdic['char'][helmetstring],(0,0))
  540. else:
  541. if render_hair == True:
  542. hairstring = 'HAIR_' + player.gender + '_' + str(player.style +1)
  543. s.blit(gra_files.gdic['char'][hairstring],(0,0))
  544. 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))
  545. if player.inventory.wearing['Clothing'] == player.inventory.nothing:
  546. if player.inventory.wearing['Body'] != player.inventory.nothing:
  547. armorstring = player.gender + '_' + player.inventory.wearing['Body'].material + '_' + player.inventory.wearing['Body'].classe
  548. s.blit(gra_files.gdic['char'][armorstring],(0,0))
  549. if player.inventory.wearing['Legs'] != player.inventory.nothing:
  550. cuissestring = player.gender + '_' + player.inventory.wearing['Legs'].material + '_' + player.inventory.wearing['Legs'].classe
  551. s.blit(gra_files.gdic['char'][cuissestring],(0,0))
  552. if player.inventory.wearing['Feet'] != player.inventory.nothing:
  553. shoestring = player.gender + '_' + player.inventory.wearing['Feet'].material + '_' + player.inventory.wearing['Feet'].classe
  554. s.blit(gra_files.gdic['char'][shoestring],(0,0))
  555. else:
  556. 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))
  557. if player.inventory.wearing['Hold(R)'] != player.inventory.nothing:
  558. weaponstring = 'WEAPONS_' + player.inventory.wearing['Hold(R)'].material + '_' + player.inventory.wearing['Hold(R)'].classe
  559. s.blit(gra_files.gdic['char'][weaponstring],(0,0))
  560. if player.inventory.wearing['Hold(L)'] != player.inventory.nothing:
  561. weaponstring = 'WEAPONS_' + player.inventory.wearing['Hold(L)'].material + '_' + player.inventory.wearing['Hold(L)'].classe
  562. s.blit(gra_files.gdic['char'][weaponstring],(0,0))
  563. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]][player.pos[0]].move_group == 'low_liquid':
  564. help_s = pygame.Surface((32,5))
  565. help_s.fill((255,0,255))
  566. s.blit(help_s,(0,27))
  567. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]][player.pos[0]].move_group == 'swim':
  568. help_s = pygame.Surface((32,13))
  569. help_s.fill((255,0,255))
  570. s.blit(help_s,(0,19))
  571. if player.buffs.get_buff('invisible') > 0:
  572. s.set_alpha(120)
  573. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  574. return s
  575. def draw_tile(self,on_map,x,y,z,visible):
  576. s = pygame.Surface((32,32))
  577. s.fill((48,48,48))
  578. if x > max_map_size-1 or y > max_map_size-1 or x < 0 or y < 0:
  579. return s
  580. if world.maplist[z][on_map].known[y][x] == 0:
  581. s.blit(gra_files.gdic['tile32'][0][3],(0,0))
  582. else:
  583. if world.maplist[z][on_map].tilemap[y][x].replace != None:
  584. old_tile = world.maplist[z][on_map].tilemap[y][x]
  585. new_tile = world.maplist[z][on_map].tilemap[y][x]
  586. run = True
  587. while run:
  588. new_tile = old_tile.replace
  589. if new_tile != None:
  590. old_tile = new_tile
  591. else:
  592. run = False
  593. if len(old_tile.tile_pos) > 2:
  594. if time.minute%2 == 0:
  595. s.blit(gra_files.gdic['tile32'][old_tile.tile_pos[1]][old_tile.tile_pos[0]],(0,0))
  596. else:
  597. s.blit(gra_files.gdic['tile32'][old_tile.tile_pos[3]][old_tile.tile_pos[2]],(0,0))
  598. else:
  599. s.blit(gra_files.gdic['tile32'][old_tile.tile_pos[1]][old_tile.tile_pos[0]],(0,0))
  600. if len(world.maplist[z][on_map].tilemap[y][x].tile_pos) > 2:
  601. if time.minute%2 == 0:
  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. else:
  604. 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))
  605. else:
  606. 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))
  607. try:
  608. if gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]] != False:
  609. if x > 0 and world.maplist[z][on_map].tilemap[y][x-1].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  610. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['v'],(0,0))
  611. if x < max_map_size and world.maplist[z][on_map].tilemap[y][x+1].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  612. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['v'],(30,0))
  613. if y > 0 and world.maplist[z][on_map].tilemap[y-1][x].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  614. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['h'],(0,0))
  615. if y < max_map_size and world.maplist[z][on_map].tilemap[y+1][x].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  616. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['h'],(0,30))
  617. if x > 0 and y > 0 and world.maplist[z][on_map].tilemap[y-1][x-1].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  618. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['c'],(0,0))
  619. if x < max_map_size and y > 0 and world.maplist[z][on_map].tilemap[y-1][x+1].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  620. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['c'],(30,0))
  621. if x > 0 and y < max_map_size and world.maplist[z][on_map].tilemap[y+1][x-1].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  622. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['c'],(0,30))
  623. if x < max_map_size and y < max_map_size and world.maplist[z][on_map].tilemap[y+1][x+1].move_group != world.maplist[z][on_map].tilemap[y][x].move_group:
  624. s.blit(gra_files.gdic['border'][world.maplist[z][on_map].tilemap[y][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x].tile_pos[0]]['c'],(30,30))
  625. except:
  626. None
  627. if world.maplist[z][on_map].tilemap[y][x].move_group == 'low_liquid' or world.maplist[z][on_map].tilemap[y][x].move_group == 'swim':
  628. if world.maplist[z][on_map].tilemap[y][x-1].replace != None:
  629. try:
  630. if world.maplist[z][on_map].tilemap[y][x-1].replace.ignore_liquid == True:
  631. mgw = 'solid'
  632. else:
  633. mgw = world.maplist[z][on_map].tilemap[y][x-1].replace.move_group
  634. except:
  635. mgw = world.maplist[z][on_map].tilemap[y][x-1].replace.move_group
  636. else:
  637. try:
  638. if world.maplist[z][on_map].tilemap[y][x-1].ignore_liquid == True:
  639. mgw = 'solid'
  640. else:
  641. mgw = world.maplist[z][on_map].tilemap[y][x-1].move_group
  642. except:
  643. mgw = world.maplist[z][on_map].tilemap[y][x-1].move_group
  644. if world.maplist[z][on_map].tilemap[y][x+1].replace != None:
  645. try:
  646. if world.maplist[z][on_map].tilemap[y][x+1].replace.ignore_liquid == True:
  647. mge = 'solid'
  648. else:
  649. mge = world.maplist[z][on_map].tilemap[y][x+1].replace.move_group
  650. except:
  651. mge = world.maplist[z][on_map].tilemap[y][x+1].replace.move_group
  652. else:
  653. try:
  654. if world.maplist[z][on_map].tilemap[y][x+1].ignore_liquid == True:
  655. mge = 'solid'
  656. else:
  657. mge = world.maplist[z][on_map].tilemap[y][x+1].move_group
  658. except:
  659. mge = world.maplist[z][on_map].tilemap[y][x+1].move_group
  660. if world.maplist[z][on_map].tilemap[y-1][x].replace != None:
  661. try:
  662. if world.maplist[z][on_map].tilemap[y-1][x].replace.ignore_liquid == True:
  663. mgn = 'solid'
  664. else:
  665. mgn = world.maplist[z][on_map].tilemap[y-1][x].replace.move_group
  666. except:
  667. mgn = world.maplist[z][on_map].tilemap[y-1][x].replace.move_group
  668. else:
  669. try:
  670. if world.maplist[z][on_map].tilemap[y-1][x].ignore_liquid == True:
  671. mgn = 'solid'
  672. else:
  673. mgn = world.maplist[z][on_map].tilemap[y-1][x].move_group
  674. except:
  675. mgn = world.maplist[z][on_map].tilemap[y-1][x].move_group
  676. if world.maplist[z][on_map].tilemap[y+1][x].replace != None:
  677. try:
  678. if world.maplist[z][on_map].tilemap[y+1][x].replace.ignore_liquid == True:
  679. mgs = 'solid'
  680. else:
  681. mgs = world.maplist[z][on_map].tilemap[y+1][x].replace.move_group
  682. except:
  683. mgs = world.maplist[z][on_map].tilemap[y+1][x].replace.move_group
  684. else:
  685. try:
  686. if world.maplist[z][on_map].tilemap[y+1][x].ignore_liquid == True:
  687. mgs = 'solid'
  688. else:
  689. mgs = world.maplist[z][on_map].tilemap[y+1][x].move_group
  690. except:
  691. mgs = world.maplist[z][on_map].tilemap[y+1][x].move_group
  692. if mgw == 'soil' or mgw == 'low_liquid':
  693. hs = pygame.Surface((32,32))
  694. if world.maplist[z][on_map].tilemap[y][x-1].replace == None:
  695. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y][x-1].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x-1].tile_pos[0]],(0,0))
  696. else:
  697. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y][x-1].replace.tile_pos[1]][world.maplist[z][on_map].tilemap[y][x-1].replace.tile_pos[0]],(0,0))
  698. if time.minute%2 == 0:
  699. hs.blit(gra_files.gdic['edge']['w1'],(0,0))
  700. else:
  701. hs.blit(gra_files.gdic['edge']['w2'],(0,0))
  702. hs.set_colorkey((255,255,255),pygame.RLEACCEL)
  703. hs = hs.convert_alpha()
  704. s.blit(hs,(0,0))
  705. if mge == 'soil' or mge == 'low_liquid':
  706. hs = pygame.Surface((32,32))
  707. if world.maplist[z][on_map].tilemap[y][x+1].replace == None:
  708. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y][x+1].tile_pos[1]][world.maplist[z][on_map].tilemap[y][x+1].tile_pos[0]],(0,0))
  709. else:
  710. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y][x+1].replace.tile_pos[1]][world.maplist[z][on_map].tilemap[y][x+1].replace.tile_pos[0]],(0,0))
  711. if time.minute%2 == 0:
  712. hs.blit(gra_files.gdic['edge']['e1'],(0,0))
  713. else:
  714. hs.blit(gra_files.gdic['edge']['e2'],(0,0))
  715. hs.set_colorkey((255,255,255),pygame.RLEACCEL)
  716. hs = hs.convert_alpha()
  717. s.blit(hs,(0,0))
  718. if mgn == 'soil' or mgn == 'low_liquid':
  719. hs = pygame.Surface((32,32))
  720. if world.maplist[z][on_map].tilemap[y-1][x].replace == None:
  721. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y-1][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y-1][x].tile_pos[0]],(0,0))
  722. else:
  723. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y-1][x].replace.tile_pos[1]][world.maplist[z][on_map].tilemap[y-1][x].replace.tile_pos[0]],(0,0))
  724. if time.minute%2 == 0:
  725. hs.blit(gra_files.gdic['edge']['n1'],(0,0))
  726. else:
  727. hs.blit(gra_files.gdic['edge']['n2'],(0,0))
  728. hs.set_colorkey((255,255,255),pygame.RLEACCEL)
  729. hs = hs.convert_alpha()
  730. s.blit(hs,(0,0))
  731. if mgs == 'soil' or mgs == 'low_liquid':
  732. hs = pygame.Surface((32,32))
  733. if world.maplist[z][on_map].tilemap[y+1][x].replace == None:
  734. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y+1][x].tile_pos[1]][world.maplist[z][on_map].tilemap[y+1][x].tile_pos[0]],(0,0))
  735. else:
  736. hs.blit(gra_files.gdic['tile32'][world.maplist[z][on_map].tilemap[y+1][x].replace.tile_pos[1]][world.maplist[z][on_map].tilemap[y+1][x].replace.tile_pos[0]],(0,0))
  737. if time.minute%2 == 0:
  738. hs.blit(gra_files.gdic['edge']['s1'],(0,0))
  739. else:
  740. hs.blit(gra_files.gdic['edge']['s2'],(0,0))
  741. hs.set_colorkey((255,255,255),pygame.RLEACCEL)
  742. hs = hs.convert_alpha()
  743. s.blit(hs,(0,0))
  744. if visible == False:
  745. s.blit(gra_files.gdic['display'][6],(0,0))
  746. if world.maplist[z][on_map].npcs[y][x] != 0:
  747. s.blit(self.draw_monster(x,y,z,on_map,visible),(0,0))
  748. return s
  749. def draw_monster(self,x,y,z,on_map,visible):
  750. s = pygame.Surface((32,32))
  751. s.fill((255,0,255))
  752. if visible == True:
  753. pos = world.maplist[z][on_map].npcs[y][x].sprite_pos
  754. s.blit(gra_files.gdic['monster'][pos[1]][pos[0]],(0,0))
  755. if not 'hover' in world.maplist[z][on_map].npcs[y][x].properties:
  756. if world.maplist[z][on_map].tilemap[y][x].move_group == 'low_liquid':
  757. help_s = pygame.Surface((32,5))
  758. help_s.fill((255,0,255))
  759. s.blit(help_s,(0,27))
  760. elif world.maplist[z][on_map].tilemap[y][x].move_group == 'swim':
  761. help_s = pygame.Surface((32,13))
  762. help_s.fill((255,0,255))
  763. s.blit(help_s,(0,19))
  764. if '-skill' in world.maplist[z][on_map].npcs[y][x].properties:
  765. s.blit(gra_files.gdic['display'][73],(0,0))
  766. elif 'blind' in world.maplist[z][on_map].npcs[y][x].properties:
  767. s.blit(gra_files.gdic['display'][74],(0,0))
  768. if world.maplist[z][on_map].npcs[y][x].quest_state != 'None':
  769. s.blit(gra_files.gdic['display'][59],(0,0))
  770. if world.maplist[z][on_map].npcs[y][x].move_border == 10:
  771. None
  772. elif world.maplist[z][on_map].npcs[y][x].AI_style == 'ignore':
  773. s.blit(gra_files.gdic['display'][28],(0,0))
  774. if not ('pet0' in world.maplist[z][on_map].npcs[y][x].properties or 'pet1' in world.maplist[z][on_map].npcs[y][x].properties or 'pet2' in world.maplist[z][on_map].npcs[y][x].properties):
  775. lvl = str(world.maplist[z][on_map].npcs[y][x].lvl)
  776. if len(lvl) == 1:
  777. lvl = '0'+lvl
  778. elif len(lvl) > 2:
  779. lvl = lvl[0]+'+'
  780. s.blit(gra_files.gdic['num'][lvl[0]],(0,6))
  781. s.blit(gra_files.gdic['num'][lvl[1]],(0,14))
  782. else:
  783. s.blit(gra_files.gdic['display'][72],(0,6))
  784. elif world.maplist[z][on_map].npcs[y][x].AI_style == 'flee':
  785. s.blit(gra_files.gdic['display'][29],(0,0))
  786. lvl = str(world.maplist[z][on_map].npcs[y][x].lvl)
  787. if len(lvl) == 1:
  788. lvl = '0'+lvl
  789. elif len(lvl) > 2:
  790. lvl = lvl[0]+'+'
  791. s.blit(gra_files.gdic['num'][lvl[0]],(0,6))
  792. s.blit(gra_files.gdic['num'][lvl[1]],(0,14))
  793. elif world.maplist[z][on_map].npcs[y][x].AI_style == 'company':
  794. s.blit(gra_files.gdic['display'][71],(0,0))
  795. help_sur_0 = pygame.Surface((26,3))
  796. help_sur_0.fill((48,48,48))
  797. s.blit(help_sur_0,(3,29))
  798. help_sur_1 = pygame.Surface((24,1))
  799. help_sur_1.fill((89,0,0))
  800. s.blit(help_sur_1,(4,30))
  801. hs2_length = (24*player.pet_lp)/world.maplist[z][on_map].npcs[y][x].basic_attribute.max_lp
  802. help_sur_2 = pygame.Surface((hs2_length,1))
  803. help_sur_2.fill((0,255,0))
  804. s.blit(help_sur_2,(4,30))
  805. else:
  806. s.blit(gra_files.gdic['display'][30],(0,0))
  807. lvl = str(world.maplist[z][on_map].npcs[y][x].lvl)
  808. if len(lvl) == 1:
  809. lvl = '0'+lvl
  810. elif len(lvl) > 2:
  811. lvl = lvl[0]+'+'
  812. s.blit(gra_files.gdic['num'][lvl[0]],(0,6))
  813. s.blit(gra_files.gdic['num'][lvl[1]],(0,14))
  814. if world.maplist[z][on_map].npcs[y][x].move_border > 10:
  815. s.blit(gra_files.gdic['display'][69],(0,0))
  816. else:
  817. 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':
  818. pos = world.maplist[z][on_map].npcs[y][x].sprite_pos
  819. s.blit(gra_files.gdic['monster'][pos[1]][pos[0]],(0,0))
  820. else:
  821. coin = random.randint(0,1)
  822. if coin == 1:
  823. s.blit(gra_files.gdic['display'][7],(0,0))
  824. else:
  825. s.blit(gra_files.gdic['display'][6],(0,0))
  826. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  827. return s
  828. def generate_light_effect(self):
  829. if player.buffs.get_buff('berserk') > 0:
  830. y = 3
  831. elif player.buffs.get_buff('nightvision') > 0:
  832. y = 2
  833. elif player.pos[2] > 0:
  834. y = 1
  835. else:
  836. y= 0
  837. x = time.hour
  838. if player.buffs.get_buff('berserk') > 0:
  839. alpha = 135
  840. elif player.buffs.get_buff('nightvision') > 0:
  841. alpha = 60
  842. elif player.pos[2] == 0:
  843. if time.hour == 12:
  844. alpha = 0
  845. elif time.hour < 12:
  846. alpha = 60-(time.hour*5)
  847. elif time.hour > 12:
  848. alpha = 0+((time.hour-12)*5)
  849. else:
  850. alpha = 135
  851. light_color = gra_files.gdic['lightmap'].get_at((x,y))
  852. s = pygame.Surface((640,360))
  853. s.fill(light_color)
  854. if player.buffs.get_buff('light') > 0 and player.buffs.get_buff('berserk') == 0:
  855. pygame.draw.circle(s,(255,0,255),[254,197],120,0)
  856. help_tile = pygame.Surface((32,32))
  857. help_tile.fill(light_color)
  858. fov = world.maplist[player.pos[2]][player.on_map].check_fov(player.pos[0],player.pos[1],6)
  859. for y in range(0,len(fov)-1):
  860. for x in range(0,len(fov[y])-1):
  861. if fov[y][x] == 0:
  862. s.blit(help_tile,(x*32,y*32))
  863. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  864. s.set_alpha(alpha)
  865. return s
  866. def render(self,mes_num, simulate = False, photo = False):
  867. radius = 6
  868. if player.pos[2] > 0:
  869. radius = 2
  870. elif player.pos[2] == 0:
  871. if time.hour > 22 or time.hour < 4:
  872. radius = 2
  873. elif time.hour > 21 or time.hour < 5:
  874. radius = 3
  875. elif time.hour > 20 or time.hour < 6:
  876. radius = 4
  877. elif time.hour > 19 or time.hour < 7:
  878. radius = 5
  879. if player.buffs.get_buff('light') > 0 or player.buffs.get_buff('nightvision'):
  880. radius = 6
  881. if player.buffs.get_buff('blind') > 0:
  882. radius = 0
  883. s = pygame.Surface((640,360))
  884. test = message.sget()
  885. s.fill((48,48,48)) #paint it grey(to clear the screen)
  886. start_pos_x = 240 #the center of the main map view
  887. start_pos_y = 180
  888. ymin = player.pos[1]-6
  889. ymax = player.pos[1]+6
  890. xmin = player.pos[0]-8
  891. xmax = player.pos[0]+7
  892. ry = 0
  893. fow = world.maplist[player.pos[2]][player.on_map].check_fov(player.pos[0],player.pos[1],radius)
  894. for y in range(ymin,ymax):
  895. rx = 0
  896. for x in range(xmin,xmax):
  897. s.blit(screen.draw_tile(player.on_map,x,y,player.pos[2],fow[ry][rx]),(rx*32,ry*32))
  898. if x == player.pos[0] and y == player.pos[1]:
  899. s.blit(screen.draw_player(),(rx*32,ry*32))
  900. player_pos_help = (x,y)
  901. rx+=1
  902. ry+=1
  903. s.blit(self.render_hits(),(0,0))
  904. s.blit(screen.generate_light_effect(),(0,0))
  905. if photo == True:
  906. if low_res == False:
  907. photo_help = pygame.Surface((480,360))
  908. photo_help.blit(s,(0,0))
  909. s = photo_help
  910. else:
  911. photo_help = pygame.Surface((320,240))
  912. photo_help.blit(s,(0,0))
  913. s = photo_help
  914. return s
  915. if self.fire_mode == 0:
  916. 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:
  917. s.blit(gra_files.gdic['display'][0],(0,0)) #render gui
  918. else:
  919. s.blit(gra_files.gdic['display'][25],(0,0)) #render gui_warning
  920. elif self.fire_mode == 1:
  921. s.blit(gra_files.gdic['display'][10],(0,0))
  922. 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))
  923. else:
  924. 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:
  925. s.blit(gra_files.gdic['display'][0],(0,0)) #render gui
  926. else:
  927. s.blit(gra_files.gdic['display'][25],(0,0)) #render gui_warning
  928. 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))
  929. #render tool info
  930. #1. Axe
  931. if player.inventory.wearing['Axe'] == player.inventory.nothing:
  932. s.blit(gra_files.gdic['display'][44],(0,39))
  933. else:
  934. s.blit(gra_files.gdic['display'][46],(0,39))
  935. axestring = 'WEAPONS_' + player.inventory.wearing['Axe'].material + '_' + player.inventory.wearing['Axe'].classe
  936. s.blit(gra_files.gdic['char'][axestring],(0,39))
  937. s.blit(gra_files.gdic['display'][47],(0,39))
  938. axe_state = (15*player.inventory.wearing['Axe'].state)/100
  939. help_sur = pygame.Surface((axe_state,1))
  940. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  941. s.blit(help_sur,(10,67))
  942. #2. Pickaxe
  943. if player.inventory.wearing['Pickaxe'] == player.inventory.nothing:
  944. s.blit(gra_files.gdic['display'][45],(16,39))
  945. else:
  946. s.blit(gra_files.gdic['display'][46],(16,39))
  947. pickaxestring = 'WEAPONS_' + player.inventory.wearing['Pickaxe'].material + '_' + player.inventory.wearing['Pickaxe'].classe
  948. s.blit(gra_files.gdic['char'][pickaxestring],(16,39))
  949. s.blit(gra_files.gdic['display'][47],(16,39))
  950. pickaxe_state = (15*player.inventory.wearing['Pickaxe'].state)/100
  951. help_sur = pygame.Surface((pickaxe_state,1))
  952. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  953. s.blit(help_sur,(26,67))
  954. #3. Melee weapon
  955. if player.inventory.wearing['Hold(R)'] == player.inventory.nothing:
  956. s.blit(gra_files.gdic['display'][52],(32,39))
  957. else:
  958. s.blit(gra_files.gdic['display'][46],(32,39))
  959. melee_string = 'WEAPONS_' + player.inventory.wearing['Hold(R)'].material + '_' + player.inventory.wearing['Hold(R)'].classe
  960. if player.inventory.wearing['Hold(R)'].classe != 'spear':
  961. s.blit(gra_files.gdic['char'][melee_string],(32,39))
  962. else:
  963. h_sur = pygame.Surface((32,19))
  964. h_sur.fill((255,0,255))
  965. h_sur.blit(gra_files.gdic['char'][melee_string],(0,0))
  966. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  967. h_sur = h_sur.convert_alpha()
  968. s.blit(h_sur,(39,48))
  969. s.blit(gra_files.gdic['display'][47],(32,39))
  970. melee_state = (15*player.inventory.wearing['Hold(R)'].state)/100
  971. help_sur = pygame.Surface((melee_state,1))
  972. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  973. s.blit(help_sur,(42,67))
  974. #4. Magic weapon
  975. if player.inventory.wearing['Hold(L)'] == player.inventory.nothing:
  976. s.blit(gra_files.gdic['display'][53],(48,39))
  977. else:
  978. s.blit(gra_files.gdic['display'][46],(48,39))
  979. magic_string = 'WEAPONS_' + player.inventory.wearing['Hold(L)'].material + '_' + player.inventory.wearing['Hold(L)'].classe
  980. if player.inventory.wearing['Hold(L)'].classe != 'rune staff':
  981. s.blit(gra_files.gdic['char'][magic_string],(42,39))
  982. else:
  983. h_sur = pygame.Surface((32,19))
  984. h_sur.fill((255,0,255))
  985. h_sur.blit(gra_files.gdic['char'][magic_string],(0,0))
  986. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  987. h_sur = h_sur.convert_alpha()
  988. s.blit(h_sur,(42,48))
  989. s.blit(gra_files.gdic['display'][47],(48,39))
  990. magic_state = (15*player.inventory.wearing['Hold(L)'].state)/100
  991. help_sur = pygame.Surface((magic_state,1))
  992. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  993. s.blit(help_sur,(58,67))
  994. #5. Necklace
  995. if player.inventory.wearing['Neck'] == player.inventory.nothing:
  996. s.blit(gra_files.gdic['display'][40],(64,39))
  997. else:
  998. s.blit(gra_files.gdic['display'][46],(64,39))
  999. necklacestring = 'WEAPONS_' + player.inventory.wearing['Neck'].material + '_' + player.inventory.wearing['Neck'].classe
  1000. s.blit(gra_files.gdic['char'][necklacestring],(64,39))
  1001. s.blit(gra_files.gdic['display'][47],(64,39))
  1002. necklace_state = (15*player.inventory.wearing['Neck'].state)/100
  1003. help_sur = pygame.Surface((necklace_state,1))
  1004. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  1005. s.blit(help_sur,(74,67))
  1006. #6. Helmet
  1007. if player.inventory.wearing['Head'] == player.inventory.nothing:
  1008. s.blit(gra_files.gdic['display'][54],(0,54))
  1009. else:
  1010. s.blit(gra_files.gdic['display'][46],(0,54))
  1011. helmet_string = player.gender + '_' + player.inventory.wearing['Head'].material + '_' + player.inventory.wearing['Head'].classe
  1012. h_sur = pygame.Surface((32,32))
  1013. h_sur.fill((255,0,255))
  1014. h_sur.blit(gra_files.gdic['char'][helmet_string],(0,0))
  1015. pygame.draw.rect(h_sur,(255,0,255),(0,0,10,32),0)
  1016. pygame.draw.rect(h_sur,(255,0,255),(0,0,32,4),0)
  1017. pygame.draw.rect(h_sur,(255,0,255),(25,0,7,32),0)
  1018. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  1019. h_sur = h_sur.convert_alpha()
  1020. s.blit(h_sur,(0,65))
  1021. s.blit(gra_files.gdic['display'][47],(0,54))
  1022. helmet_state = (15*player.inventory.wearing['Head'].state)/100
  1023. help_sur = pygame.Surface((helmet_state,1))
  1024. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  1025. s.blit(help_sur,(10,82))
  1026. #7. Armor
  1027. if player.inventory.wearing['Body'] == player.inventory.nothing:
  1028. s.blit(gra_files.gdic['display'][55],(16,54))
  1029. else:
  1030. s.blit(gra_files.gdic['display'][46],(16,54))
  1031. armor_string = player.gender + '_' + player.inventory.wearing['Body'].material + '_' + player.inventory.wearing['Body'].classe
  1032. h_sur = pygame.Surface((32,32))
  1033. h_sur.fill((255,0,255))
  1034. h_sur.blit(gra_files.gdic['char'][armor_string],(0,0))
  1035. pygame.draw.rect(h_sur,(255,0,255),(0,0,10,32),0)
  1036. pygame.draw.rect(h_sur,(255,0,255),(25,0,7,32),0)
  1037. h_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  1038. h_sur = h_sur.convert_alpha()
  1039. s.blit(h_sur,(16,55))
  1040. s.blit(gra_files.gdic['display'][47],(16,54))
  1041. armor_state = (15*player.inventory.wearing['Body'].state)/100
  1042. help_sur = pygame.Surface((armor_state,1))
  1043. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  1044. s.blit(help_sur,(26,82))
  1045. #8. Cuisse
  1046. if player.inventory.wearing['Legs'] == player.inventory.nothing:
  1047. s.blit(gra_files.gdic['display'][56],(32,54))
  1048. else:
  1049. s.blit(gra_files.gdic['display'][46],(32,54))
  1050. cuisse_string = player.gender + '_' + player.inventory.wearing['Legs'].material + '_' + player.inventory.wearing['Legs'].classe
  1051. s.blit(gra_files.gdic['char'][cuisse_string],(32,50))
  1052. s.blit(gra_files.gdic['display'][47],(32,54))
  1053. cuisse_state = (15*player.inventory.wearing['Legs'].state)/100
  1054. help_sur = pygame.Surface((cuisse_state,1))
  1055. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  1056. s.blit(help_sur,(42,82))
  1057. #9. Shoes
  1058. if player.inventory.wearing['Feet'] == player.inventory.nothing:
  1059. s.blit(gra_files.gdic['display'][57],(48,54))
  1060. else:
  1061. s.blit(gra_files.gdic['display'][46],(48,54))
  1062. shoes_string = player.gender + '_' + player.inventory.wearing['Feet'].material + '_' + player.inventory.wearing['Feet'].classe
  1063. s.blit(gra_files.gdic['char'][shoes_string],(49,46))
  1064. s.blit(gra_files.gdic['display'][47],(48,54))
  1065. shoes_state = (15*player.inventory.wearing['Feet'].state)/100
  1066. help_sur = pygame.Surface((shoes_state,1))
  1067. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  1068. s.blit(help_sur,(58,82))
  1069. #10. Ring
  1070. if player.inventory.wearing['Hand'] == player.inventory.nothing:
  1071. s.blit(gra_files.gdic['display'][39],(64,54))
  1072. else:
  1073. s.blit(gra_files.gdic['display'][46],(64,54))
  1074. ring_string = 'WEAPONS_' + player.inventory.wearing['Hand'].material + '_' + player.inventory.wearing['Hand'].classe
  1075. s.blit(gra_files.gdic['char'][ring_string],(64,54))
  1076. s.blit(gra_files.gdic['display'][47],(64,54))
  1077. ring_state = (15*player.inventory.wearing['Hand'].state)/100
  1078. help_sur = pygame.Surface((ring_state,1))
  1079. help_sur.blit(gra_files.gdic['display'][48],(0,0))
  1080. s.blit(help_sur,(74,82))
  1081. #render icons
  1082. #1. Use
  1083. 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:
  1084. s.blit(gra_files.gdic['display'][32],(0,161))
  1085. s.blit(gra_files.gdic['display'][34],(0,161))
  1086. else:
  1087. s.blit(gra_files.gdic['display'][31],(0,161))
  1088. s.blit(gra_files.gdic['display'][33],(0,161))
  1089. use_string = '['+key_name['e']+']action'
  1090. use_image1 = self.font.render(use_string,1,(0,0,0))
  1091. use_image2 = self.font.render(use_string,1,(255,255,255))
  1092. s.blit(use_image1,(36,173))
  1093. s.blit(use_image2,(34,173))
  1094. #2. Fire
  1095. if player.inventory.wearing['Hold(L)'] == player.inventory.nothing or player.mp < 2:
  1096. s.blit(gra_files.gdic['display'][32],(0,129))
  1097. s.blit(gra_files.gdic['display'][36],(0,129))
  1098. else:
  1099. s.blit(gra_files.gdic['display'][31],(0,129))
  1100. s.blit(gra_files.gdic['display'][35],(0,129))
  1101. if self.fire_mode == False:
  1102. fire_string = '['+key_name['f']+']fire'
  1103. else:
  1104. fire_string = '['+key_name['x']+']cancel'
  1105. fire_image1 = self.font.render(fire_string,1,(0,0,0))
  1106. fire_image2 = self.font.render(fire_string,1,(255,255,255))
  1107. s.blit(fire_image1,(36,141))
  1108. s.blit(fire_image2,(34,141))
  1109. #4.Focus
  1110. s.blit(gra_files.gdic['display'][32],(0,97))#65
  1111. try:
  1112. focus_state = (32*player.mp/player.attribute.max_mp)
  1113. except:
  1114. focus_state = 1
  1115. help_sur = pygame.Surface((focus_state,32))
  1116. help_sur.fill((255,0,255))
  1117. help_sur.blit(gra_files.gdic['display'][31],(0,0))
  1118. help_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  1119. help_sur = help_sur.convert_alpha()
  1120. s.blit(help_sur,(0,97))
  1121. if player.mp < player.attribute.max_mp:
  1122. s.blit(gra_files.gdic['display'][38],(0,97))
  1123. focus_string = 'unfocused'
  1124. else:
  1125. s.blit(gra_files.gdic['display'][37],(0,97))
  1126. focus_string = 'focused'
  1127. focus_image1 = self.font.render(focus_string,1,(0,0,0))
  1128. focus_image2 = self.font.render(focus_string,1,(255,255,255))
  1129. s.blit(focus_image1,(36,109))#77
  1130. s.blit(focus_image2,(34,109))
  1131. # render messages
  1132. help_sur = pygame.Surface((480,60))
  1133. help_sur.fill((48,48,48))
  1134. help_sur.set_alpha(120)
  1135. mes_pos_y = 345
  1136. s.blit(help_sur,(0,300))
  1137. mlist = test
  1138. for c in range(0,5):
  1139. if c > 2:
  1140. color = (160,160,160)
  1141. elif c > 0:
  1142. color = (206,206,206)
  1143. else:
  1144. color = (255,255,255)
  1145. shadow_image = self.font.render(mlist[c],1,(0,0,0))
  1146. text_image = self.font.render(mlist[c],1,color)
  1147. s.blit(shadow_image,(2,mes_pos_y-(c*10)))
  1148. s.blit(text_image,(0,mes_pos_y-(c*10)))
  1149. #render lvl info
  1150. lvl_string = str(player.lvl)
  1151. if len(lvl_string) == 1:
  1152. lvl_string = '0'+lvl_string
  1153. lvl_image = self.font.render(lvl_string,1,(255,255,255))
  1154. s.blit(lvl_image,(153,48))
  1155. bar_length = 1 + ((319/100)*player.xp)
  1156. xp_surface = pygame.Surface((bar_length,64))
  1157. xp_surface.fill((255,0,255))
  1158. xp_surface.blit(gra_files.gdic['display'][19],(0,0))
  1159. xp_surface.set_colorkey((255,0,255),pygame.RLEACCEL)
  1160. xp_surface = xp_surface.convert_alpha()
  1161. s.blit(xp_surface,(0,0))
  1162. if game_options.mousepad == 1:
  1163. if self.fire_mode == 0:
  1164. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  1165. else:
  1166. s.blit(gra_files.gdic['display'][9],(480,0))
  1167. else:
  1168. s_help = pygame.Surface((160,360))
  1169. s_help.fill((48,48,48))
  1170. s.blit(s_help,(480,0))
  1171. #render buffs
  1172. buffs = player.buffs.sget()
  1173. if low_res == False:
  1174. posx = 388
  1175. posy = 10
  1176. else:
  1177. posx = 228
  1178. posy = 75
  1179. for i in buffs:
  1180. if i != ' ':
  1181. buff_shadow = self.font.render(i,1,(0,0,0))
  1182. s.blit(buff_shadow,(posx+2,posy))
  1183. buff_image = self.font.render(i,1,(200,200,200))
  1184. s.blit(buff_image,(posx,posy))
  1185. else:
  1186. None
  1187. posy += 20
  1188. #render date
  1189. date_string = time.sget()
  1190. posx = 235
  1191. posy = 10
  1192. date_image = self.font.render(date_string[0],1,(0,0,0))
  1193. s.blit(date_image,(posx,posy))
  1194. posy = 20
  1195. time_image = self.font.render(date_string[1],1,(0,0,0))
  1196. s.blit(time_image,(posx,posy))
  1197. #render player info
  1198. #lp
  1199. lp_string = str(player.lp) + '/' + str(player.attribute.max_lp)
  1200. posx = 13
  1201. posy = 12
  1202. if player.lp < 4:
  1203. lp_image = self.font.render(lp_string,1,(200,0,0))
  1204. else:
  1205. lp_image = self.font.render(lp_string,1,(0,0,0))
  1206. s.blit(lp_image,(posx,posy))
  1207. #hunger
  1208. hunger_percent = int((100 * player.attribute.hunger) / player.attribute.hunger_max)
  1209. hunger_string = str(hunger_percent) + '%'
  1210. posx = 75
  1211. posy = 12
  1212. if hunger_percent < 11:
  1213. hunger_image = self.font.render(hunger_string,1,(200,0,0))
  1214. else:
  1215. hunger_image = self.font.render(hunger_string,1,(0,0,0))
  1216. s.blit(hunger_image,(posx,posy))
  1217. #trirst
  1218. thirst_percent = int((100 * player.attribute.thirst) / player.attribute.thirst_max)
  1219. thirst_string = str(thirst_percent) + '%'
  1220. posx = 125
  1221. posy = 12
  1222. if thirst_percent < 11:
  1223. thirst_image = self.font.render(thirst_string,1,(200,0,0))
  1224. else:
  1225. thirst_image = self.font.render(thirst_string,1,(0,0,0))
  1226. s.blit(thirst_image,(posx,posy))
  1227. #tiredness
  1228. tiredness_percent = int((100 * player.attribute.tiredness) / player.attribute.tiredness_max)
  1229. tiredness_string = str(tiredness_percent) + '%'
  1230. posx = 180
  1231. posy = 12
  1232. if tiredness_percent < 11:
  1233. tiredness_image = self.font.render(tiredness_string,1,(200,0,0))
  1234. else:
  1235. tiredness_image = self.font.render(tiredness_string,1,(0,0,0))
  1236. s.blit(tiredness_image,(posx,posy))
  1237. if game_options.mousepad == 0:
  1238. s_help = pygame.Surface((640,360))
  1239. s_help.fill((48,48,48))
  1240. s_help.blit(s,(80,0))
  1241. s = s_help
  1242. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1243. self.screen.blit(s,(0,0))
  1244. if simulate == False:
  1245. pygame.display.flip()
  1246. else:
  1247. return s
  1248. if test[1] == '~*~':
  1249. return True
  1250. else:
  1251. return False
  1252. def render_load(self,num,progress=None):
  1253. s = pygame.Surface((640,360))
  1254. s.fill((48,48,48)) #paint it grey(to clear the screen)
  1255. if num == 0:
  1256. string = 'Looking for saved data... '
  1257. elif num == 1:
  1258. string = 'Loading world data...'
  1259. elif num == 2:
  1260. string = 'Nothing found...'
  1261. elif num == 3:
  1262. string = 'Generate overworld...'
  1263. elif num == 4:
  1264. string = 'Generate caves...'
  1265. elif num == 5:
  1266. string = 'Saving...'
  1267. elif num == 6:
  1268. string = 'Loading time data...'
  1269. elif num == 7:
  1270. string = 'Loading player data...'
  1271. elif num == 8:
  1272. string = 'Set time...'
  1273. elif num == 9:
  1274. string = 'Generate player...'
  1275. elif num == 10:
  1276. string = 'Making time related changes...'
  1277. elif num == 11:
  1278. string = 'Something has gone wrong...'
  1279. elif num == 12:
  1280. string = 'Zzzzzzzzzz'
  1281. elif num == 13:
  1282. string = 'Generate deus ex machina...'
  1283. elif num == 14:
  1284. string = 'Loading deus ex machina...'
  1285. elif num == 15:
  1286. string = 'Generate grot...'
  1287. elif num == 16:
  1288. string = 'Generate elfish fortress...'
  1289. elif num == 17:
  1290. string = 'Generate orcish mines...'
  1291. elif num == 18:
  1292. string = 'Generate desert...'
  1293. elif num == 19:
  1294. string = 'Initialize level...'
  1295. elif num == 20:
  1296. string = 'Please use run.py/run.exe'
  1297. ######add more here
  1298. if low_res == False:
  1299. posx = 150
  1300. posy = 200
  1301. else:
  1302. posx=50
  1303. posy= 100
  1304. image = self.font.render(string,1,(255,255,255))
  1305. s.blit(image,(posx,posy))
  1306. if progress != None:
  1307. s.blit(gra_files.gdic['display'][20],(posx-50,posy+20))
  1308. help_sur = pygame.Surface((((progress*320)/100),12))
  1309. help_sur.fill((255,0,255))
  1310. help_sur.blit(gra_files.gdic['display'][21],(0,0))
  1311. help_sur.set_colorkey((255,0,255),pygame.RLEACCEL)
  1312. help_sur = help_sur.convert_alpha()
  1313. s.blit(help_sur,(posx-50,posy+20))
  1314. if low_res == False:
  1315. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1316. self.screen.blit(s,(0,0))
  1317. pygame.display.flip()
  1318. def render_built(self,xmin,xmax,ymin,ymax,style):
  1319. start_pos_x = 256 #the center of the main map view
  1320. start_pos_y = 192
  1321. price = 0
  1322. bg = self.render(0, True)
  1323. s = pygame.Surface((640,360))
  1324. s.fill((255,0,255))
  1325. if style == 'Room':
  1326. build_total = True
  1327. for y in range (-ymin,ymax+1):
  1328. for x in range (-xmin,xmax+1):
  1329. 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:
  1330. built_here = 1
  1331. price += 2
  1332. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == True:
  1333. built_here = 2
  1334. price += 1
  1335. else:
  1336. built_here = 0
  1337. if world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+y][player.pos[0]+x] != 0:
  1338. built_here = 0
  1339. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].build_here == False:
  1340. built_here = 0
  1341. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].build_here == False:
  1342. if built_here == 1:
  1343. price -= 2
  1344. elif built_here == 2:
  1345. price -= 1
  1346. built_here = 0
  1347. if built_here == 0:
  1348. build_total = False
  1349. if build_total == False:
  1350. price = 0
  1351. for y in range (-ymin,ymax+1):
  1352. for x in range (-xmin,xmax+1):
  1353. if build_total != 0:
  1354. if x == xmax or x == -xmin or y == ymax or y == -ymin:
  1355. if x == xmax or x == -xmin:
  1356. if built_here == 1:
  1357. s.blit(gra_files.gdic['built'][1],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_true here
  1358. elif built_here == 2:
  1359. s.blit(gra_files.gdic['built'][6],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_over here
  1360. elif y == ymax or y == -ymin:
  1361. if built_here == 1:
  1362. s.blit(gra_files.gdic['built'][1],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_true here
  1363. elif built_here == 2:
  1364. s.blit(gra_files.gdic['built'][6],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_over here
  1365. else:
  1366. if built_here == 1:
  1367. s.blit(gra_files.gdic['built'][5],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_true here
  1368. elif built_here == 2:
  1369. s.blit(gra_files.gdic['built'][7],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_over
  1370. else:
  1371. if x == xmax or x == -xmin or y == ymax or y == -ymin:
  1372. if x == xmax or x == -xmin:
  1373. s.blit(gra_files.gdic['built'][0],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_false here
  1374. elif y == ymax or y == -ymin:
  1375. s.blit(gra_files.gdic['built'][0],(start_pos_x+(x*32),start_pos_y+(y*32))) #wall_false here
  1376. else:
  1377. s.blit(gra_files.gdic['built'][4],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_false here
  1378. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1379. # render mode name
  1380. name = '~Build Room~'
  1381. name_image = self.font.render(name,1,(255,255,255))
  1382. posx = 0
  1383. posy = 0
  1384. s.blit(name_image,(posx,posy))
  1385. # render wood needed
  1386. wood_need = int(price/2)
  1387. if wood_need == 0 and price != 0:
  1388. wood_need = 1
  1389. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1390. posx = 0
  1391. posy = 15
  1392. if wood_need <= player.inventory.materials.wood:
  1393. wood_image = self.font.render(wood_string,1,(255,255,255))
  1394. else:
  1395. wood_image = self.font.render(wood_string,1,(200,0,0))
  1396. s.blit(wood_image,(posx,posy))
  1397. # render stone needed
  1398. stone_need = int(price/2)
  1399. if stone_need == 0 and price != 0:
  1400. stone_need = 1
  1401. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1402. posx = 160
  1403. posy = 15
  1404. if stone_need <= player.inventory.materials.stone:
  1405. stone_image = self.font.render(stone_string,1,(255,255,255))
  1406. else:
  1407. stone_image = self.font.render(stone_string,1,(200,0,0))
  1408. s.blit(stone_image,(posx,posy))
  1409. # render info line
  1410. info_string_0 = '['+key_name['wasd']+']change Size'
  1411. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1412. posx = 0
  1413. posy = 30
  1414. info_image = self.font.render(info_string_0,1,(255,255,255))
  1415. s.blit(info_image,(posx,posy))
  1416. posx = 0
  1417. posy = 40
  1418. info_image = self.font.render(info_string_1,1,(255,255,255))
  1419. s.blit(info_image,(posx,posy))
  1420. elif style == 'Doorway':
  1421. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].move_group == 'solid' 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 == True and world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+ymin][player.pos[0]+xmin] == 0:
  1422. built_here = 1
  1423. price += 2
  1424. else:
  1425. built_here = 0
  1426. if world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+ymin][player.pos[0]+xmin] != 0:
  1427. built_here = False
  1428. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].build_here == False:
  1429. if built_here == 1:
  1430. price -= 2
  1431. elif built_here == 2:
  1432. price -= 1
  1433. built_here = 0
  1434. if built_here != 0:
  1435. if built_here == 1:
  1436. s.blit(gra_files.gdic['built'][3],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_true here
  1437. elif built_here == 2:
  1438. s.blit(gra_files.gdic['built'][8],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_over
  1439. else:
  1440. s.blit(gra_files.gdic['built'][2],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_false here
  1441. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1442. # render mode name
  1443. name = '~Built Doorway~'
  1444. name_image = self.font.render(name,1,(255,255,255))
  1445. posx = 0
  1446. posy = 0
  1447. s.blit(name_image,(posx,posy))
  1448. # render wood needed
  1449. wood_need = 0
  1450. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1451. posx = 0
  1452. posy = 15
  1453. if wood_need <= player.inventory.materials.wood:
  1454. wood_image = self.font.render(wood_string,1,(255,255,255))
  1455. else:
  1456. wood_image = self.font.render(wood_string,1,(200,0,0))
  1457. s.blit(wood_image,(posx,posy))
  1458. # render stone needed
  1459. stone_need = 0
  1460. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1461. posx = 160
  1462. posy = 15
  1463. if stone_need <= player.inventory.materials.stone:
  1464. stone_image = self.font.render(stone_string,1,(255,255,255))
  1465. else:
  1466. stone_image = self.font.render(stone_string,1,(200,0,0))
  1467. s.blit(stone_image,(posx,posy))
  1468. # render info line
  1469. info_string_0 = '['+key_name['wasd']+']change Position'
  1470. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1471. posx = 0
  1472. posy = 30
  1473. info_image = self.font.render(info_string_0,1,(255,255,255))
  1474. s.blit(info_image,(posx,posy))
  1475. posx = 0
  1476. posy = 40
  1477. info_image = self.font.render(info_string_1,1,(255,255,255))
  1478. s.blit(info_image,(posx,posy))
  1479. elif style == 'Door':
  1480. 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:
  1481. built_here = 1
  1482. price += 2
  1483. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].civilisation == True:
  1484. built_here = 2
  1485. price += 1
  1486. else:
  1487. built_here = 0
  1488. if world.maplist[player.pos[2]][player.on_map].npcs[player.pos[1]+ymin][player.pos[0]+xmin] != 0:
  1489. built_here = False
  1490. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+ymin][player.pos[0]+xmin].build_here == False:
  1491. if built_here == 1:
  1492. price -= 2
  1493. elif built_here == 2:
  1494. price -= 1
  1495. built_here = 0
  1496. if built_here != 0:
  1497. if built_here == 1:
  1498. s.blit(gra_files.gdic['built'][3],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_true here
  1499. elif built_here == 2:
  1500. s.blit(gra_files.gdic['built'][8],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_over
  1501. else:
  1502. s.blit(gra_files.gdic['built'][2],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #door_false here
  1503. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1504. # render mode name
  1505. name = '~Built Door~'
  1506. name_image = self.font.render(name,1,(255,255,255))
  1507. posx = 0
  1508. posy = 0
  1509. s.blit(name_image,(posx,posy))
  1510. # render wood needed
  1511. wood_need = price
  1512. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1513. posx = 0
  1514. posy = 15
  1515. if wood_need <= player.inventory.materials.wood:
  1516. wood_image = self.font.render(wood_string,1,(255,255,255))
  1517. else:
  1518. wood_image = self.font.render(wood_string,1,(200,0,0))
  1519. s.blit(wood_image,(posx,posy))
  1520. # render stone needed
  1521. stone_need = 0
  1522. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1523. posx = 160
  1524. posy = 15
  1525. if stone_need <= player.inventory.materials.stone:
  1526. stone_image = self.font.render(stone_string,1,(255,255,255))
  1527. else:
  1528. stone_image = self.font.render(stone_string,1,(200,0,0))
  1529. s.blit(stone_image,(posx,posy))
  1530. # render info line
  1531. info_string_0 = '['+key_name['wasd']+']change Position'
  1532. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1533. posx = 0
  1534. posy = 30
  1535. info_image = self.font.render(info_string_0,1,(255,255,255))
  1536. s.blit(info_image,(posx,posy))
  1537. posx = 0
  1538. posy = 40
  1539. info_image = self.font.render(info_string_1,1,(255,255,255))
  1540. s.blit(info_image,(posx,posy))
  1541. elif style == 'Stair up':
  1542. if player.pos[2] > 0:
  1543. 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:
  1544. build_here = 0
  1545. else:
  1546. build_here = 1
  1547. if build_here == 0:
  1548. s.blit(gra_files.gdic['built'][10],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up true icon here
  1549. else:
  1550. s.blit(gra_files.gdic['built'][11],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1551. else:
  1552. s.blit(gra_files.gdic['built'][11],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1553. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1554. # render mode name
  1555. name = '~Built stair up~'
  1556. name_image = self.font.render(name,1,(255,255,255))
  1557. posx = 0
  1558. posy = 0
  1559. s.blit(name_image,(posx,posy))
  1560. # render wood needed
  1561. wood_need = 10
  1562. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1563. posx = 0
  1564. posy = 15
  1565. if wood_need <= player.inventory.materials.wood:
  1566. wood_image = self.font.render(wood_string,1,(255,255,255))
  1567. else:
  1568. wood_image = self.font.render(wood_string,1,(200,0,0))
  1569. s.blit(wood_image,(posx,posy))
  1570. # render stone needed
  1571. stone_need = 40
  1572. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1573. posx = 160
  1574. posy = 15
  1575. if stone_need <= player.inventory.materials.stone:
  1576. stone_image = self.font.render(stone_string,1,(255,255,255))
  1577. else:
  1578. stone_image = self.font.render(stone_string,1,(200,0,0))
  1579. s.blit(stone_image,(posx,posy))
  1580. # render info line
  1581. info_string_0 = '['+key_name['wasd']+']change Position'
  1582. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1583. posx = 0
  1584. posy = 30
  1585. info_image = self.font.render(info_string_0,1,(255,255,255))
  1586. s.blit(info_image,(posx,posy))
  1587. posx = 0
  1588. posy = 40
  1589. info_image = self.font.render(info_string_1,1,(255,255,255))
  1590. s.blit(info_image,(posx,posy))
  1591. elif style == 'Stair down':
  1592. if player.pos[2] < 15:
  1593. 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:
  1594. build_here = 0
  1595. else:
  1596. build_here = 1
  1597. if build_here == 0:
  1598. s.blit(gra_files.gdic['built'][12],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up true icon here
  1599. else:
  1600. s.blit(gra_files.gdic['built'][13],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1601. else:
  1602. s.blit(gra_files.gdic['built'][12],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #stair up false icon here
  1603. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1604. # render mode name
  1605. name = '~Built stair down~'
  1606. name_image = self.font.render(name,1,(255,255,255))
  1607. posx = 0
  1608. posy = 0
  1609. s.blit(name_image,(posx,posy))
  1610. # render wood needed
  1611. wood_need = 10
  1612. wood_string = 'Wood: ' + str(wood_need) + '(' + str(player.inventory.materials.wood) + ')'
  1613. posx = 0
  1614. posy = 15
  1615. if wood_need <= player.inventory.materials.wood:
  1616. wood_image = self.font.render(wood_string,1,(255,255,255))
  1617. else:
  1618. wood_image = self.font.render(wood_string,1,(200,0,0))
  1619. s.blit(wood_image,(posx,posy))
  1620. # render stone needed
  1621. if player.pos[2] > 0:
  1622. stone_need = 40
  1623. else:
  1624. stone_need = 15
  1625. stone_string = 'Stone: ' + str(stone_need) + '(' + str(player.inventory.materials.stone) + ')'
  1626. posx = 160
  1627. posy = 15
  1628. if stone_need <= player.inventory.materials.stone:
  1629. stone_image = self.font.render(stone_string,1,(255,255,255))
  1630. else:
  1631. stone_image = self.font.render(stone_string,1,(200,0,0))
  1632. s.blit(stone_image,(posx,posy))
  1633. # render info line
  1634. info_string_0 = '['+key_name['wasd']+']change Position'
  1635. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1636. posx = 0
  1637. posy = 30
  1638. info_image = self.font.render(info_string_0,1,(255,255,255))
  1639. s.blit(info_image,(posx,posy))
  1640. posx = 0
  1641. posy = 40
  1642. info_image = self.font.render(info_string_1,1,(255,255,255))
  1643. s.blit(info_image,(posx,posy))
  1644. elif style == 'Agriculture':
  1645. for y in range (-ymin,ymax+1):
  1646. for x in range (-xmin,xmax+1):
  1647. 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:
  1648. built_here = 1
  1649. price += 1
  1650. elif world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].civilisation == True:
  1651. built_here = 2
  1652. price += 1
  1653. else:
  1654. built_here = 0
  1655. if world.maplist[player.pos[2]][player.on_map].tilemap[player.pos[1]+y][player.pos[0]+x].build_here == False:
  1656. if built_here == 1:
  1657. price -= 2
  1658. elif built_here == 2:
  1659. price -= 1
  1660. built_here = 0
  1661. if built_here != 0:
  1662. if built_here == 1:
  1663. s.blit(gra_files.gdic['built'][15],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_true here
  1664. elif built_here == 2:
  1665. s.blit(gra_files.gdic['built'][16],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_over
  1666. else:
  1667. s.blit(gra_files.gdic['built'][14],(start_pos_x+(x*32),start_pos_y+(y*32))) #floor_false here
  1668. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1669. # render mode name
  1670. name = '~Build Agriculture~'
  1671. name_image = self.font.render(name,1,(255,255,255))
  1672. posx = 0
  1673. posy = 0
  1674. s.blit(name_image,(posx,posy))
  1675. # render seeds needed
  1676. seed_need = price
  1677. if seed_need == 0:
  1678. seed_need = 1
  1679. wood_need = seed_need
  1680. stone_need = 0
  1681. wood_string = 'Seeds: ' + str(seed_need) + '(' + str(player.inventory.materials.seeds) + ')'
  1682. posx = 120
  1683. posy = 15
  1684. if wood_need <= player.inventory.materials.seeds:
  1685. wood_image = self.font.render(wood_string,1,(255,255,255))
  1686. else:
  1687. wood_image = self.font.render(wood_string,1,(200,0,0))
  1688. s.blit(wood_image,(posx,posy))
  1689. # render info line
  1690. info_string_0 = '['+key_name['wasd']+']change Size'
  1691. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']BUILT!'
  1692. posx = 0
  1693. posy = 30
  1694. info_image = self.font.render(info_string_0,1,(255,255,255))
  1695. s.blit(info_image,(posx,posy))
  1696. posx = 0
  1697. posy = 40
  1698. info_image = self.font.render(info_string_1,1,(255,255,255))
  1699. s.blit(info_image,(posx,posy))
  1700. elif style == 'remove':
  1701. shape = world.maplist[player.pos[2]][player.on_map].float_building_shape(player.pos[0]+xmin,player.pos[1]+ymin)
  1702. for y in range(player.pos[1]-8,player.pos[1]+8):
  1703. for x in range(player.pos[0]-6,player.pos[0]+6):
  1704. rx = x-player.pos[0]
  1705. ry = y-player.pos[1]
  1706. if shape[y][x] == 1:
  1707. s.blit(gra_files.gdic['built'][9],(start_pos_x+(rx*32),start_pos_y+(ry*32))) #remove icon here
  1708. s.blit(gra_files.gdic['built'][19],(start_pos_x+(xmin*32),start_pos_y+(ymin*32))) #remove icon here
  1709. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1710. # render mode name
  1711. name = '~Remove~'
  1712. name_image = self.font.render(name,1,(255,255,255))
  1713. posx = 0
  1714. posy = 0
  1715. s.blit(name_image,(posx,posy))
  1716. # render ---
  1717. wood_string = '---'
  1718. posx = 120
  1719. posy = 15
  1720. wood_image = self.font.render(wood_string,1,(255,255,255))
  1721. s.blit(wood_image,(posx,posy))
  1722. # render info line
  1723. info_string_0 = '['+key_name['wasd']+']change Size'
  1724. info_string_1 = '['+key_name['x']+']Leave ['+key_name['e']+']REMOVE!'
  1725. posx = 0
  1726. posy = 30
  1727. info_image = self.font.render(info_string_0,1,(255,255,255))
  1728. s.blit(info_image,(posx,posy))
  1729. posx = 0
  1730. posy = 40
  1731. info_image = self.font.render(info_string_1,1,(255,255,255))
  1732. s.blit(info_image,(posx,posy))
  1733. wood_need = 0
  1734. stone_need = 0
  1735. if game_options.mousepad == 0:
  1736. s_help = pygame.Surface((640,360))
  1737. s_help.fill((255,0,255))
  1738. s_help.blit(s,(80,0))
  1739. s = s_help
  1740. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  1741. s = s.convert_alpha()
  1742. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1743. bg.blit(s,(0,0))
  1744. self.screen.blit(bg,(0,0))
  1745. pygame.display.flip()
  1746. return (wood_need,stone_need)
  1747. def render_place(self,tile,use_name):
  1748. global player
  1749. x = player.pos[0]
  1750. y = player.pos[1]
  1751. start_pos_x = 256 #the center of the main map view
  1752. start_pos_y = 192
  1753. run = True
  1754. while run:
  1755. lootable = False
  1756. placeable = True
  1757. plantable = False
  1758. #1: check if lootable
  1759. for i in range(9,14):
  1760. if tile.techID == tl.tlist['functional'][i].techID:#this is a workbench
  1761. lootable = True
  1762. if tile.use_group == 'gather':
  1763. lootable = True
  1764. #2: check if placeable
  1765. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].move_group != 'soil' and world.maplist[player.pos[2]][player.on_map].tilemap[y][x].move_group != 'dry_entrance':
  1766. placeable = False
  1767. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].replace != None:
  1768. placeable = False
  1769. if world.maplist[player.pos[2]][player.on_map].npcs[y][x] != 0:
  1770. placeable = False
  1771. if tile.move_group != 'soil':
  1772. if x == player.pos[0] and y == player.pos[1]:
  1773. placeable = False
  1774. if use_name == 'place(indoor)':
  1775. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].indoor == False:
  1776. placeable = False
  1777. if use_name == 'place(outdoor)':
  1778. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].indoor == True:
  1779. placeable = False
  1780. #2.5: check if plantable
  1781. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].can_grown == True:
  1782. plantable = True
  1783. if use_name != 'plant':
  1784. plantable = True #if the object to be placeced no plant plantable is always true
  1785. #3: render
  1786. self.render(0,True)
  1787. s = pygame.Surface((640,360))
  1788. s.fill((255,0,255))
  1789. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1790. string1 ='~'+tile.name+'~'
  1791. string1_image = self.font.render(string1,1,(255,255,255))
  1792. s.blit(string1_image,(0,0))
  1793. if lootable == False:
  1794. warning = self.font.render('Can\'t be moved later!',1,(200,0,0))
  1795. s.blit(warning,(0,20))
  1796. string2 = '['+key_name['wasd']+']Move ['+key_name['e']+']Place! ['+key_name['x']+']Leave'
  1797. string2_image = self.font.render(string2,1,(255,255,255))
  1798. s.blit(string2_image,(0,40))
  1799. xx = x - player.pos[0]
  1800. yy = y - player.pos[1]
  1801. if placeable == True and plantable == True:
  1802. s.blit(gra_files.gdic['built'][18],(start_pos_x+(xx*32),start_pos_y+(yy*32)))
  1803. else:
  1804. s.blit(gra_files.gdic['built'][17],(start_pos_x+(xx*32),start_pos_y+(yy*32)))
  1805. if game_options.mousepad == 0:
  1806. s_help = pygame.Surface((640,360))
  1807. s_help.fill((255,0,255))
  1808. s_help.blit(s,(80,0))
  1809. s = s_help
  1810. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  1811. s = s.convert_alpha()
  1812. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1813. self.screen.blit(s,(0,0))
  1814. pygame.display.flip()
  1815. #4: user input
  1816. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  1817. if ui == 'exit':
  1818. global master_loop
  1819. global playing
  1820. global exitgame
  1821. exitgame = True
  1822. try:
  1823. save_options(game_options,options_path,os.sep)
  1824. screen.render_load(5)
  1825. save(world,player,time,gods,save_path,os.sep)
  1826. screen.save_tmp_png()
  1827. del player
  1828. except:
  1829. None
  1830. master_loop = False
  1831. playing = False
  1832. run = False
  1833. return('exit')
  1834. if ui == 'w':
  1835. if y > 0 and y > player.pos[1]-2:
  1836. y -= 1
  1837. elif ui == 's':
  1838. if y < max_map_size-1 and y < player.pos[1]+2:
  1839. y += 1
  1840. elif ui == 'a':
  1841. if x > 0 and x > player.pos[0]-2:
  1842. x -= 1
  1843. elif ui == 'd':
  1844. if x < max_map_size-1 and x < player.pos[0]+2:
  1845. x += 1
  1846. elif ui == 'e':
  1847. if placeable == True and plantable == True:
  1848. replace = world.maplist[player.pos[2]][player.on_map].tilemap[y][x]
  1849. world.maplist[player.pos[2]][player.on_map].tilemap[y][x] = deepcopy(tile)
  1850. world.maplist[player.pos[2]][player.on_map].tilemap[y][x].replace = deepcopy(replace)
  1851. world.maplist[player.pos[2]][player.on_map].tilemap[y][x].civilisation = True
  1852. if world.maplist[player.pos[2]][player.on_map].tilemap[y][x].techID == tl.tlist['misc'][0].techID or world.maplist[player.pos[2]][player.on_map].tilemap[y][x].techID == tl.tlist['global_caves'][4].techID:
  1853. world.maplist[player.pos[2]][player.on_map].tilemap[y][x].replace = None
  1854. world.maplist[player.pos[2]][player.on_map].tilemap[y][x].civilisation = False
  1855. if use_name == 'plant':
  1856. mes = 'You planted a '+tile.name+'.'
  1857. else:
  1858. mes = 'You placed a '+tile.name+'.'
  1859. message.add(mes)
  1860. return(x,y)
  1861. elif ui == 'x':
  1862. run = False
  1863. return False
  1864. return False#only to be sure
  1865. def render_textbox_open(self):
  1866. clock = pygame.time.Clock()
  1867. for i in range(-64,1,6):
  1868. s = pygame.Surface((320,240))
  1869. s.fill((255,0,255))
  1870. s.blit(gra_files.gdic['display'][5],(0,i)) #render gui_transparent over gui
  1871. if game_options.mousepad == 0:
  1872. s_help = pygame.Surface((640,360))
  1873. s_help.fill((255,0,255))
  1874. s_help.blit(s,(80,0))
  1875. s = s_help
  1876. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  1877. s = s.convert_alpha()
  1878. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1879. self.screen.blit(s,(0,0))
  1880. pygame.display.flip()
  1881. clock.tick(256)
  1882. def render_request(self,line1,line2,line3,first_call=True):
  1883. #this function just renders 3 lines of text in the textbox
  1884. self.render(0, True)
  1885. if first_call == True:
  1886. self.render_textbox_open()
  1887. s = pygame.Surface((640,380))
  1888. s.fill((255,0,255))
  1889. s.blit(gra_files.gdic['display'][5],(0,0)) #render gui_transparent over gui
  1890. # render lines
  1891. line1_image = self.font.render(line1,1,(255,255,255))
  1892. posx = 0
  1893. posy = 0
  1894. s.blit(line1_image,(posx,posy))
  1895. line2_image = self.font.render(line2,1,(255,255,255))
  1896. posx = 0
  1897. posy = 20
  1898. s.blit(line2_image,(posx,posy))
  1899. line3_image = self.font.render(line3,1,(255,255,255))
  1900. posx = 0
  1901. posy = 40
  1902. s.blit(line3_image,(posx,posy))
  1903. if game_options.mousepad == 0:
  1904. s_help = pygame.Surface((640,360))
  1905. s_help.fill((255,0,255))
  1906. s_help.blit(s,(80,0))
  1907. s = s_help
  1908. s.set_colorkey((255,0,255),pygame.RLEACCEL)
  1909. s = s.convert_alpha()
  1910. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1911. self.screen.blit(s,(0,0))
  1912. pygame.display.flip()
  1913. def render_map(self,level=0):
  1914. run = True
  1915. while run:
  1916. m = pygame.Surface((max_map_size,max_map_size))
  1917. for y in range(0,max_map_size):
  1918. for x in range(0,max_map_size):
  1919. try:
  1920. t_col = world.maplist[level][player.on_map].tilemap[y][x].tile_color
  1921. except:
  1922. level = 0
  1923. t_col = world.maplist[level][player.on_map].tilemap[y][x].tile_color
  1924. 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
  1925. m.blit(gra_files.gdic['tile1']['white'],(x,y))
  1926. else:
  1927. if world.maplist[level][player.on_map].known[y][x] == 1:
  1928. m.blit(gra_files.gdic['tile1'][t_col],(x,y))
  1929. elif world.maplist[level][player.on_map].known[y][x] == 0:
  1930. m.blit(gra_files.gdic['tile1']['black'],(x,y))
  1931. else:
  1932. m.blit(gra_files.gdic['tile1']['black'],(x,y))
  1933. m = pygame.transform.scale(m,(270,270))
  1934. s = pygame.Surface((640,360))
  1935. bg = pygame.Surface((480,360))
  1936. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  1937. s.blit(bg,(0,0))
  1938. if game_options.mousepad == 1:
  1939. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  1940. else:
  1941. s_help = pygame.Surface((160,360))
  1942. s_help.fill((48,48,48))
  1943. s.blit(s_help,(480,0))
  1944. text = '~Map~ [Press['+key_name['x']+'] to leave'
  1945. text_image = screen.font.render(text,1,(255,255,255))
  1946. s.blit(text_image,(5,2))#menue title
  1947. lvl_string = 'Level ' + str(level)
  1948. text_image = screen.font.render(lvl_string,1,(0,0,0))
  1949. if low_res == False:
  1950. s.blit(text_image,(300,70))
  1951. else:
  1952. s.blit(text_image,(190,50))
  1953. s.blit(m,(25,55))
  1954. if game_options.mousepad == 0:
  1955. s_help = pygame.Surface((640,360))
  1956. s_help.fill((48,48,48))
  1957. s_help.blit(s,(80,0))
  1958. s = s_help
  1959. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  1960. self.screen.blit(s,(0,0))
  1961. pygame.display.flip()
  1962. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  1963. if ui == 'exit':
  1964. global master_loop
  1965. global playing
  1966. global exitgame
  1967. exitgame = True
  1968. screen.render_load(5)
  1969. save(world,player,time,gods,save_path,os.sep)
  1970. screen.save_tmp_png()
  1971. master_loop = False
  1972. playing = False
  1973. run = False
  1974. return('exit')
  1975. if ui == 'x':
  1976. run = False
  1977. def render_credits(self):
  1978. global master_loop
  1979. run = True
  1980. while run:
  1981. s = pygame.Surface((640,360))
  1982. bg = pygame.Surface((480,360))
  1983. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  1984. s.blit(bg,(0,0))
  1985. if game_options.mousepad == 1 and low_res == False:
  1986. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  1987. else:
  1988. s_help = pygame.Surface((160,360))
  1989. s_help.fill((48,48,48))
  1990. s.blit(s_help,(480,0))
  1991. text = '~Credits~ [Press ['+key_name['x']+'] to leave]'
  1992. text_image = screen.font.render(text,1,(255,255,255))
  1993. s.blit(text_image,(5,2))#menue title
  1994. 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')
  1995. for i in range (0,len(credit_items)):
  1996. text_image = screen.font.render(credit_items[i],1,(0,0,0))
  1997. s.blit(text_image,(21,120+i*25))#blit credit_items
  1998. if game_options.mousepad == 0:
  1999. s_help = pygame.Surface((640,360))
  2000. s_help.fill((48,48,48))
  2001. s_help.blit(s,(80,0))
  2002. s = s_help
  2003. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  2004. self.screen.blit(s,(0,0))
  2005. pygame.display.flip()
  2006. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2007. if ui == 'exit':
  2008. master_loop = False
  2009. run = False
  2010. return('exit')
  2011. if ui == 'x':
  2012. run = False
  2013. def render_status(self):
  2014. player_attribute = ('Strength: '+str(player.attribute.p_strength),
  2015. 'Skill: '+str(player.attribute.p_defense),
  2016. 'Power: '+str(player.attribute.m_strength),
  2017. 'Will: '+str(player.attribute.m_defense),
  2018. 'Health: '+str(player.lp)+'/'+str(player.attribute.max_lp),
  2019. '--> SKILLS')
  2020. attribute_info = ('Strength','Skill','Power','Will','Health')
  2021. if player.skill.woodcutting == 'Novice':
  2022. woodcutting_next_lvl = '200'
  2023. else:
  2024. woodcutting_next_lvl = '1000'
  2025. if player.skill.mining == 'Novice':
  2026. mining_next_lvl = '200'
  2027. else:
  2028. mining_next_lvl = '1000'
  2029. if len(player.buffs.buff_list) > 0:
  2030. next_str = 'BUFFS -->'
  2031. else:
  2032. next_str = '<-- ATTRIBUTES'
  2033. player_skills = ('Weapon Crafting: '+player.skill.weapon_crafting,
  2034. 'Metallurgy: '+player.skill.metallurgy,
  2035. 'Alchemy: '+player.skill.alchemy,
  2036. 'Woodcutting: '+player.skill.woodcutting+' ('+str(player.skill.woodcutting_progress)+'/'+woodcutting_next_lvl+')',
  2037. 'Mining: '+player.skill.mining+' ('+str(player.skill.mining_progress)+'/'+mining_next_lvl+')',
  2038. next_str)
  2039. skill_info = ('Weapon Crafting','Metallurgy','Alchemy','Woodcutting','Mining')
  2040. buff_strings = list(player.buffs.buff_list.keys())
  2041. player_buffs = []
  2042. if len(player.buffs.buff_list) > 0:
  2043. for i in buff_strings:
  2044. player_buffs.append(i.upper())
  2045. player_buffs.append('<-- ATTRIBUTES')
  2046. run = True
  2047. while run:
  2048. c = screen.get_choice('Attributes',player_attribute,True)
  2049. if c == 'Break':
  2050. run = False
  2051. return False
  2052. if c < 5:
  2053. screen.render_text(texts[attribute_info[c]])
  2054. elif c == 5:
  2055. run2 = True
  2056. while run2:
  2057. d = screen.get_choice('Skills',player_skills,True)
  2058. if d == 'Break':
  2059. run = False
  2060. run2 = False
  2061. return False
  2062. if d < 5:
  2063. screen.render_text(texts[skill_info[d]])
  2064. elif d == 5:
  2065. if len(player.buffs.buff_list) > 0:
  2066. run3 = True
  2067. while run3:
  2068. d = screen.get_choice('Buffs',player_buffs,True)
  2069. if d == 'Break':
  2070. run = False
  2071. run2 = False
  2072. run3 = False
  2073. return False
  2074. if d < len(player.buffs.buff_list):
  2075. try:
  2076. screen.render_text(texts[buff_strings[d]])
  2077. except:
  2078. screen.render_text(texts['unknown buff'])
  2079. elif d == len(player.buffs.buff_list):
  2080. run2 = False
  2081. run3 = False
  2082. else:
  2083. run2 = False
  2084. def render_text(self,text,replace_keys=True,more_txt=False,simulation= False):
  2085. run = True
  2086. while run:
  2087. if low_res == False:
  2088. s = pygame.Surface((640,360))
  2089. else:
  2090. s = pygame.Surface((320,240))
  2091. bg = pygame.Surface((480,360))
  2092. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2093. if low_res == True:
  2094. bg = pygame.transform.scale(bg,(320,240))
  2095. s.blit(bg,(0,0))
  2096. if game_options.mousepad == 1 and low_res == False:
  2097. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2098. else:
  2099. s_help = pygame.Surface((160,360))
  2100. s_help.fill((48,48,48))
  2101. s.blit(s_help,(480,0))
  2102. if simulation == False:
  2103. if more_txt == False:
  2104. top_text = '[Press ['+key_name['x']+'] to leave]'
  2105. else:
  2106. top_text = '[Press ['+key_name['e']+'] for next page]'
  2107. text_image = screen.font.render(top_text,1,(255,255,255))
  2108. s.blit(text_image,(5,2))#menue title
  2109. for i in range (0,len(text)):
  2110. text_image = screen.font.render(text[i],1,(0,0,0))
  2111. if low_res == False:
  2112. s.blit(text_image,(60,80+i*25))#blit credit_items
  2113. else:
  2114. s.blit(text_image,(21,36+i*20))#blit credit_items
  2115. if simulation == True:
  2116. return s
  2117. if game_options.mousepad == 0 and low_res == False:
  2118. s_help = pygame.Surface((640,360))
  2119. s_help.fill((48,48,48))
  2120. s_help.blit(s,(80,0))
  2121. s = s_help
  2122. if low_res == False:
  2123. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  2124. self.screen.blit(s,(0,0))
  2125. pygame.display.flip()
  2126. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2127. if ui == 'exit':
  2128. global master_loop
  2129. global playing
  2130. global exitgame
  2131. exitgame = True
  2132. try:
  2133. screen.render_load(5)
  2134. save(world,player,time,gods,save_path,os.sep)
  2135. screen.save_tmp_png()
  2136. del player
  2137. except:
  2138. None
  2139. master_loop = False
  2140. playing = False
  2141. run = False
  2142. return('exit')
  2143. if ui == 'x':
  2144. run = False
  2145. elif ui == 'e' and more_txt == True:
  2146. run = False
  2147. def render_multi_text(self,texts):
  2148. run = True
  2149. page = 0
  2150. total_pages = len(texts)
  2151. while run:
  2152. s = self.render_text(texts[page],simulation=True)
  2153. page_txt = 'Page '+str(page+1)+ ' of '+str(total_pages)+' ['+key_name['x']+'] - leave'
  2154. page_image = screen.font.render(page_txt,1,(255,255,255))
  2155. s.blit(page_image,(5,2))#menue title
  2156. if game_options.mousepad == 0 and low_res == False:
  2157. s_help = pygame.Surface((640,360))
  2158. s_help.fill((48,48,48))
  2159. s_help.blit(s,(80,0))
  2160. s = s_help
  2161. if low_res == False:
  2162. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  2163. self.screen.blit(s,(0,0))
  2164. pygame.display.flip()
  2165. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2166. if ui == 's' or ui == 'd':
  2167. page += 1
  2168. if page > total_pages-1:
  2169. page = 0
  2170. elif ui == 'w' or ui == 'a':
  2171. page -= 1
  2172. if page < 0:
  2173. page = total_pages-1
  2174. elif ui == 'x':
  2175. run = False
  2176. def render_options(self):
  2177. run = True
  2178. num = 0
  2179. options_path = save_path
  2180. for c in range(0,5):
  2181. options_path = options_path.replace(os.sep + 'World' + str(c),'')
  2182. while run:
  2183. if game_options.screenmode == 2:
  2184. winm = 'Screenmode: Fullscreen'
  2185. elif game_options.screenmode == 1:
  2186. winm = 'Screenmode: Windowed(1280X720)'
  2187. else:
  2188. winm = 'Screenmode: Windowed(640X360)'
  2189. if game_options.bgmmode != 0:
  2190. audiom = 'BGM: ' + str(int(game_options.bgmmode*100)) + '%'
  2191. else:
  2192. audiom = 'BGM: OFF'
  2193. if game_options.sfxmode != 0:
  2194. sfxm = 'SFX: ' +str(int(game_options.sfxmode*100)) + '%'
  2195. else:
  2196. sfxm = 'SFX: OFF'
  2197. if game_options.turnmode == 1:
  2198. turnm = 'Gamemode: Semi-Realtime'
  2199. else:
  2200. turnm = 'Gamemode: Turnbased'
  2201. if game_options.mousepad == 1:
  2202. mousem = 'Use Mouse: yes'
  2203. else:
  2204. mousem = 'Use Mouse: no'
  2205. if game_options.check_version == 1:
  2206. versm = 'Check Version: yes'
  2207. else:
  2208. versm = 'Check Version: no'
  2209. s = pygame.Surface((640,360))
  2210. bg = pygame.Surface((480,360))
  2211. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2212. if low_res == True:
  2213. bg = pygame.transform.scale(bg,(320,240))
  2214. s.blit(bg,(0,0))
  2215. text = '~Options~ [Press ['+key_name['e']+'] to choose]'
  2216. text_image = screen.font.render(text,1,(255,255,255))
  2217. s.blit(text_image,(5,2))#menue title
  2218. menu_items = (winm,audiom,sfxm,turnm,mousem,versm,'Done')
  2219. for i in range (0,len(menu_items)):
  2220. text_image = screen.font.render(menu_items[i],1,(0,0,0))
  2221. s.blit(text_image,(21,120+i*25))#blit menu_items
  2222. s.blit(gra_files.gdic['display'][4],(0,112+num*25))#blit marker
  2223. if game_options.mousepad == 1:
  2224. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2225. else:
  2226. s_help = pygame.Surface((160,360))
  2227. s_help.fill((48,48,48))
  2228. s.blit(s_help,(480,0))
  2229. if game_options.mousepad == 0:
  2230. s_help = pygame.Surface((640,360))
  2231. s_help.fill((48,48,48))
  2232. s_help.blit(s,(80,0))
  2233. s = s_help
  2234. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  2235. self.screen.blit(s,(0,0))
  2236. pygame.display.flip()
  2237. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2238. if ui == 'exit':
  2239. global master_loop
  2240. global playing
  2241. global exitgame
  2242. global player
  2243. exitgame = True
  2244. try:
  2245. save_options(game_options,options_path,os.sep)
  2246. screen.render_load(5)
  2247. save(world,player,time,gods,save_path,os.sep)
  2248. screen.save_tmp_png()
  2249. del player
  2250. except:
  2251. None
  2252. master_loop = False
  2253. playing = False
  2254. run = False
  2255. return('exit')
  2256. if ui == 'w':
  2257. num -= 1
  2258. if num < 0:
  2259. num = len(menu_items)-1
  2260. if ui == 's':
  2261. num += 1
  2262. if num >= len(menu_items):
  2263. num = 0
  2264. if ui == 'x':
  2265. run = False
  2266. if ui == 'e':
  2267. if num == 0:
  2268. screen.re_init()
  2269. pygame.display.flip()
  2270. save_options(game_options,options_path,os.sep)
  2271. if num == 1:
  2272. ui = screen.get_choice('BGM Loudness',('OFF','25%','50%','75%','100%'),True)
  2273. if ui == 0:
  2274. game_options.bgmmode = 0
  2275. pygame.mixer.music.pause()
  2276. elif ui == 1:
  2277. game_options.bgmmode = 0.25
  2278. pygame.mixer.music.unpause()
  2279. bgm.check_for_song(force_play=True)
  2280. elif ui == 2:
  2281. game_options.bgmmode = 0.5
  2282. pygame.mixer.music.unpause()
  2283. bgm.check_for_song(force_play=True)
  2284. elif ui == 3:
  2285. game_options.bgmmode = 0.75
  2286. pygame.mixer.music.unpause()
  2287. bgm.check_for_song(force_play=True)
  2288. elif ui == 4:
  2289. game_options.bgmmode = 1
  2290. pygame.mixer.music.unpause()
  2291. bgm.check_for_song(force_play=True)
  2292. save_options(game_options,options_path,os.sep)
  2293. if num == 2:
  2294. ui = screen.get_choice('SFX Loudness',('OFF','25%','50%','75%','100%'),True)
  2295. if ui == 0:
  2296. game_options.sfxmode = 0
  2297. elif ui == 1:
  2298. game_options.sfxmode = 0.25
  2299. sfx.set_loudness()
  2300. elif ui == 2:
  2301. game_options.sfxmode = 0.5
  2302. sfx.set_loudness()
  2303. elif ui == 3:
  2304. game_options.sfxmode = 0.75
  2305. sfx.set_loudness()
  2306. elif ui == 4:
  2307. game_options.sfxmode = 1
  2308. sfx.set_loudness()
  2309. save_options(game_options,options_path,os.sep)
  2310. if num == 3:
  2311. if game_options.turnmode == 1:
  2312. game_options.turnmode = 0
  2313. else:
  2314. game_options.turnmode = 1
  2315. save_options(game_options,options_path,os.sep)
  2316. if num == 4 and low_res == False:
  2317. if game_options.mousepad == 1:
  2318. game_options.mousepad = 0
  2319. else:
  2320. game_options.mousepad = 1
  2321. pygame.mouse.set_visible(game_options.mousepad)
  2322. save_options(game_options,options_path,os.sep)
  2323. if num == 5:
  2324. if game_options.check_version == 1:
  2325. game_options.check_version = 0
  2326. else:
  2327. game_options.check_version = 1
  2328. save_options(game_options,options_path,os.sep)
  2329. if num == 6:
  2330. save_options(game_options,options_path,os.sep)
  2331. run = False
  2332. def render_brake(self,simulate= False):
  2333. run = True
  2334. num = 0
  2335. global exitgame
  2336. global playing
  2337. global player
  2338. while run:
  2339. if low_res == False:
  2340. s = pygame.Surface((640,360))
  2341. else:
  2342. s = pygame.Surface((320,240))
  2343. bg = pygame.Surface((480,360))
  2344. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2345. if low_res == True:
  2346. bg = pygame.transform.scale(bg,(320,240))
  2347. s.blit(bg,(0,0))
  2348. text = '~Game Paused~ [Press ['+key_name['e']+'] to choose]'
  2349. text_image = screen.font.render(text,1,(255,255,255))
  2350. s.blit(text_image,(5,2))#menue title
  2351. menu_items = ('Resume','Status','Message History','Save and Exit', 'Options',)
  2352. for i in range (0,len(menu_items)):
  2353. text_image = screen.font.render(menu_items[i],1,(0,0,0))
  2354. if low_res == False:
  2355. s.blit(text_image,(21,120+i*25))#blit menu_items
  2356. else:
  2357. s.blit(text_image,(21,46+i*25))#blit menu_items
  2358. if low_res == False:
  2359. s.blit(gra_files.gdic['display'][4],(0,112+num*25))#blit marker
  2360. else:
  2361. s.blit(gra_files.gdic['display'][4],(0,38+num*25))#blit marker
  2362. if game_options.mousepad == 1 and low_res != True:
  2363. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2364. else:
  2365. s_help = pygame.Surface((160,360))
  2366. s_help.fill((48,48,48))
  2367. s.blit(s_help,(480,0))
  2368. if game_options.mousepad == 0 and low_res == False:
  2369. s_help = pygame.Surface((640,360))
  2370. s_help.fill((48,48,48))
  2371. s_help.blit(s,(80,0))
  2372. s = s_help
  2373. if low_res == False:
  2374. s = pygame.transform.scale(s,(self.displayx,self.displayy))
  2375. if simulate == True:
  2376. return s
  2377. self.screen.blit(s,(0,0))
  2378. pygame.display.flip()
  2379. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2380. if ui == 'exit':
  2381. global master_loop
  2382. global playing
  2383. global exitgame
  2384. exitgame = True
  2385. screen.render_load(5)
  2386. save(world,player,time,gods,save_path,os.sep)
  2387. screen.save_tmp_png()
  2388. master_loop = False
  2389. playing = False
  2390. run = False
  2391. return('exit')
  2392. if ui == 'w':
  2393. num -= 1
  2394. if num < 0:
  2395. num = len(menu_items)-1
  2396. if ui == 's':
  2397. num += 1
  2398. if num >= len(menu_items):
  2399. num = 0
  2400. if ui == 'x':
  2401. run = False
  2402. screen.render_fade(True,False,'screen')
  2403. if ui == 'e':
  2404. if num == 0:
  2405. run = False
  2406. screen.render_fade(True,False,'screen')
  2407. if num == 1:
  2408. screen.render_status()
  2409. if num == 2:
  2410. do = message.render_history()
  2411. if do == 'exit':
  2412. run = False
  2413. if num == 3:
  2414. exitgame = True
  2415. screen.render_load(5)
  2416. save(world,player,time,gods,save_path,os.sep)
  2417. screen.save_tmp_png()
  2418. del player
  2419. playing = False
  2420. run = False
  2421. if num == 4:
  2422. do = screen.render_options()
  2423. if do == 'exit':
  2424. run = False
  2425. return exitgame
  2426. def get_choice(self,headline,choices,allow_chancel,style='Default'):
  2427. #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
  2428. run = True
  2429. num = 0
  2430. while run:
  2431. s = pygame.Surface((640,360))
  2432. bg = pygame.Surface((480,360))
  2433. if style == 'Default':
  2434. bg.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2435. elif style == 'Warning':
  2436. bg.blit(gra_files.gdic['display'][17],(0,0))
  2437. s.blit(bg,(0,0))
  2438. text_image = screen.font.render(headline,1,(255,255,255))
  2439. if low_res == False:
  2440. s.blit(text_image,(5,2))#menue title
  2441. else:
  2442. s.blit(text_image,(0,2))#menue title
  2443. menu_items = choices
  2444. for i in range (0,len(menu_items)):
  2445. text_image = screen.font.render(menu_items[i],1,(0,0,0))
  2446. if low_res == False:
  2447. s.blit(text_image,(21,120+i*25))#blit menu_items
  2448. else:
  2449. s.blit(text_image,(21,46+i*25))#blit menu_items
  2450. if allow_chancel == True:
  2451. string = '['+key_name['e']+'] - choose ['+key_name['x']+'] - leave'
  2452. text_image = screen.font.render(string,1,(255,255,255))
  2453. if low_res == True:
  2454. s.blit(text_image,(0,225))
  2455. else:
  2456. s.blit(text_image,(5,335))
  2457. else:
  2458. string = '['+key_name['e']+'] - choose'
  2459. text_image = screen.font.render(string,1,(255,255,255))
  2460. if low_res == True:
  2461. s.blit(text_image,(0,225))
  2462. else:
  2463. s.blit(text_image,(5,335))
  2464. if style == 'Default':
  2465. if low_res == False:
  2466. s.blit(gra_files.gdic['display'][4],(0,112+num*25))#blit marker
  2467. else:
  2468. s.blit(gra_files.gdic['display'][4],(0,38+num*25))#blit marker
  2469. elif style == 'Warning':
  2470. if low_res == False:
  2471. s.blit(gra_files.gdic['display'][18],(0,112+num*25))#blit marker
  2472. else:
  2473. s.blit(gra_files.gdic['display'][18],(0,38+num*25))#blit marker
  2474. if game_options.mousepad == 1:
  2475. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2476. else:
  2477. s_help = pygame.Surface((160,360))
  2478. s_help.fill((48,48,48))
  2479. s.blit(s_help,(480,0))
  2480. if game_options.mousepad == 0:
  2481. s_help = pygame.Surface((640,360))
  2482. s_help.fill((48,48,48))
  2483. s_help.blit(s,(80,0))
  2484. s = s_help
  2485. else:
  2486. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2487. s = pygame.transform.scale(s,(screen.displayx,screen.displayy))
  2488. screen.screen.blit(s,(0,0))
  2489. pygame.display.flip()
  2490. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2491. if ui == 'exit':
  2492. global master_loop
  2493. global playing
  2494. global exitgame
  2495. global player
  2496. exitgame = True
  2497. try:
  2498. screen.render_load(5)
  2499. save(world,player,time,gods,save_path,os.sep)
  2500. screen.save_tmp_png()
  2501. except:
  2502. None
  2503. master_loop = False
  2504. playing = False
  2505. run = False
  2506. return('exit')
  2507. if ui == 'w':
  2508. num -= 1
  2509. if num < 0:
  2510. num = len(menu_items)-1
  2511. if ui == 's':
  2512. num += 1
  2513. if num >= len(menu_items):
  2514. num = 0
  2515. if ui == 'e':
  2516. run = False
  2517. return num
  2518. if ui == 'x' and allow_chancel == True:
  2519. run = False
  2520. return 'Break'
  2521. def string_input(self, input_message, length):
  2522. run = True
  2523. string = ''
  2524. pos = 0
  2525. x = 0
  2526. y = 0
  2527. 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', '.',','),('(','[','<','{',')',']','>','}','#','+','-','_','*','/','&','%'))
  2528. while run:
  2529. s = pygame.Surface((640,360))
  2530. s.blit(gra_files.gdic['display'][1],(0,0)) #render background
  2531. text_image = screen.font.render(input_message,1,(255,255,255))
  2532. s.blit(text_image,(5,2))#menue title
  2533. num_stars = length - len(string)
  2534. star_string = ''
  2535. if num_stars > 0:
  2536. for i in range (0,num_stars):
  2537. star_string += '*'
  2538. shown_string = string + '_' + star_string
  2539. string_image = screen.font.render(shown_string,1,(255,255,255))
  2540. s.blit(string_image,(5,35))#string so far
  2541. for i in range (0,5):#blit chars
  2542. for j in range (0,len(char_field[1])):
  2543. if i == y and j == x:
  2544. char_image = screen.font.render(char_field[i][j],1,(255,255,255))
  2545. else:
  2546. char_image = screen.font.render(char_field[i][j],1,(0,0,0))
  2547. if low_res == False:
  2548. s.blit(char_image,(55+(j*20),150+(i*20)))
  2549. else:
  2550. s.blit(char_image,(5+(j*20),90+(i*20)))
  2551. if game_options.mousepad == 1 and low_res == False:
  2552. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2553. else:
  2554. s_help = pygame.Surface((160,360))
  2555. s_help.fill((48,48,48))
  2556. s.blit(s_help,(480,0))
  2557. text = '['+key_name['e']+'] - Add Char ['+key_name['x']+'] - Del Char ['+key_name['b']+'] - Done'
  2558. text_image = screen.font.render(text,1,(255,255,255))
  2559. if low_res == False:
  2560. s.blit(text_image,(5,335))
  2561. else:
  2562. help_sur = pygame.Surface((320,16))
  2563. help_sur.fill((48,48,48))
  2564. help_sur.blit(text_image,(5,5))
  2565. s.blit(help_sur,(0,224))
  2566. if game_options.mousepad == 0 and low_res == False:
  2567. s_help = pygame.Surface((640,360))
  2568. s_help.fill((48,48,48))
  2569. s_help.blit(s,(80,0))
  2570. s = s_help
  2571. if low_res == False:
  2572. s = pygame.transform.scale(s,(screen.displayx,screen.displayy))
  2573. screen.screen.blit(s,(0,0))
  2574. pygame.display.flip()
  2575. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2576. if ui == 'w':
  2577. y -= 1
  2578. if y < 0:
  2579. y = 4
  2580. if ui == 's':
  2581. y += 1
  2582. if y > 4:
  2583. y = 0
  2584. if ui == 'a':
  2585. x -= 1
  2586. if x < 0:
  2587. x = len(char_field[1])-1
  2588. if ui == 'd':
  2589. x += 1
  2590. if x > len(char_field[1])-1:
  2591. x = 0
  2592. if ui == 'e':
  2593. if pos <= length:
  2594. string += char_field[y][x]
  2595. pos += 1
  2596. if ui == 'b':
  2597. run = False
  2598. if ui == 'x':
  2599. if pos > 0:
  2600. pos -= 1
  2601. string = string[:pos]
  2602. return string
  2603. def render_dead(self):
  2604. global exitgame
  2605. self.reset_hit_matrix()
  2606. if player.godmode == True:
  2607. player.respawn()
  2608. message.add('YOU DIE.. NOT!')
  2609. return True
  2610. run = True
  2611. while run:
  2612. if low_res == False:
  2613. s = pygame.Surface((640,360))
  2614. else:
  2615. s = pygame.Surface((320,240))
  2616. s.fill((48,48,48)) #paint it grey(to clear the screen)
  2617. text_image = screen.font.render('YOU ARE DEAD!',1,(255,255,255))
  2618. if low_res == False:
  2619. s.blit(text_image,(175,60))
  2620. else:
  2621. s.blit(text_image,(75,60))
  2622. if player.difficulty == 3: #you play on roguelike mode
  2623. choose_string = '------------- ['+key_name['x']+'] - END GAME'
  2624. else:#you play on a other mode
  2625. choose_string = '['+key_name['e']+'] - RESPAWN ['+key_name['x']+'] - END GAME'
  2626. choose_image = screen.font.render(choose_string,1,(255,255,255))
  2627. if low_res == False:
  2628. s.blit(choose_image,(125,200))
  2629. else:
  2630. s.blit(choose_image,(25,200))
  2631. if game_options.mousepad == 1 and low_res == False:
  2632. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2633. else:
  2634. s_help = pygame.Surface((160,360))
  2635. s_help.fill((48,48,48))
  2636. s.blit(s_help,(480,0))
  2637. if game_options.mousepad == 0 and low_res == False:
  2638. s_help = pygame.Surface((640,360))
  2639. s_help.fill((48,48,48))
  2640. s_help.blit(s,(80,0))
  2641. s = s_help
  2642. else:
  2643. s.blit(gra_files.gdic['display'][8],(480,0)) #render mouse pad
  2644. if low_res == False:
  2645. s = pygame.transform.scale(s,(screen.displayx,screen.displayy))
  2646. screen.screen.blit(s,(0,0))
  2647. pygame.display.flip()
  2648. ui = getch(screen.displayx,screen.displayy,game_options.sfxmode,game_options.turnmode,mouse=game_options.mousepad)
  2649. if ui == 'exit':
  2650. global master_loop
  2651. global playing
  2652. global exitgame
  2653. exitgame = True
  2654. if player.difficulty !=3:
  2655. screen.render_load(5)
  2656. save(world,player,time,gods,save_path,os.sep)
  2657. screen.save_tmp_png()
  2658. else:
  2659. files_to_remove = ('gods.data','player.data','world.data','time.data')
  2660. for i in files_to_remove:
  2661. del_file = save_path + os.sep + i
  2662. try:
  2663. os.remove(del_file)
  2664. except:
  2665. None
  2666. master_loop = False
  2667. playing = False
  2668. run = False
  2669. return('exit')
  2670. if ui == 'e' and player.difficulty != 3:
  2671. player.respawn()
  2672. save(world,player,time,gods,save_path,os.sep)
  2673. run = False
  2674. elif ui == 'x':
  2675. player.respawn()
  2676. if player.difficulty != 3:
  2677. screen.render_load(5)
  2678. save(world,player,time,gods,save_path,os.sep)
  2679. screen.save_tmp_png()
  2680. else:
  2681. files_to_remove = ('gods.data','player.data','world.data','time.data')
  2682. for i in files_to_remove:
  2683. del_file = save_path + os.sep + i
  2684. try:
  2685. os.remove(del_file)
  2686. except:
  2687. None
  2688. run = False
  2689. exitgame = True
  2690. class maP():
  2691. def __init__(self, name, tilemap, visit=False, map_type='overworld',monster_num=1):
  2692. self.name = name
  2693. self.known = []
  2694. self.containers = []
  2695. self.tilemap = tilemap
  2696. self.visit = visit
  2697. self.last_visit = 0 #-------test only
  2698. self.map_type = map_type
  2699. self.monster_num = monster_num
  2700. self.build_type = 'Full' #Full: build everything you want, Part: no stairs, None: Buildmode is not callable
  2701. self.thirst_multi_day = 1
  2702. self.thirst_multi_night = 1
  2703. self.no_monster_respawn = False
  2704. self.countdowns = []
  2705. self.npcs = []
  2706. self.monster_plus = 0
  2707. self.monster_count = 0
  2708. self.music_day_original = 'overworld'
  2709. self.music_day = self.music_day_original
  2710. self.music_night_original = 'night'
  2711. self.music_night = self.music_night_original
  2712. self.generation_release = release_number
  2713. for y in range (0,max_map_size):
  2714. self.known.append([])
  2715. for x in range (0,max_map_size):
  2716. self.known[y].append(0)
  2717. for y in range (0,max_map_size):
  2718. self.containers.append([])
  2719. for x in range (0,max_map_size):
  2720. self.containers[y].append(0)
  2721. for y in range (0,max_map_size):
  2722. self.npcs.append([])
  2723. for x in range (0,max_map_size):
  2724. self.npcs[y].append(0)
  2725. def fill(self, tile):
  2726. for y in range (0,max_map_size):
  2727. for x in range(0,max_map_size):
  2728. self.tilemap[y][x] = deepcopy(tile)
  2729. def check_fov(self,x,y,dist):
  2730. fov = []
  2731. startx = x-8
  2732. starty = y-6
  2733. extreme_coordinates = []
  2734. dist_coordinates = []
  2735. for yy in range(0,12):
  2736. fov.append([])
  2737. for xx in range(0,15):
  2738. fov[yy].append(0)
  2739. dist1 = ((8-xx)**2+(6-yy)**2)**0.5
  2740. if dist1 > 0:
  2741. extreme_coordinates.append((xx,yy))
  2742. dist_coordinates.append(dist1)
  2743. for i in range(0,len(extreme_coordinates)-1):
  2744. c = 0
  2745. run = True
  2746. while run:
  2747. dir_x = (8-extreme_coordinates[i][0])/dist_coordinates[i]
  2748. dir_y = (6-extreme_coordinates[i][1])/dist_coordinates[i]
  2749. lx = int(round(8+c*dir_x))
  2750. ly = int(6+c*dir_y)
  2751. if ly < 6:
  2752. ly += 1
  2753. elif ly > 6:
  2754. ly -= 1
  2755. ldist = ((8-lx)**2+(6-ly)**2)**0.5
  2756. try:
  2757. fov[ly][lx] = 1
  2758. except:
  2759. None
  2760. c+=1
  2761. if lx < 0 or lx > 14 or ly < 0 or ly > 11:
  2762. run = False
  2763. elif ldist >= dist:
  2764. run = False
  2765. elif self.tilemap[starty+ly][startx+lx].transparency == False:
  2766. run = False
  2767. return fov
  2768. def check_los(self,startx,starty,endx,endy):
  2769. try:
  2770. 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:
  2771. return False
  2772. vector = (endx-startx,endy-starty)
  2773. dist = (vector[0]**2+vector[1]**2)**0.5
  2774. try:
  2775. test1 = self.npcs[starty][startx].inner_view_range
  2776. test2 = self.npcs[starty][startx].outer_view_range
  2777. test3 = self.npcs[starty][startx].active
  2778. except:
  2779. self.npcs[starty][startx].inner_view_range = 5
  2780. self.npcs[starty][startx].outer_view_range = 8
  2781. self.npcs[starty][startx].active = False
  2782. if dist <= self.npcs[starty][startx].inner_view_range and self.npcs[starty][startx].active == False:
  2783. self.npcs[starty][startx].active = True
  2784. if dist > self.npcs[starty][startx].outer_view_range and self.npcs[starty][startx].active == True:
  2785. self.npcs[starty][startx].active = False
  2786. if self.npcs[starty][startx].active == False:
  2787. return False
  2788. else:
  2789. return True
  2790. #uvector = (vector[0]/dist,vector[1]/dist)
  2791. #c = 0
  2792. #run = True
  2793. #while run:
  2794. # x = int(round(startx+(c*uvector[0]),0))
  2795. # y = int(round(starty+(c*uvector[1]),0))
  2796. #screen.write_hit_matrix(x,y,15)
  2797. # if x < 0 or x > max_map_size or y < 0 or y > max_map_size:
  2798. # return False #only to be sure
  2799. #
  2800. # if x == endx and y == endy:
  2801. # return True
  2802. #
  2803. # if self.tilemap[y][x].transparency == False:
  2804. # return False
  2805. # c += 1
  2806. except:
  2807. return False
  2808. def set_round_frame(self,tile,radius):
  2809. center = int(max_map_size/2)
  2810. for y in range(0,max_map_size):
  2811. for x in range(0,max_map_size):
  2812. range_x = x-center
  2813. range_y = y-center
  2814. if ((range_x**2+range_y**2)**0.5) > radius:
  2815. self.tilemap[y][x] = tile
  2816. def set_music(self,day,night,change_original=False):
  2817. if day != None:
  2818. self.music_day = day
  2819. if change_original == True:
  2820. self.music_day_original = day
  2821. if night != None:
  2822. self.music_night = night
  2823. if change_original == True:
  2824. self.music_night_original = night
  2825. def drunken_finder(self,startx,starty,tile):
  2826. x = startx
  2827. y = starty
  2828. run = True
  2829. while run:
  2830. direction = random.randint(0,3)
  2831. if direction == 0:
  2832. y -= 1
  2833. elif direction == 1:
  2834. x += 1
  2835. elif direction == 2:
  2836. y += 1
  2837. else:
  2838. x -= 1
  2839. if self.tilemap[y][x].techID == tile.techID:
  2840. run = False
  2841. return (x,y)
  2842. def drunken_walker(self,startx,starty,tile_replace,num_replace):
  2843. num = 1
  2844. x = startx
  2845. y = starty
  2846. self.tilemap[y][x] = tile_replace
  2847. while num < num_replace:
  2848. #step 0: get possible directions
  2849. dir_list = []
  2850. for n in range(-1,2):
  2851. if x+n < max_map_size-2 and x+n > 2:
  2852. if x+n < max_map_size-7 and x+n > 7:
  2853. count = 5
  2854. else:
  2855. count = min((max_map_size-2)-(x+n),(x+n),3)
  2856. count = max(count,1)#only to be sure count < 1
  2857. for c in range(0,count):
  2858. dir_list.append([x+n,y])
  2859. if y+n < max_map_size-2 and y+n > 2:
  2860. if y+n < max_map_size-7 and y+n > 7:
  2861. count = 5
  2862. else:
  2863. count = min((max_map_size-2)-(y+n),(y+n),3)
  2864. count = max(count,1)#only to be sure count < 1
  2865. for c in range(0,count):
  2866. dir_list.append([x,y+n])
  2867. #step 1: set tile new tile
  2868. ran = random.randint(0,len(dir_list)-1)
  2869. x = dir_list[ran][0]
  2870. y = dir_list[ran][1]
  2871. if self.tilemap[y][x].techID != tile_replace.techID:
  2872. self.tilemap[y][x] = tile_replace
  2873. num += 1
  2874. def floating(self,startx,starty,tile_fill,tile_border):
  2875. #its important to use a tile_fill that isn't on the map and a tile_border that is on the map
  2876. run = True
  2877. self.tilemap[starty][startx] = deepcopy(tile_fill)
  2878. while run:
  2879. count = 0
  2880. for y in range(0,max_map_size):
  2881. for x in range(0,max_map_size):
  2882. if self.tilemap[y][x].techID == tile_fill.techID:
  2883. for yy in range(y-1,y+2):
  2884. for xx in range(x-1,x+2):
  2885. try:
  2886. if self.tilemap[yy][xx].techID != tile_border.techID and self.tilemap[yy][xx].techID != tile_fill.techID:
  2887. self.tilemap[yy][xx] = deepcopy(tile_fill)
  2888. count += 1
  2889. except:
  2890. None
  2891. if count == 0:
  2892. run = False
  2893. def float_civilisation(self,start_x,start_y):
  2894. tm = []
  2895. for y in range(0,max_map_size):
  2896. tm.append([])
  2897. for x in range(0,max_map_size):
  2898. tm[y].append(0)
  2899. tm[start_y][start_x] = 1
  2900. run = True
  2901. total_count = 1
  2902. while run:
  2903. count = 0
  2904. for yy in range(0,max_map_size):
  2905. for xx in range(0,max_map_size):
  2906. if tm[yy][xx] == 1:
  2907. for yyy in range(yy-1,yy+2):
  2908. for xxx in range(xx-1,xx+2):
  2909. try:
  2910. if tm[yyy][xxx] == 0 and self.tilemap[yyy][xxx].move_group == 'soil' and self.tilemap[yyy][xxx].civilisation == True:
  2911. tm[yyy][xxx] = 1
  2912. count += 1
  2913. total_count += 1
  2914. elif self.tilemap[yyy][xxx].civilisation == False:
  2915. return 0
  2916. except:
  2917. None
  2918. if count == 0:
  2919. run = False
  2920. return total_count
  2921. def float_building_shape(self,start_x,start_y):
  2922. help_map = []
  2923. for i in range(0,max_map_size):
  2924. help_map.append([])
  2925. for j in range(0,max_map_size):
  2926. help_map[i].append(0)
  2927. if self.tilemap[start_y][start_x].civilisation == True:
  2928. help_map[start_y][start_x] = 1
  2929. else:
  2930. return help_map
  2931. run = True
  2932. while run:
  2933. count = 0
  2934. for y in range(0,max_map_size):
  2935. for x in range(0,max_map_size):
  2936. if help_map[y][x] == 1:
  2937. for yy in range(y-1,y+2):
  2938. for xx in range(x-1,x+2):
  2939. if self.tilemap[yy][xx].civilisation == True and help_map[yy][xx] == 0:
  2940. help_map[yy][xx] = 1
  2941. count += 1
  2942. if count == 0:
  2943. run = False
  2944. return help_map
  2945. def get_quarter_size(self,startx,starty):
  2946. #this funktion gives back a tulpel with the width and height of a quarter made out of the same tile like the start position
  2947. techID = self.tilemap[starty][startx].techID
  2948. q_width = 0
  2949. q_height = 0
  2950. run_w = True
  2951. run_h = True
  2952. while run_w:
  2953. if self.tilemap[starty][startx+q_width].techID == techID:
  2954. q_width += 1
  2955. else:
  2956. run_w = False
  2957. while run_h:
  2958. if self.tilemap[starty+q_height][startx].techID == techID:
  2959. q_height += 1
  2960. else:
  2961. run_h = False
  2962. return (q_width,q_height)
  2963. def set_frame(self,tile):
  2964. for y in range (0,max_map_size):
  2965. for x in range (0,max_map_size):
  2966. if x == 0 or x == max_map_size-1 or y == 0 or y == max_map_size-1:
  2967. self.tilemap[y][x] = tile
  2968. def cut(self, minx, maxx, miny, maxy, replace):
  2969. #everything that is not between min and mx is replaced abainst a tile
  2970. for y in range (0,max_map_size):
  2971. for x in range (0,max_map_size):
  2972. if x < minx or x > maxx or y < miny or y > maxy:
  2973. self.tilemap[y][x] = replace
  2974. def imp(self, start_x, start_y, replace_inner, replace_outer, step_min, step_max, circles, replace_except=None): #dig random caves
  2975. #was made to generate random caves but dosn't pleased me. maybe this can be used for mazes.(unused atm)
  2976. x = start_x
  2977. y = start_y
  2978. for l in range (0,circles):
  2979. run = True
  2980. while run:
  2981. direction = random.randint(0,3)
  2982. move_x = 0
  2983. move_y = 0
  2984. if direction == 0:
  2985. move_y = -1
  2986. elif direction == 1:
  2987. move_x = 1
  2988. elif direction == 2:
  2989. move_y = 1
  2990. else:
  2991. move_x= -1
  2992. length = random.randint(step_min, step_max)
  2993. for m in range (0,length):
  2994. x = x + move_x
  2995. y = y + move_y
  2996. if x <= 1 or x >= 78 or y <= 1 or y >= 78:
  2997. break
  2998. run = False
  2999. self.tilemap[y][x] = replace_inner
  3000. for b in range (-1,2):
  3001. for a in range (-1,2):
  3002. 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:
  3003. self.tilemap[y+a][x+b] = replace_outer
  3004. run = False
  3005. def imp_connect(self,xpos,ypos,replace_inner,replace_except=None,except_replacer=None,style='straight'): #conects two or more points
  3006. for a in range (0,len(ypos)-1):
  3007. for b in range(0,len(xpos)-1):
  3008. y = ypos[a]
  3009. x = xpos[b]
  3010. go = True
  3011. direction = 0 #needed for natural ways. jumps between 0 and 1
  3012. while go:
  3013. try:
  3014. y_goal = ypos[a+1]
  3015. x_goal = xpos[b+1]
  3016. except:
  3017. y_goal = ypos[0]
  3018. x_goal = xpos[0]
  3019. if x == x_goal and y == y_goal:
  3020. go = False
  3021. if x_goal - x < 0: #find out if you need to go right or left
  3022. x_direction = -1
  3023. else:
  3024. x_direction = 1
  3025. if y_goal - y < 0: #find out if you need to go up or down
  3026. y_direction = -1
  3027. else:
  3028. y_direction = 1
  3029. if style == 'straight':
  3030. if x != x_goal:
  3031. x = x + x_direction
  3032. if self.tilemap[y][x] != replace_except:
  3033. self.tilemap[y][x] = replace_inner
  3034. elif self.tilemap[y][x] == replace_except:
  3035. self.tilemap[y][x] = except_replacer
  3036. elif y != y_goal:
  3037. y = y + y_direction
  3038. if self.tilemap[y][x] != replace_except:
  3039. self.tilemap[y][x] = replace_inner
  3040. elif self.tilemap[y][x] == replace_except:
  3041. self.tilemap[y][x] = except_replacer
  3042. elif style == 'natural':
  3043. if x != x_goal and direction == 0:
  3044. x = x + x_direction
  3045. if self.tilemap[y][x] != replace_except:
  3046. self.tilemap[y][x] = replace_inner
  3047. elif self.tilemap[y][x] == replace_except:
  3048. self.tilemap[y][x] = except_replacer
  3049. elif y != y_goal and direction == 1:
  3050. y = y + y_direction
  3051. if self.tilemap[y][x] != replace_except:
  3052. self.tilemap[y][x] = replace_inner
  3053. elif self.tilemap[y][x] == replace_except:
  3054. self.tilemap[y][x] = except_replacer
  3055. if direction == 0:
  3056. direction = 1
  3057. elif direction == 1:
  3058. direction = 0
  3059. def spawn_monsters(self,depth):
  3060. #This function spawns monsters on the map
  3061. if self.map_type == 'elfish_fortress':
  3062. monster_max = 0
  3063. for y in range(0,max_map_size):
  3064. for x in range(0,max_map_size):
  3065. if self.tilemap[y][x].techID == tl.tlist['functional'][8].techID:#this is a bed
  3066. monster_max += 1
  3067. else:
  3068. monster_max = (max_map_size*max_map_size)/30
  3069. monster_max = int(monster_max * self.monster_num)
  3070. if self.map_type == 'grot':
  3071. spawnpoints = self.find_all_moveable(ignore_water = False, ignore_no_spawn = False)
  3072. else:
  3073. spawnpoints = self.find_all_moveable(ignore_no_spawn = False)
  3074. del_list = []
  3075. monster_count = self.monster_count
  3076. for i in range (0,len(spawnpoints)):
  3077. if self.npcs[spawnpoints[i][1]][spawnpoints[i][0]] != 0: #there is a monster here
  3078. spawnpoints[i] = 'del'
  3079. #monster_count += 1#count the monsters that are already on the map
  3080. newlist = []
  3081. for k in spawnpoints:
  3082. if k != 'del':
  3083. newlist.append(k)
  3084. spawnpoints = newlist
  3085. monster_max -= monster_count
  3086. if monster_max > len(spawnpoints):
  3087. monster_max = len(spawnpoints)
  3088. for k in range(0,monster_max):
  3089. ran = random.randint(0,len(ml.mlist[self.map_type])-1)
  3090. ran2 = random.randint(0,len(spawnpoints)-1)
  3091. ran3 = random.randint(0,len(ml.mlist['civilian'])-1)
  3092. 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
  3093. self.set_monster_strength(spawnpoints[ran2][0],spawnpoints[ran2][1],depth)
  3094. self.monster_count += 1
  3095. if self.no_monster_respawn == False:
  3096. self.countdowns.append(countdown('spawner',spawnpoints[ran2][1],spawnpoints[ran2][0],random.randint(5,60)))
  3097. try:
  3098. if player.difficulty == 4:
  3099. self.npcs[spawnpoints[ran2][1]][spawnpoints[ran2][0]].AI_style = 'ignore'
  3100. except:
  3101. None
  3102. #set monsters personal_id
  3103. 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))
  3104. #set monster groups
  3105. self.spawn_monster_groups(ml.mlist['kobold'][0],ml.mlist['kobold'][1],9)#kobolds
  3106. def set_monster_strength(self,x,y,z,preset_lvl=None,lvl_bonus=0):
  3107. if self.npcs[y][x] != 0:
  3108. old_lvl = self.npcs[y][x].lvl
  3109. ran = random.randint(1,3)
  3110. if Time_ready == True:
  3111. if player.difficulty == 3:
  3112. base_lvl = 25
  3113. elif player.difficulty == 2:
  3114. base_lvl = 20
  3115. elif player.difficulty == 1:
  3116. base_lvl = 15
  3117. elif player.difficulty == 0:
  3118. base_lvl = 10
  3119. else:
  3120. base_lvl = 0
  3121. time_coeff = int(base_lvl*((time.year-1)*28*12 + time.day_total)/150) #base_lvl levels each 150 days of gameplay #
  3122. else:
  3123. time_coeff = 0
  3124. 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
  3125. try:
  3126. time_coeff = player.lvl
  3127. except:
  3128. None
  3129. monster_lvl = z + ran + self.monster_plus + time_coeff
  3130. if monster_lvl >= old_lvl and old_lvl > 0:
  3131. try:
  3132. screen.write_hit_matrix(x,y,12) #render monster_lvl_up
  3133. except:
  3134. None
  3135. if preset_lvl != None:
  3136. self.npcs[y][x].lvl = preset_lvl
  3137. else:
  3138. self.npcs[y][x].lvl = monster_lvl
  3139. self.npcs[y][x].lvl += lvl_bonus
  3140. attribute_list =[]
  3141. al = ('p_strength','p_defense','m_strength','m_defense','health')
  3142. for c in range(0,5):
  3143. if self.npcs[y][x].attribute_prev[c] > 0:
  3144. for h in range(0,self.npcs[y][x].attribute_prev[c]):
  3145. attribute_list.append(al[c])
  3146. for i in range(0,self.npcs[y][x].lvl):
  3147. choice = attribute_list[random.randint(0,len(attribute_list)-1)]
  3148. if choice == 'p_strength':
  3149. self.npcs[y][x].basic_attribute.p_strength +=3
  3150. elif choice == 'p_defense':
  3151. self.npcs[y][x].basic_attribute.p_defense +=3
  3152. elif choice == 'm_strength':
  3153. self.npcs[y][x].basic_attribute.m_strength +=3
  3154. elif choice == 'm_defense':
  3155. self.npcs[y][x].basic_attribute.m_defense +=3
  3156. elif choice == 'health':
  3157. self.npcs[y][x].basic_attribute.max_lp +=1
  3158. self.npcs[y][x].lp = self.npcs[y][x].basic_attribute.max_lp
  3159. if old_lvl == 0:
  3160. el = [['spear','sword','axe','hammer'],['rune','wand','rune staff','artefact'],['armor','armor'],['necklace','amulet','talisman'],['ring','ring']]
  3161. e_nr = 0
  3162. for q in range(0,len(el)-1):
  3163. ran = random.randint(0,len(el[q])-1)
  3164. if self.npcs[y][x].worn_equipment[q] == 1:
  3165. help_equipment = item_wear(el[q][ran],random.randint(0,min((z*3),21)),random.randint(-2,2))
  3166. self.npcs[y][x].basic_attribute.p_strength += help_equipment.attribute.p_strength
  3167. self.npcs[y][x].basic_attribute.p_defense += help_equipment.attribute.p_defense
  3168. self.npcs[y][x].basic_attribute.m_strength += help_equipment.attribute.m_strength
  3169. self.npcs[y][x].basic_attribute.m_defense += help_equipment.attribute.m_defense
  3170. self.npcs[y][x].basic_attribute.luck += help_equipment.attribute.luck
  3171. if 'cattle' in self.npcs[y][x].properties:
  3172. self.npcs[y][x].basic_attribute.max_lp = 1
  3173. self.npcs[y][x].lp = self.npcs[y][x].basic_attribute.max_lp
  3174. self.npcs[y][x].lp = self.npcs[y][x].basic_attribute.p_defense = 1
  3175. self.npcs[y][x].lp = self.npcs[y][x].basic_attribute.m_defense = 1
  3176. if 'pet0' in self.npcs[y][x].properties:
  3177. self.npcs[y][x].basic_attribute.max_lp = 5
  3178. if 'pet1' in self.npcs[y][x].properties:
  3179. self.npcs[y][x].basic_attribute.max_lp = 10
  3180. if 'pet2' in self.npcs[y][x].properties:
  3181. self.npcs[y][x].basic_attribute.max_lp = 15
  3182. def make_vault(self,on_tile,depth):
  3183. run = True
  3184. while run:
  3185. pos = self.find_any(on_tile)
  3186. test = True
  3187. orientation = random.randint(0,3)#0:north, 1:east, 2:south, 3:west
  3188. try:
  3189. if pos[0] < 6 or pos[0] > max_map_size-6 or pos[1] < 6 or pos[1] > max_map_size-6:
  3190. test = False
  3191. if orientation == 0:
  3192. x_offset = -2
  3193. y_offset = random.randint(-1,1)
  3194. elif orientation == 1:
  3195. x_offset = random.randint(-1,1)
  3196. y_offset = -2
  3197. elif orientation == 2:
  3198. x_offset = 2
  3199. y_offste = random.randint(-1,1)
  3200. else:
  3201. x_offset = random.randint(-1,1)
  3202. y_offset = 2
  3203. for ty in range(pos[1]+y_offset-1,pos[1]+y_offset+6):
  3204. for tx in range(pos[0]+x_offset-1,pos[0]+x_offset+6):
  3205. if self.tilemap[ty][tx].techID == tl.tlist['dungeon'][0].techID:
  3206. test = False
  3207. elif self.tilemap[ty][tx].techID == tl.tlist['dungeon'][6].techID:
  3208. test = False
  3209. elif self.tilemap[ty][tx].techID == tl.tlist['dungeon'][9].techID:
  3210. test = False
  3211. elif self.tilemap[ty][tx].techID == tl.tlist['functional'][2].techID:
  3212. test = False
  3213. except:
  3214. test = False
  3215. if test:
  3216. run = False
  3217. for yy in range(pos[1]+y_offset-2,pos[1]+y_offset+3):
  3218. for xx in range(pos[0]+x_offset-2,pos[0]+x_offset+3):
  3219. 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:
  3220. self.tilemap[yy][xx] = deepcopy(tl.tlist['dungeon'][9])
  3221. self.tilemap[yy][xx].no_spawn = True
  3222. else:
  3223. self.tilemap[yy][xx] = deepcopy(tl.tlist['dungeon'][0])
  3224. self.tilemap[yy][xx].no_spawn = True
  3225. make_loot = True # if make_loot is set on False no gems or ore will spawn inside the vault
  3226. vault_center_x = pos[0]+x_offset
  3227. vault_center_y = pos[1]+y_offset
  3228. door_pos = self.drunken_finder(vault_center_x,vault_center_y,tl.tlist['dungeon'][9])
  3229. self.tilemap[door_pos[1]][door_pos[0]] = deepcopy(tl.tlist['dungeon'][6])
  3230. self.tilemap[door_pos[1]][door_pos[0]].no_spawn = True
  3231. vault_type = random.randint(0,4)
  3232. #vault_type = 4
  3233. if vault_type == 0: #Libary
  3234. replace = self.tilemap[vault_center_y][vault_center_x]
  3235. self.tilemap[vault_center_y][vault_center_x] = deepcopy(tl.tlist['functional'][19])#set a bookshelf
  3236. self.tilemap[vault_center_y][vault_center_x].replace = replace
  3237. self.tilemap[vault_center_y][vault_center_x].no_spawn = True
  3238. replace = self.tilemap[vault_center_y+1][vault_center_x]
  3239. self.tilemap[vault_center_y+1][vault_center_x] = deepcopy(tl.tlist['functional'][4])#set a chest
  3240. self.tilemap[vault_center_y+1][vault_center_x].replace = replace
  3241. self.tilemap[vault_center_y+1][vault_center_x].no_spawn = True
  3242. num_spellbooks = random.randint(2,3)#fill the chest
  3243. spellbook_list = []
  3244. 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],il.ilist['misc'][45],il.ilist['misc'][83])
  3245. for i in range(0,num_spellbooks):
  3246. ran = random.randint(0,len(sb)-1)
  3247. spellbook_list.append(sb[ran])
  3248. self.containers[vault_center_y+1][vault_center_x] = container(spellbook_list)
  3249. self.npcs[vault_center_y-1][vault_center_x-1] = deepcopy(ml.mlist['grot'][0]) #
  3250. self.set_monster_strength(vault_center_x-1,vault_center_y-1,depth,lvl_bonus=3) #
  3251. self.npcs[vault_center_y-1][vault_center_x+1] = deepcopy(ml.mlist['grot'][0]) #
  3252. self.set_monster_strength(vault_center_x+1,vault_center_y-1,depth,lvl_bonus=3) #set blue nagas
  3253. self.npcs[vault_center_y+1][vault_center_x-1] = deepcopy(ml.mlist['grot'][0]) #
  3254. self.set_monster_strength(vault_center_x-1,vault_center_y+1,depth,lvl_bonus=3) #
  3255. self.npcs[vault_center_y+1][vault_center_x+1] = deepcopy(ml.mlist['grot'][0]) #
  3256. self.set_monster_strength(vault_center_x+1,vault_center_y+1,depth,lvl_bonus=3) #
  3257. if vault_type == 1: #Slime pit
  3258. replace = self.tilemap[vault_center_y][vault_center_x]
  3259. self.tilemap[vault_center_y][vault_center_x] = deepcopy(tl.tlist['statue'][2])#set a blob statue
  3260. self.tilemap[vault_center_y][vault_center_x].replace = replace
  3261. self.tilemap[vault_center_y][vault_center_x].no_spawn = True
  3262. self.npcs[vault_center_y-1][vault_center_x-1] = deepcopy(ml.mlist['special'][10]) #
  3263. self.set_monster_strength(vault_center_x-1,vault_center_y-1,depth,lvl_bonus=3) #
  3264. self.npcs[vault_center_y-1][vault_center_x+1] = deepcopy(ml.mlist['special'][10]) #
  3265. self.set_monster_strength(vault_center_x+1,vault_center_y-1,depth,lvl_bonus=3) #set giant blobs
  3266. self.npcs[vault_center_y+1][vault_center_x-1] = deepcopy(ml.mlist['special'][10]) #
  3267. self.set_monster_strength(vault_center_x-1,vault_center_y+1,depth,lvl_bonus=3) #
  3268. self.npcs[vault_center_y+1][vault_center_x+1] = deepcopy(ml.mlist['special'][10]) #
  3269. self.set_monster_strength(vault_center_x+1,vault_center_y+1,depth,lvl_bonus=3) #
  3270. if vault_type == 2: #Kobold Lair
  3271. replace = self.tilemap[vault_center_y][vault_center_x]
  3272. self.tilemap[vault_center_y][vault_center_x] = deepcopy(tl.tlist['deco'][9])#set a stony throne
  3273. self.tilemap[vault_center_y][vault_center_x].replace = replace #
  3274. self.tilemap[vault_center_y][vault_center_x].no_spawn = True #
  3275. for posy in range(vault_center_y-1,vault_center_y+2): #
  3276. for posx in range(vault_center_x-1,vault_center_x+2): #set Kobolds
  3277. self.npcs[posy][posx] = deepcopy(ml.mlist['kobold'][1]) #
  3278. self.set_monster_strength(posx,posy,depth,lvl_bonus=3) #
  3279. self.npcs[vault_center_y][vault_center_x] = deepcopy(ml.mlist['kobold'][0]) #set kobold shaman
  3280. self.set_monster_strength(vault_center_x,vault_center_y,depth,lvl_bonus=3) #
  3281. if vault_type == 3: #Bat Cave
  3282. make_loot = False
  3283. for posy in range(vault_center_y-1,vault_center_y+2): #
  3284. for posx in range(vault_center_x-1,vault_center_x+2): #set bats
  3285. self.npcs[posy][posx] = deepcopy(ml.mlist['cave'][2]) #
  3286. self.set_monster_strength(posx,posy,depth) #
  3287. if vault_type == 4: #mimic chamber
  3288. make_loot = False
  3289. ranx = random.randint(-1,1) #
  3290. rany = random.randint(-1,1) #
  3291. replace = self.tilemap[vault_center_y+rany][vault_center_x+ranx] #
  3292. self.tilemap[vault_center_y+rany][vault_center_x+ranx] = deepcopy(tl.tlist['functional'][4])#set a chest
  3293. self.tilemap[vault_center_y+rany][vault_center_x+ranx].replace = replace #
  3294. self.tilemap[vault_center_y+rany][vault_center_x+ranx].no_spawn = True #
  3295. 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],il.ilist['misc'][45],il.ilist['misc'][83])
  3296. ransb = random.randint(0,len(sb)-1)
  3297. book = sb[ransb]
  3298. pick = item_wear('pickaxe', 20,0)
  3299. axe = item_wear('axe',20,0)
  3300. self.containers[vault_center_y+rany][vault_center_x+ranx] = container([book,axe,pick])#fill chest
  3301. for posy in range(vault_center_y-1,vault_center_y+2): #
  3302. for posx in range(vault_center_x-1,vault_center_x+2): #set sleeping mimics
  3303. if self.tilemap[posy][posx].techID != tl.tlist['functional'][4].techID: #
  3304. self.npcs[posy][posx] = deepcopy(ml.mlist['special'][3]) #
  3305. if make_loot == True:
  3306. for yyy in range(vault_center_y-2,vault_center_y+3):
  3307. for xxx in range(vault_center_x-2,vault_center_x+3):
  3308. if self.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][0].techID:
  3309. ran2 = random.randint(0,2)
  3310. replace = self.tilemap[yyy][xxx]
  3311. if ran2 > 1:
  3312. self.tilemap[yyy][xxx] = deepcopy(tl.tlist['misc'][9])#set gem
  3313. self.tilemap[yyy][xxx].no_spawn = True
  3314. else:
  3315. self.tilemap[yyy][xxx] = deepcopy(tl.tlist['misc'][11])#set ore
  3316. self.tilemap[yyy][xxx].no_spawn = True
  3317. self.tilemap[yyy][xxx].replace = replace
  3318. #print('Made vault at: '+str(pos[0])+','+str(pos[1])+' Type:'+str(vault_type))
  3319. ####go on here
  3320. def make_orc_cave(self,on_tile):
  3321. run = True
  3322. while run:
  3323. pos = self.find_any(on_tile)
  3324. test = True
  3325. try:
  3326. for ty in range(pos[1]-2,pos[1]+3):
  3327. for tx in range(pos[0]-2,pos[0]+3):
  3328. if self.tilemap[ty][tx].techID == tl.tlist['misc'][16]:
  3329. test = False
  3330. elif self.tilemap[ty][tx].techID == tl.tlist['mine'][0]:
  3331. test = False
  3332. elif self.tilemap[ty][tx].techID == tl.tlist['dungeon'][3]:
  3333. test = False
  3334. elif self.tilemap[ty][tx].techID == tl.tlist['misc'][12]:
  3335. test = False
  3336. except:
  3337. test = False
  3338. if ((pos[0]-(max_map_size/2))**2+(pos[1]-(max_map_size/2))**2)**0.5 > 10:
  3339. 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:
  3340. run = False
  3341. for y in range(pos[1]-2,pos[1]+3):
  3342. for x in range(pos[0]-2,pos[0]+3):
  3343. self.tilemap[y][x] = tl.tlist['misc'][16] #fill with solid orcish wall
  3344. for y in range(pos[1]-1,pos[1]+2):
  3345. for x in range(pos[0]-1,pos[0]+2):
  3346. self.tilemap[y][x] = tl.tlist['mine'][0] #fill inner with orcish mine floor
  3347. if x != pos[0] or y != pos[1]:
  3348. self.npcs[y][x] = deepcopy(ml.mlist['orc'][random.randint(0,len(ml.mlist['orc'])-1)]) #
  3349. else: #
  3350. self.npcs[y][x] = deepcopy(ml.mlist['orcish_mines'][1]) #
  3351. self.set_monster_strength(x,y,1) #generate orcs
  3352. self.countdowns.append(countdown('orc_spawner',x,y,random.randint(5,60))) #
  3353. self.tilemap[pos[1]-2][pos[0]] = deepcopy(tl.tlist['dungeon'][3])#
  3354. self.tilemap[pos[1]+2][pos[0]] = deepcopy(tl.tlist['dungeon'][3])# make dungeon doors
  3355. self.tilemap[pos[1]][pos[0]-2] = deepcopy(tl.tlist['dungeon'][3])#
  3356. self.tilemap[pos[1]][pos[0]+2] = deepcopy(tl.tlist['dungeon'][3])#
  3357. self.tilemap[pos[1]-2][pos[0]-2] = deepcopy(tl.tlist['misc'][12])#
  3358. self.tilemap[pos[1]-2][pos[0]-2].replace = deepcopy(on_tile) #
  3359. self.tilemap[pos[1]-2][pos[0]+2] = deepcopy(tl.tlist['misc'][12])#
  3360. self.tilemap[pos[1]-2][pos[0]+2].replace = deepcopy(on_tile) # add orc deko to the connors
  3361. self.tilemap[pos[1]+2][pos[0]-2] = deepcopy(tl.tlist['misc'][12])#
  3362. self.tilemap[pos[1]+2][pos[0]-2].replace = deepcopy(on_tile) #
  3363. self.tilemap[pos[1]+2][pos[0]+2] = deepcopy(tl.tlist['misc'][12])#
  3364. self.tilemap[pos[1]+2][pos[0]+2].replace = deepcopy(on_tile) #
  3365. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['misc'][18])#set a crystal orb
  3366. def AI_move(self):
  3367. #This function moves all monsters that are 7 or less fields away from the player.
  3368. #It dosn't move all monsters to save performance
  3369. #ymin = player.pos[1]-7
  3370. #if ymin < 0:
  3371. # ymin = 0
  3372. #xmin = player.pos[0]-7
  3373. #if xmin < 0:
  3374. # xmin = 0
  3375. #ymax = player.pos[1]+8
  3376. #if ymax > max_map_size:
  3377. # ymax = max_map_size
  3378. #xmax = player.pos[0]+8
  3379. #if xmax > max_map_size:
  3380. # xmax = max_map_size
  3381. xmin = 0
  3382. ymin = 0
  3383. xmax = max_map_size
  3384. ymax = max_map_size
  3385. for y in range (ymin,ymax):#reset the move_done switches
  3386. for x in range (xmin,xmax):
  3387. if self.npcs[y][x] != 0:
  3388. if self.npcs[y][x].lp > 0:
  3389. self.npcs[y][x].move_done = 0
  3390. else:
  3391. test = False
  3392. while test == False:
  3393. test = self.monster_die(x,y)
  3394. for y in range (ymin,ymax):
  3395. for x in range (xmin,xmax):
  3396. if self.npcs[y][x] != 0 and self.npcs[y][x].move_done == 0:#if there is a monster at this place
  3397. #-2. get AI_style
  3398. AI_style = self.npcs[y][x].AI_style
  3399. #-1. remove blind
  3400. if 'blind' in self.npcs[y][x].properties:
  3401. rand = random.randint(0,9)
  3402. if rand < 2:
  3403. for i in range(0,len(self.npcs[y][x].properties)):
  3404. if self.npcs[y][x].properties[i] == 'blind':
  3405. p = i
  3406. try:
  3407. del self.npcs[y][x].properties[p]
  3408. except:
  3409. None
  3410. #0. Get LoS
  3411. los = self.check_los(x,y,player.pos[0],player.pos[1])
  3412. if 'blind' in self.npcs[y][x].properties:
  3413. los = False
  3414. if los == True:
  3415. self.npcs[y][x].last_known_player_pos = (player.pos[0],player.pos[1])
  3416. if player.buffs.get_buff('invisible') > 0:
  3417. los = False
  3418. if self.npcs[y][x].last_known_player_pos != 'Unknown':
  3419. if x == self.npcs[y][x].last_known_player_pos[0] and y == self.npcs[y][x].last_known_player_pos[1]:
  3420. self.npcs[y][x].last_known_player_pos = 'Unknown'
  3421. if player.buffs.get_buff('invisible') > 0 or 'blind' in self.npcs[y][x].properties:
  3422. self.npcs[y][x].last_known_player_pos = 'Unknown'
  3423. #I. Get possible fields for a move
  3424. moves = [(x,y)]
  3425. yy = (-1,0,0,1)
  3426. xx = (0,-1,1,0)
  3427. for i in range (0,4):
  3428. try:
  3429. monster_move_groups = self.npcs[y][x].move_groups
  3430. tile_move_group = self.tilemap[y+yy[i]][x+xx[i]].move_group
  3431. move_group_check = tile_move_group in monster_move_groups
  3432. if self.npcs[y+yy[i]][x+xx[i]] == 0:
  3433. npc = False
  3434. else:
  3435. npc = True
  3436. 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
  3437. stair = True
  3438. else:
  3439. stair = False
  3440. if x + xx[i] == player.pos[0] and y + yy[i] == player.pos[1]:
  3441. playerpos = True
  3442. else:
  3443. playerpos = False
  3444. if move_group_check == True and npc == False and stair == False and playerpos == False:
  3445. moves.append((x+xx[i],y+yy[i]))
  3446. except:
  3447. print('Debug:Error')
  3448. #II. Find out which possible move leads to which distance between monster and player
  3449. distances = []
  3450. for j in range (0,len(moves)):
  3451. if self.npcs[y][x].last_known_player_pos != 'Unknown':
  3452. a = self.npcs[y][x].last_known_player_pos[0] - moves[j][0]
  3453. b = self.npcs[y][x].last_known_player_pos[1] - moves[j][1]
  3454. else:
  3455. a = 100
  3456. b = 100
  3457. c = (a**2 + b**2)**0.5 # this is just the good old pythagoras (c² = a² + b²)
  3458. distances.append(c)
  3459. #III. Choose the right move (or special action)
  3460. do_move = 'foo'
  3461. if AI_style == 'hostile' and los == False:# and self.npcs[y][x].last_known_player_pos == 'Unknown':
  3462. AI_style = 'ignore'
  3463. if AI_style == 'hostile':
  3464. comp = False
  3465. for yy in range(y-1,y+2):
  3466. if self.npcs[yy][x] != 0 and self.npcs[yy][x].AI_style == 'company':
  3467. comp = [x,yy]
  3468. for xx in range(x-1,x+2):
  3469. if self.npcs[y][xx] != 0 and self.npcs[y][xx].AI_style == 'company':
  3470. comp = [xx,y]
  3471. if comp != False and not 'blind' in self.npcs[y][x].properties:
  3472. ran = random.randint(0,99)
  3473. if ran < 40:
  3474. self.npcs[y][x].move_done = 1
  3475. mes = self.npcs[y][x].name + ' [hurts] ' + self.npcs[comp[1]][comp[0]].name
  3476. message.add(mes)
  3477. screen.write_hit_matrix(comp[0],comp[1],4)
  3478. sfx.play('hit')
  3479. player.pet_lp -= 1
  3480. if player.pet_lp < 1:
  3481. self.npcs[comp[1]][comp[0]].relation = int(self.npcs[comp[1]][comp[0]].relation*0.8)
  3482. return_done = False
  3483. for yyy in range(0,max_map_size):
  3484. for xxx in range(0,max_map_size):
  3485. if world.maplist[0]['elysium_0_0'].tilemap[yyy][xxx].techID == tl.tlist['sanctuary'][4].techID and world.maplist[0]['elysium_0_0'].npcs[yyy][xxx] == 0 and return_done == False:
  3486. string = self.npcs[comp[1]][comp[0]].name + ' returns home.'
  3487. message.add(string)
  3488. screen.write_hit_matrix(comp[0],comp[1],7)
  3489. self.npcs[comp[1]][comp[0]].AI_style = 'ignore'
  3490. world.maplist[0]['elysium_0_0'].npcs[yyy][xxx] = deepcopy(self.npcs[comp[1]][comp[0]])
  3491. self.npcs[comp[1]][comp[0]] = 0
  3492. player.pet_pos = False
  3493. player.pet_on_map = False
  3494. return_done = True
  3495. ability_keys = self.npcs[y][x].ability.keys()
  3496. if self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp/2 and player.lp > player.attribute.max_lp/2 and distances[0] < 3 and self.npcs[y][x].num_special > 0 :#this is a defensive situation for the monster
  3497. if 'def_teleport' in ability_keys:
  3498. ran = random.randint(0,99)
  3499. if ran < self.npcs[y][x].ability['def_teleport'] and self.npcs[y][x].move_done != 1:
  3500. moves = self.find_all_moveable(ignore_player_pos = False)
  3501. if moves != False:
  3502. if len(moves) == 1:
  3503. pos_num = 0
  3504. else:
  3505. pos_num = random.randint(0,len(moves)-1)
  3506. self.npcs[y][x].move_done = 1
  3507. self.npcs[y][x].num_special -= 1
  3508. tp_string = 'A ' + self.npcs[y][x].name + ' teleports.'
  3509. message.add(tp_string)
  3510. screen.write_hit_matrix(x,y,7)
  3511. sfx.play('teleport')
  3512. self.npcs[moves[pos_num][1]][moves[pos_num][0]] = self.npcs[y][x]
  3513. self.npcs[y][x] = 0
  3514. if 'def_flee' in ability_keys:
  3515. ran = random.randint(0,99)
  3516. if self.npcs[y][x] != 0:
  3517. if ran < self.npcs[y][x].ability['def_flee'] and self.npcs[y][x].move_done != 1 and self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp:
  3518. flee_string = 'A ' + self.npcs[y][x].name + ' turns to flee.'
  3519. message.add(flee_string)
  3520. self.npcs[y][x].AI_style = 'flee'
  3521. self.npcs[y][x].move_done = 1
  3522. self.npcs[y][x].num_special -= 1
  3523. if 'def_potion' in ability_keys:
  3524. ran = random.randint(0,99)
  3525. if ran < self.npcs[y][x].ability['def_potion'] and self.npcs[y][x].move_done != 1:
  3526. if self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp:
  3527. potion_string = 'A ' + self.npcs[y][x].name + ' quaffes a potion of healing.'
  3528. message.add(potion_string)
  3529. screen.write_hit_matrix(x,y,6)
  3530. lp = min(self.npcs[y][x].basic_attribute.max_lp, self.npcs[y][x].lp+7)
  3531. self.npcs[y][x].lp = lp
  3532. sfx.play('drink')
  3533. self.npcs[y][x].move_done = 1
  3534. self.npcs[y][x].num_special -= 1
  3535. if self.npcs[y][x] != 0:
  3536. if (distances[0] > 1 or player.buffs.get_buff('invisible') > 0) 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
  3537. if 'spawn' in ability_keys: #the value of spawn is a tulpel with 2 elements; 0: chance that something is spawned 1: number that determines what is spawned
  3538. ran = random.randint(0,99)
  3539. if ran < self.npcs[y][x].ability['spawn'][0]:
  3540. spawn_kind = self.npcs[y][x].ability['spawn'][1]
  3541. xlist = []
  3542. ylist = []
  3543. for yy in range(y-1,y+2):
  3544. for xx in range(x-1,x+2):
  3545. if self.tilemap[yy][xx].move_group == 'soil' and self.npcs[yy][xx] == 0 and xx != player.pos[0] and yy != player.pos[1]:
  3546. xlist.append(xx)
  3547. ylist.append(yy)
  3548. if len(xlist) == len(ylist) and len(xlist) > 0:
  3549. if len(xlist) > 1:
  3550. num = random.randint(0,len(xlist)-1)
  3551. else:
  3552. num = 0
  3553. if self.npcs[y][x].move_done != 1 and self.npcs[y][x].num_special > 0:
  3554. self.npcs[ylist[num]][xlist[num]] = deepcopy(ml.mlist['special'][spawn_kind]) #all spawnlings must be a part of ml.mlist['special']
  3555. self.npcs[ylist[num]][xlist[num]].personal_id = self.npcs[y][x].personal_id + '_child'
  3556. self.set_monster_strength(xlist[num],ylist[num],player.pos[2])
  3557. mes = 'A ' + self.npcs[y][x].name + ' summons a ' + ml.mlist['special'][spawn_kind].name + '.'
  3558. message.add(mes)
  3559. sfx.play('teleport')
  3560. screen.write_hit_matrix(xlist[num],ylist[num],7)
  3561. self.npcs[y][x].move_done = 1
  3562. self.npcs[y][x].num_special -= 1
  3563. if 'blink' in ability_keys:
  3564. ran = random.randint(0,99)
  3565. if ran < self.npcs[y][x].ability['blink'] and self.npcs[y][x].move_done != 1 and self.npcs[y][x].num_special > 0:
  3566. xlist = []
  3567. ylist = []
  3568. for yy in range(player.pos[1]-3,player.pos[1]+4):
  3569. for xx in range(player.pos[0]-3,player.pos[0]+4):
  3570. if self.tilemap[yy][xx].move_group in self.npcs[y][x].move_groups and self.npcs[yy][xx] == 0:
  3571. if yy != player.pos[1] or xx != player.pos[0]:
  3572. xlist.append(xx)
  3573. ylist.append(yy)
  3574. if len(xlist) != 0:
  3575. try:
  3576. rand = random.randint(0,len(xlist)-1)
  3577. except:
  3578. rand = 0
  3579. screen.write_hit_matrix(x,y,7)
  3580. screen.write_hit_matrix(xlist[rand],ylist[rand],7)
  3581. mes = 'A '+self.npcs[y][x].name+' blinks!'
  3582. message.add(mes)
  3583. self.npcs[ylist[rand]][xlist[rand]] = self.npcs[y][x]
  3584. self.npcs[y][x] = 0
  3585. self.npcs[ylist[rand]][xlist[rand]].num_special -= 1
  3586. self.npcs[ylist[rand]][xlist[rand]].move_done = 1
  3587. if (x == player.pos[0] or y == player.pos[1]) and los == True:
  3588. straight_line = True
  3589. else:
  3590. straight_line = False
  3591. shoot = False
  3592. throw = False
  3593. if 'range_shoot' in ability_keys:
  3594. shoot = True
  3595. elif 'range_throw' in ability_keys:
  3596. throw = True
  3597. if self.npcs[y][x] != 0 and straight_line == True and los == True and (shoot == True or throw == True) and distances[0] < 5:
  3598. #Step 0: Random
  3599. if shoot == True:
  3600. chance = self.npcs[y][x].ability['range_shoot']
  3601. else:
  3602. chance = self.npcs[y][x].ability['range_throw'][0]
  3603. ran = random.randint(0,99)
  3604. if ran < chance and self.npcs[y][x].num_special > 0 and self.npcs[y][x].move_done != 1:
  3605. #Step 1: find the right direction
  3606. if y > player.pos[1]:
  3607. y_dir = -1
  3608. elif y < player.pos[1]:
  3609. y_dir = 1
  3610. else:
  3611. y_dir = 0
  3612. if x > player.pos[0]:
  3613. x_dir = -1
  3614. elif x < player.pos[0]:
  3615. x_dir = 1
  3616. else:
  3617. x_dir = 0
  3618. #Step 2: Check for borders
  3619. run = True
  3620. count = 1
  3621. fire_free = True
  3622. while run:
  3623. cx = x + (count*x_dir)
  3624. cy = y + (count*y_dir)
  3625. if self.tilemap[cy][cx].transparency == False:
  3626. fire_free = False
  3627. run = False
  3628. count +=1
  3629. if cx == player.pos[0] and cy == player.pos[1]:
  3630. run = False
  3631. #Step 3: Fire!
  3632. if fire_free == True:
  3633. run = True
  3634. count = 1
  3635. if 'range_shoot' in ability_keys:
  3636. sfx.play('fire')
  3637. else:
  3638. sfx.play('miss')
  3639. while run:
  3640. xx = x + (count*x_dir)
  3641. yy = y + (count*y_dir)
  3642. if xx != player.pos[0] or yy != player.pos[1]:
  3643. screen.write_hit_matrix(xx,yy,2)
  3644. if self.tilemap[yy][xx].transparency == False:
  3645. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3646. if 'range_throw' in ability_keys:
  3647. sfx.play('throw')
  3648. run = False
  3649. else:
  3650. if shoot == True:#----------> go on here!!!!!!!!
  3651. self.npcs[y][x].move_done = 1
  3652. try:
  3653. player.monster_attacks(x,y)
  3654. except:
  3655. None
  3656. elif self.npcs[y][x].ability['range_throw'][1] == 'stone':
  3657. self.npcs[y][x].move_done = 1
  3658. message.add('A '+self.npcs[y][x].name+' throws a stone!')
  3659. chance = 9 - count
  3660. coin = random.randint(0,9)
  3661. if coin < chance:
  3662. sfx.play('hit')
  3663. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  3664. message.add('The stone hits you.(1 damage)')
  3665. player.lp -= 1
  3666. else:
  3667. sfx.play('throw')
  3668. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3669. message.add('The stone misses you.')
  3670. elif self.npcs[y][x].ability['range_throw'][1] == 'dart':
  3671. self.npcs[y][x].move_done = 1
  3672. message.add('A '+self.npcs[y][x].name+' throws a dart!')
  3673. chance = 9 - count
  3674. coin = random.randint(0,9)
  3675. if coin < chance:
  3676. sfx.play('hit')
  3677. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  3678. message.add('The dart hits you.(2 damage)')
  3679. player.lp -= 2
  3680. else:
  3681. sfx.play('throw')
  3682. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3683. message.add('The dart misses you.')
  3684. elif self.npcs[y][x].ability['range_throw'][1] == 'knife':
  3685. self.npcs[y][x].move_done = 1
  3686. message.add('A '+self.npcs[y][x].name+' throws a throwing knife')
  3687. chance = 9 - count
  3688. coin = random.randint(0,9)
  3689. if coin < chance:
  3690. sfx.play('hit')
  3691. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  3692. message.add('The throwing knife hits you.(3 damage)')
  3693. player.lp -= 3
  3694. else:
  3695. sfx.play('throw')
  3696. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  3697. message.add('The throwing knife misses you.')
  3698. run = False
  3699. count += 1
  3700. self.npcs[y][x].move_done = 1
  3701. if 'range_throw' in ability_keys:
  3702. self.npcs[y][x].num_special -= 1
  3703. if self.npcs[y][x] != 0 and self.npcs[y][x].move_done == 0:
  3704. if len(moves) > 0:#if no move is possible at least the 'move' of stay still must remain
  3705. good_moves = []
  3706. for k in range (0, len(moves)):
  3707. if player.buffs.get_buff('invisible') == 0:
  3708. if distances[k] <= distances[0]:#if the possible move makes the distance between player and monster smaller
  3709. good_moves.append(moves[k])
  3710. else:
  3711. good_moves = moves
  3712. if 'blind' in self.npcs[y][x].properties or player.buffs.get_buff('invisible') != 0:
  3713. good_moves = moves
  3714. else:
  3715. good_moves = moves
  3716. if len(good_moves) <= 1:
  3717. good_moves = moves
  3718. if len(good_moves) > 1:
  3719. ran = random.randint(0,len(good_moves)-1)
  3720. else:
  3721. ran = 0
  3722. do_move = good_moves[ran]
  3723. else:
  3724. if self.npcs[y][x].move_done == 0 and self.npcs[y][x].last_known_player_pos == (player.pos[0],player.pos[1]) and distances[0] == 1 and los == True:
  3725. #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.
  3726. if player.inventory.materials.gem > 0 and 'close_steal' in ability_keys:
  3727. ran = random.randint(0,99)
  3728. if ran < self.npcs[y][x].ability['close_steal']:
  3729. player.inventory.materials.gem -= 1
  3730. self.npcs[y][x].corps_lvl += 1
  3731. screen.write_hit_matrix(player.pos[0],player.pos[1],8)
  3732. screen.write_hit_matrix(x,y,9)
  3733. sfx.play('steal')
  3734. steal_string = 'A ' + self.npcs[y][x].name + ' steals a gem from you.'
  3735. message.add(steal_string)
  3736. self.npcs[y][x].move_done = 1#set the move_done switch on
  3737. if self.npcs[y][x].move_done == 0:
  3738. #casting flames
  3739. if 'close_flames' in ability_keys:
  3740. ran = random.randint(0,99)
  3741. if ran < self.npcs[y][x].ability['close_flames'] and self.npcs[y][x].num_special > 0:
  3742. #Step 0: Check if any (other) monsters are near by
  3743. sfx.play('flame')
  3744. monster_num = 0
  3745. for yy in range(y-1,y+2):
  3746. for xx in range(x-1,x+2):
  3747. if self.npcs[yy][xx] != 0:
  3748. monster_num += 1
  3749. if monster_num == 1:#there is no other monster near by
  3750. num_flames = 0
  3751. for yyy in range(y-1,y+2):
  3752. for xxx in range(x-1,x+2):
  3753. if xxx != x or yyy != y:
  3754. 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':
  3755. replace = self.tilemap[yyy][xxx]
  3756. self.tilemap[yyy][xxx] = deepcopy(tl.tlist['effect'][4])
  3757. self.tilemap[yyy][xxx].replace = replace
  3758. self.countdowns.append(countdown('flame',xxx,yyy,3))
  3759. num_flames+=1
  3760. if num_flames > 0:
  3761. flame_string = 'A '+ self.npcs[y][x].name + ' casts a flame spell!'
  3762. message.add(flame_string)
  3763. self.npcs[y][x].num_special -= 1
  3764. self.npcs[y][x].move_done = 1
  3765. if self.npcs[y][x].move_done == 0 and self.npcs[y][x].num_special > 0:
  3766. #vampirism
  3767. if 'close_vampirism' in ability_keys:
  3768. ran = random.randint(0,99)
  3769. if ran < self.npcs[y][x].ability['close_vampirism']:
  3770. player.lp -= 1
  3771. self.npcs[y][x].lp += 1
  3772. screen.write_hit_matrix(player.pos[0],player.pos[1],18)
  3773. screen.write_hit_matrix(x,y,19)
  3774. sfx.play('vampire')
  3775. vamp_string = 'A ' + self.npcs[y][x].name +' sucks your blood.'
  3776. message.add(vamp_string)
  3777. self.npcs[y][x].num_special -= 1
  3778. self.npcs[y][x].move_done = 1
  3779. if self.npcs[y][x].move_done == 0 and self.npcs[y][x].num_special > 0:
  3780. #steal items
  3781. if 'close_stealItem' in ability_keys:
  3782. ran = random.randint(0,99)
  3783. if ran < self.npcs[y][x].ability['close_stealItem']:
  3784. #0: Find parent
  3785. parent_pos = False
  3786. parent_id = self.npcs[y][x].personal_id.replace('_child','')
  3787. for yy in range(0,max_map_size):
  3788. for xx in range(0,max_map_size):
  3789. if self.npcs[yy][xx] != 0 and self.npcs[yy][xx].personal_id == parent_id:
  3790. parent_pos = (xx,yy)
  3791. #1: Check Parent Status
  3792. if parent_pos != False:
  3793. if len(self.containers[parent_pos[1]][parent_pos[0]].items) < 7:
  3794. p_check = True
  3795. else:
  3796. p_check = False
  3797. #2: Steal Item
  3798. if p_check == True:
  3799. all_bp = ('Head','Body','Legs','Feet','Hold(R)','Hold(L)','Neck','Axe','Pickaxe','Hand')
  3800. final_bp = ['None',]
  3801. for i in range(0,len(all_bp)-1):
  3802. if player.inventory.wearing[all_bp[i]] != player.inventory.nothing:
  3803. final_bp.append(all_bp[i])
  3804. del final_bp[0]
  3805. if len(final_bp) > 0:
  3806. if len(final_bp) == 1:
  3807. ran = 0
  3808. else:
  3809. ran = random.randint(0,len(final_bp)-1)
  3810. item = player.inventory.wearing[final_bp[ran]]
  3811. player.inventory.wearing[final_bp[ran]] = player.inventory.nothing
  3812. self.containers[parent_pos[1]][parent_pos[0]].items.append(item)
  3813. mes = 'A '+self.npcs[y][x].name+' steals your '+item.name+'!'
  3814. message.add(mes)
  3815. sfx.play('steal')
  3816. screen.write_hit_matrix(player.pos[0],player.pos[1],21)
  3817. screen.write_hit_matrix(parent_pos[0],parent_pos[1],22)
  3818. self.npcs[y][x].lp = 0
  3819. if self.npcs[y][x].move_done == 0 and self.npcs[y][x].num_special > 0:
  3820. #throw explosives
  3821. if 'close_throwExplosive' in ability_keys:
  3822. ran = random.randint(0,99)
  3823. if ran < self.npcs[y][x].ability['close_throwExplosive']:
  3824. positions = []
  3825. for yy in range(player.pos[1]-1,player.pos[1]+2):
  3826. for xx in range(player.pos[0]-1,player.pos[0]+2):
  3827. if self.tilemap[yy][xx].replace == None and self.tilemap[yy][xx].move_group == 'soil' and self.tilemap[yy][xx].use_group == 'None':
  3828. positions.append((xx,yy))
  3829. if len(positions) > 0:
  3830. sfx.play('throw')
  3831. screen.write_hit_matrix(x,y,20)
  3832. ran = random.randint(0,len(positions)-1)
  3833. pos = positions[ran]
  3834. screen.write_hit_matrix(pos[0],pos[1],16)
  3835. coin = random.randint(0,3)
  3836. if coin == 0:
  3837. message.add('A '+self.npcs[y][x].name+' throws a bomb!')
  3838. replace = self.tilemap[pos[1]][pos[0]]
  3839. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['effect'][0])
  3840. self.countdowns.append(countdown('bomb3',pos[0],pos[1],1))
  3841. self.tilemap[pos[1]][pos[0]].replace = replace
  3842. else:
  3843. message.add('A '+self.npcs[y][x].name+' throws an explosive!')
  3844. replace = self.tilemap[pos[1]][pos[0]]
  3845. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['effect'][7])
  3846. self.tilemap[pos[1]][pos[0]].replace = replace
  3847. self.npcs[y][x].move_done = 1
  3848. self.npcs[y][x].num_special -= 1
  3849. if self.npcs[y][x].move_done == 0 and los == True:
  3850. try:
  3851. player.monster_attacks(x,y)
  3852. except:
  3853. None
  3854. self.npcs[y][x].move_done = 1#set the move_done switch on
  3855. elif AI_style == 'flee':
  3856. if distances[0] > 4: #moves[0] is always the position of the monster right now, so distances 0 is always it's distance towards the player
  3857. if len(moves) > 1:
  3858. ran = random.randint(0,len(moves)-1)
  3859. else:
  3860. ran = 0
  3861. do_move = moves[ran]
  3862. else:
  3863. if len(moves) > 0:#if no move is possible at least the 'move' of stay still must remain
  3864. good_moves = []
  3865. for k in range (0, len(moves)):
  3866. 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
  3867. good_moves.append(moves[k])
  3868. else:
  3869. good_moves = moves
  3870. if len(good_moves) == 0:
  3871. good_moves = moves
  3872. if len(good_moves) > 1:
  3873. ran = random.randint(0,len(good_moves)-1)
  3874. else:
  3875. ran = 0
  3876. do_move = good_moves[ran]
  3877. elif AI_style == 'ignore':
  3878. ability_keys = self.npcs[y][x].ability.keys()
  3879. if self.npcs[y][x].move_done == 0:
  3880. if 'produce_egg' in ability_keys:
  3881. ran = random.randint(0,999)
  3882. if ran < self.npcs[y][x].ability['produce_egg'] and self.tilemap[y][x].replace == None:
  3883. replace = self.tilemap[y][x]
  3884. self.tilemap[y][x] = deepcopy(tl.tlist['functional'][33])
  3885. self.tilemap[y][x].replace = replace
  3886. if self.npcs[y][x].move_done == 0:
  3887. if len(moves) > 1:
  3888. ran = random.randint(0,len(moves)-1)
  3889. else:
  3890. ran = 0
  3891. do_move = moves[ran]
  3892. elif self.npcs[y][x].AI_style == 'company':
  3893. ability_keys = self.npcs[y][x].ability.keys()
  3894. if self.npcs[y][x].move_done == 0:
  3895. if 'attack_monster' in ability_keys:
  3896. monsters_list = []
  3897. for yy in range (y-1,y+2):
  3898. if self.npcs[yy][x] != 0 and self.npcs[yy][x].AI_style == 'hostile':
  3899. monsters_list.append([x,yy])
  3900. for xx in range(x-1,x+2):
  3901. if self.npcs[y][xx] != 0 and self.npcs[y][xx].AI_style == 'hostile':
  3902. monsters_list.append([xx,y])
  3903. if len(monsters_list) > 0:
  3904. if len(monsters_list) == 1:
  3905. ran = 0
  3906. else:
  3907. ran = random.randint(0,len(monsters_list)-1)
  3908. xxx = monsters_list[ran][0]
  3909. yyy = monsters_list[ran][1]
  3910. rand = random.randint(0,99)
  3911. if 'eat_monster' in ability_keys:
  3912. if rand < self.npcs[y][x].ability['eat_monster']:
  3913. mes = self.npcs[y][x].name + ' [eats] ' + self.npcs[yyy][xxx].name
  3914. message.add(mes)
  3915. sfx.play('eat')
  3916. self.npcs[yyy][xxx] = 0
  3917. self.npcs[y][x].move_done = 1
  3918. if rand < self.npcs[y][x].ability['attack_monster'] and self.npcs[y][x].move_done == 0:
  3919. mes = self.npcs[y][x].name + ' [hits] ' + self.npcs[yyy][xxx].name
  3920. message.add(mes)
  3921. self.npcs[yyy][xxx].lp -= 1
  3922. screen.write_hit_matrix(xxx,yyy,4)
  3923. sfx.play('hit')
  3924. if '-skill' in ability_keys and not '-skill' in self.npcs[yyy][xxx].properties:
  3925. self.npcs[yyy][xxx].properties.append('-skill')
  3926. if self.npcs[yyy][xxx].lp < 1:
  3927. self.monster_die(xxx,yyy)
  3928. self.npcs[y][x].move_done = 0
  3929. if self.npcs[y][x].move_done == 0:
  3930. if 'light' in ability_keys:
  3931. time_night = False
  3932. if time.hour < 6 or time.hour > 19:
  3933. time_night = True
  3934. if time_night == True or player.pos[2] > 0:
  3935. player.buffs.set_buff('light',1,False)
  3936. if self.npcs[y][x].move_done == 0:
  3937. if 'blind' in ability_keys:
  3938. monsters_list = []
  3939. for yy in range (y-1,y+2):
  3940. if self.npcs[yy][x] != 0 and self.npcs[yy][x].AI_style == 'hostile' and not 'blind' in self.npcs[yy][x].properties:
  3941. monsters_list.append([x,yy])
  3942. for xx in range(x-1,x+2):
  3943. if self.npcs[y][xx] != 0 and self.npcs[y][xx].AI_style == 'hostile' and not 'blind' in self.npcs[y][xx].properties:
  3944. monsters_list.append([xx,y])
  3945. if len(monsters_list) > 0:
  3946. if len(monsters_list) == 1:
  3947. ran = 0
  3948. else:
  3949. ran = random.randint(0,len(monsters_list)-1)
  3950. xxx = monsters_list[ran][0]
  3951. yyy = monsters_list[ran][1]
  3952. rand = random.randint(0,99)
  3953. if rand < self.npcs[y][x].ability['blind']:
  3954. mes = self.npcs[y][x].name + ' [blinds] ' + self.npcs[yyy][xxx].name
  3955. message.add(mes)
  3956. self.npcs[yyy][xxx].properties.append('blind')
  3957. self.npcs[y][x].move_done = 1
  3958. #IV. Move the monster
  3959. if do_move != 'foo':
  3960. border = random.randint(1,9)
  3961. if border > self.npcs[y][x].move_border:
  3962. self.npcs[y][x].move_done = 1#set the move_done switch on
  3963. helper = self.npcs[y][x]#copy the monster
  3964. self.npcs[y][x] = 0 #del the monster at the old position
  3965. self.npcs[do_move[1]][do_move[0]] = helper# set monster to the new position
  3966. def monster_die(self,x,y,xp = None):
  3967. #this function is called when the player kills a monster. the x and the y variables are to define the location of the monster
  3968. monster_x = x
  3969. monster_y = y
  3970. real_drop = False
  3971. if self.tilemap[y][x].replace == None:
  3972. test_replace = True
  3973. else:
  3974. test_replace = False
  3975. if self.npcs[monster_y][monster_x].corps_style == 'make_blobs':
  3976. test_replace = True
  3977. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' vanishes!'
  3978. if test_replace != True or self.tilemap[y][x].drops_here != True:
  3979. location_list = [(monster_x,monster_y),]
  3980. for yy in range(y-1,y+2):
  3981. for xx in range(x-1,x+2):
  3982. if self.tilemap[yy][xx].replace == None and self.npcs[yy][xx] == 0:
  3983. test_replace = True
  3984. else:
  3985. test_replace = False
  3986. if test_replace == True and self.tilemap[yy][xx].drops_here and self.tilemap[yy][xx].move_group == 'soil' and self.containers[yy][xx] == 0:
  3987. location_list.append((xx,yy))
  3988. if len(location_list) > 1:
  3989. del location_list[0]
  3990. if len(location_list) == 1:
  3991. x = location_list[0][0]
  3992. y = location_list[0][1]
  3993. else:
  3994. ran = random.randint(0,len(location_list)-1)
  3995. x = location_list[ran][0]
  3996. y = location_list[ran][1]
  3997. if test_replace == True and self.tilemap[y][x].drops_here: #only on empty fields corps can be spawned
  3998. 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
  3999. coin = random.randint(0,99)
  4000. if coin < 50:#there is a chance of 50%
  4001. replace = self.tilemap[y][x]
  4002. self.tilemap[y][x] = tl.tlist['local'][10]#<---sepling
  4003. self.tilemap[y][x].replace = replace
  4004. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' turns into a new tree!'
  4005. 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
  4006. coin = random.randint(0,99)
  4007. if coin < 50:#there is a chance of 50%
  4008. replace = self.tilemap[y][x]
  4009. self.tilemap[y][x] = deepcopy(tl.tlist['local'][14])#<---rock
  4010. self.tilemap[y][x].replace = replace
  4011. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' turns to stone!'
  4012. 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
  4013. coin = random.randint(0,99)
  4014. if coin < 15:#there is a chance of 15%
  4015. real_drop = True
  4016. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' dies!'
  4017. replace = self.tilemap[y][x]
  4018. self.tilemap[y][x] = deepcopy(tl.tlist['functional'][6])#<--humanoid remains
  4019. self.tilemap[y][x].replace = replace
  4020. items = []
  4021. max_items = max(1,self.npcs[monster_y][monster_x].corps_lvl)
  4022. for i in range (0, max_items):
  4023. #possible drops of a humanoid monster are equipment items and food items
  4024. coin = random.randint(0,99)
  4025. if coin < 65: #there is a chance of 65% that a item becomes a eqipment item
  4026. material = random.randint(0,20) #all materials are allowed
  4027. classes = ('spear','sword','axe','hammer','shoes','cuisse','helmet','armor','wand','rune','rune staff','artefact','ring','amulet','necklace','talisman','pickaxe')
  4028. kind = classes[random.randint(0,len(classes)-1)]#all classes of objects are allowed
  4029. plus = random.randint(-2,+2)# a plus between -2 and +2 is possible
  4030. state = random.randint(10,85)#the state of this used objects will always be between 10% and 80%
  4031. curse_chance = random.randint(0,30)
  4032. if curse_chance < material:
  4033. curse = 0
  4034. elif curse_chance == material:
  4035. curse = 2
  4036. else:
  4037. curse = 1
  4038. item = item_wear(kind,material,plus,state,curse)
  4039. elif coin < 68: #there is a chance of 3% to drop a simple blueprint
  4040. blueprint = random.randint(15,20)
  4041. item = deepcopy(il.ilist['misc'][blueprint])
  4042. elif coin < 80: #there is a chance of 12% to drop a torch or a throwable:
  4043. 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])
  4044. ran = random.randint(0,len(item_list)-1)
  4045. item = deepcopy(item_list[ran])
  4046. else:
  4047. coin2 = random.randint(0,1)
  4048. if coin == 1:
  4049. item = deepcopy(il.ilist['food'][random.randint(0,len(il.ilist['food'])-1)])
  4050. else:
  4051. item_list = (il.ilist['misc'][74],il.ilist['misc'][75],il.ilist['misc'][76],il.ilist['misc'][77])
  4052. ran = random.randint(0,len(item_list)-1)
  4053. item = deepcopy(item_list[ran])
  4054. items.append(item)
  4055. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  4056. 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
  4057. coin = random.randint(0,99)
  4058. if coin < 15:#there is a chance of 15%
  4059. real_drop = True
  4060. replace = self.tilemap[y][x]
  4061. self.tilemap[y][x] = deepcopy(tl.tlist['functional'][21])#<--animal remains
  4062. self.tilemap[y][x].replace = replace
  4063. items = []
  4064. max_items = max(1,self.npcs[monster_y][monster_x].corps_lvl)
  4065. for i in range (0, max_items):
  4066. #animals drop flesh. the corpslvl says how much
  4067. items.append(deepcopy(il.ilist['food'][9]))#<---raw meat
  4068. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  4069. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' dies!'
  4070. 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
  4071. coin = random.randint(0,99)
  4072. if coin < 10:#there is a chance of 10%
  4073. real_drop = True
  4074. die_mess = 'The ' + self.npcs[monster_y][monster_x].name + ' dies!'
  4075. replace = self.tilemap[y][x]
  4076. self.tilemap[y][x] = deepcopy(tl.tlist['functional'][6])#<--humanoid remains
  4077. self.tilemap[y][x].replace = replace
  4078. items = []
  4079. max_items = max(1,self.npcs[monster_y][monster_x].corps_lvl)
  4080. for i in range (0, max_items):
  4081. #possible drops of a scrollkeeper are scrolls and spellbooks
  4082. coin = random.randint(0,99)
  4083. if coin < 75: #there is a chance of 75% that a item becomes a scroll
  4084. 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],il.ilist['misc'][82])
  4085. ran = random.randint(0,len(scrolls)-1)
  4086. item = deepcopy(scrolls[ran])
  4087. else:
  4088. 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],il.ilist['misc'][83])
  4089. ran = random.randint(0,len(books)-1)
  4090. item = deepcopy(books[ran])
  4091. items.append(item)
  4092. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  4093. elif self.npcs[monster_y][monster_x].corps_style == 'miner':
  4094. if self.npcs[monster_y][monster_x].techID == ml.mlist['special'][0].techID:#this is a vase
  4095. die_mess = 'The vase shatters.'
  4096. ran = random.randint(0,99)
  4097. if ran <= self.npcs[monster_y][monster_x].corps_lvl: #for miners the corps_lvl determinates the chance of getting a gem
  4098. real_drop = True
  4099. replace = self.tilemap[y][x]
  4100. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][9])#set a lost gem
  4101. self.tilemap[y][x].replace = replace
  4102. 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
  4103. real_drop = True
  4104. replace = self.tilemap[y][x]
  4105. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][11])#set a lost ore
  4106. self.tilemap[y][x].replace = replace
  4107. elif self.npcs[monster_y][monster_x].corps_style == 'thief':
  4108. if self.tilemap[y][x].replace == None and self.npcs[monster_y][monster_x].corps_lvl > 0:
  4109. real_drop = True
  4110. replace = self.tilemap[y][x]
  4111. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][9])#set a lost gem
  4112. self.tilemap[y][x].replace = replace
  4113. 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
  4114. elif self.npcs[monster_y][monster_x].corps_style == 'reset_parent':
  4115. parent_id = self.npcs[monster_y][monster_x].personal_id.replace('_child','')
  4116. for yy in range(0,max_map_size):
  4117. for xx in range(0,max_map_size):
  4118. if self.npcs[yy][xx] != 0:
  4119. if self.npcs[yy][xx].personal_id == parent_id:
  4120. self.npcs[yy][xx].num_special += 1
  4121. elif self.npcs[monster_y][monster_x].corps_style == 'kill_childs':
  4122. child_id = self.npcs[monster_y][monster_x].personal_id + '_child'
  4123. for yy in range(0,max_map_size):
  4124. for xx in range(0,max_map_size):
  4125. if self.npcs[yy][xx] != 0:
  4126. if self.npcs[yy][xx].personal_id == child_id:
  4127. self.npcs[yy][xx] = 0
  4128. elif self.npcs[monster_y][monster_x].corps_style == 'kobold_fear':
  4129. for yy in range(y-7,y+8):
  4130. for xx in range(x-7,x+8):
  4131. try:
  4132. if self.npcs[yy][xx].techID == ml.mlist['kobold'][1].techID and self.npcs[yy][xx].name != 'frightened kobold':
  4133. self.npcs[yy][xx] = deepcopy(self.npcs[yy][xx])#only to be sure
  4134. self.npcs[yy][xx].name = 'frightened kobold'
  4135. self.npcs[yy][xx].sprite_pos = (5,3)
  4136. self.npcs[yy][xx].basic_attribute.p_strength = int(self.npcs[yy][xx].basic_attribute.p_strength*0.6)
  4137. self.npcs[yy][xx].basic_attribute.m_strength = int(self.npcs[yy][xx].basic_attribute.m_strength*0.6)
  4138. self.npcs[yy][xx].basic_attribute.p_defense = int(self.npcs[yy][xx].basic_attribute.p_defense*0.6)
  4139. self.npcs[yy][xx].basic_attribute.m_defense = int(self.npcs[yy][xx].basic_attribute.m_defense*0.6)
  4140. screen.write_hit_matrix(xx,yy,17)
  4141. coin = random.randint(0,1)
  4142. if coin == 1:
  4143. self.npcs[yy][xx].AI_style = 'flee'
  4144. except:
  4145. None
  4146. elif self.npcs[monster_y][monster_x].corps_style == 'vase':
  4147. die_mess = 'The vase shatters and monsters jump out.'
  4148. monster_count = 0
  4149. for yy in range(y-1,y+2):
  4150. for xx in range(x-1,x+2):
  4151. if yy != player.pos[1] or xx!= player.pos[0]:
  4152. if self.npcs[yy][xx] == 0 and self.tilemap[yy][xx].move_group == 'soil' and self.tilemap[yy][xx].damage == 0:
  4153. self.npcs[yy][xx] = deepcopy(ml.mlist['special'][2])#set vase monsters
  4154. self.set_monster_strength(xx,yy,player.pos[2])
  4155. if player.difficulty == 4:
  4156. self.npcs[yy][xx].AI_style = 'ignore'
  4157. monster_count += 1
  4158. if monster_count > 0:
  4159. die_mess = 'The vase shatters and '+str(monster_count)+' monsters jump out.'
  4160. else:
  4161. die_mess = 'The vase shatters.'
  4162. elif self.npcs[monster_y][monster_x].corps_style == 'mimic':
  4163. die_mess = 'The mimic wakes up.'
  4164. elif self.npcs[monster_y][monster_x].corps_style == 'cage':
  4165. die_mess = 'You smash the cage!'
  4166. sfx.play('destroy_cage')
  4167. elif self.npcs[monster_y][monster_x].corps_style == 'make_blobs':
  4168. counter = 0
  4169. blob_lvl = max(self.npcs[monster_y][monster_x].lvl-1,0)
  4170. for yy in range(y-1,y+2):
  4171. for xx in range(x-1,x+2):
  4172. if yy != y or xx != x:
  4173. not_player_pos = yy != player.pos[1] or xx != player.pos[0]
  4174. if self.tilemap[yy][xx].move_group == 'soil' and not_player_pos == True and self.npcs[yy][xx] == 0:
  4175. self.npcs[yy][xx] = deepcopy(ml.mlist['special'][15])#set a green blob
  4176. self.set_monster_strength(xx,yy,player.pos[2],preset_lvl=blob_lvl)
  4177. if player.difficulty == 4:
  4178. self.npcs[yy][xx].AI_style = 'ignore'
  4179. counter += 1
  4180. if counter == 1:
  4181. die_mess = 'The giant blob leaves behind a small blob.'
  4182. elif counter > 1:
  4183. die_mess = 'The giant blob bursts into '+str(counter)+' small blobs.'
  4184. elif self.npcs[monster_y][monster_x].corps_style == 'vanish':
  4185. ran = random.randint(0,99)
  4186. if ran <= self.npcs[monster_y][monster_x].corps_lvl: #the corps_lvl determinates the chance of getting a present
  4187. real_drop = True
  4188. replace = self.tilemap[y][x]
  4189. self.tilemap[y][x] = deepcopy(tl.tlist['misc'][13])#set a present
  4190. self.tilemap[y][x].replace = replace
  4191. item_ran = random.randint(0,99)
  4192. if item_ran < 25:
  4193. items = [il.ilist['misc'][43]]#set a heavy bag
  4194. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  4195. elif item_ran < 50:
  4196. choose_ran = random.randint(0,len(il.ilist['clothe'])-1)
  4197. items = [il.ilist['clothe'][choose_ran]]
  4198. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  4199. elif item_ran < 95:
  4200. r = random.randint(3,7)
  4201. items = [il.ilist['misc'][r]]#set a workbench
  4202. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  4203. else:
  4204. items = [il.ilist['misc'][70]]#set a book of skill
  4205. self.add_container(items,x,y,deep_copy=True,checkIt=True)
  4206. ############ADD MORE HERE###############
  4207. if real_drop == True:
  4208. screen.write_hit_matrix(x,y,16)
  4209. if self.npcs[monster_y][monster_x].move_border < 10:
  4210. screen.write_hit_matrix(monster_x,monster_y,13)
  4211. if self.npcs[monster_y][monster_x].corps_style == 'mimic':
  4212. self.npcs[monster_y][monster_x] = deepcopy(ml.mlist['special'][4])#set a mimic
  4213. self.set_monster_strength(monster_x,monster_y,player.pos[2])
  4214. if player.difficulty == 4:
  4215. self.npcs[monster_y][monster_x].AI_style = 'ignore'
  4216. elif self.npcs[monster_y][monster_x].corps_style == 'cage':
  4217. self.npcs[monster_y][monster_x] = deepcopy(ml.mlist['rescued'][random.randint(0,len(ml.mlist['rescued'])-1)])
  4218. self.set_monster_strength(monster_x,monster_y,player.pos[2])
  4219. else:
  4220. self.npcs[monster_y][monster_x] = 0 #always del the monster if it is no mimic or cage
  4221. self.make_monsters_angry(monster_x,monster_y,'kill')
  4222. self.monster_count -= 1
  4223. if xp != None:
  4224. die_mess = die_mess + ' [+' + str(xp) + 'xp]'
  4225. message.add(die_mess)
  4226. return True
  4227. def make_shops(self):
  4228. num = int((max_map_size*max_map_size) / (50*50))
  4229. for i in range (0,num):
  4230. run = True
  4231. while run:
  4232. poses = self.find_all_moveable(False,False)
  4233. ran = random.randint(0,len(poses)-1)
  4234. pos = poses[ran]
  4235. if min(pos[0],pos[1]) > 4 and max(pos[0],pos[1]) < max_map_size-4:
  4236. run = False
  4237. x = pos[0]
  4238. y = pos[1]
  4239. for yy in range(y-2,y+3):
  4240. for xx in range(x-2,x+3):
  4241. self.npcs[yy][xx] = 0 #always del the monsters
  4242. if xx == x-2 or xx == x+2 or yy == y-2 or yy == y+2:
  4243. self.tilemap[yy][xx] = deepcopy(tl.tlist['shop'][1])
  4244. else:
  4245. self.tilemap[yy][xx] = deepcopy(tl.tlist['shop'][0])
  4246. self.tilemap[y][x-2] = deepcopy(tl.tlist['shop'][2])
  4247. self.tilemap[y][x+2] = deepcopy(tl.tlist['shop'][2])
  4248. self.tilemap[y-2][x] = deepcopy(tl.tlist['shop'][2])
  4249. self.tilemap[y+2][x] = deepcopy(tl.tlist['shop'][2])
  4250. if self.map_type == 'orcish_mines':
  4251. self.npcs[y][x] = deepcopy(ml.mlist['shop'][1])
  4252. elif self.map_type == 'grot':
  4253. self.npcs[y][x] = deepcopy(ml.mlist['shop'][2])
  4254. else:
  4255. 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
  4256. def make_monsters_angry(self,x,y,style):
  4257. for yy in range(y-3,y+4):
  4258. for xx in range(x-3,x+4):
  4259. try:
  4260. if self.npcs[yy][xx] != 0:
  4261. if self.npcs[yy][xx].anger == style:
  4262. lvl = self.npcs[yy][xx].lvl
  4263. self.npcs[yy][xx] = deepcopy(ml.mlist['angry_monster'][self.npcs[yy][xx].anger_monster])
  4264. self.set_monster_strength(xx,yy,player.pos[2],lvl)
  4265. if player.difficulty == 4:
  4266. self.npcs[yy][xx].AI_style = 'ignore'
  4267. except:
  4268. None
  4269. def time_pass(self):
  4270. #This function refresches the map for every day that past since players last visit... make plants growing etc.
  4271. if self.last_visit != time.day_total:
  4272. screen.render_load(10)
  4273. past_time = time.day_total - self.last_visit
  4274. if past_time < 0:
  4275. past_time = 364 - past_time
  4276. for c in range (0,past_time):
  4277. for y in range (0,max_map_size):
  4278. for x in range(0,max_map_size):
  4279. tile = self.tilemap[y][x]
  4280. #######Life of plants######
  4281. #1. Scrub
  4282. if tile.grow_group == 'scrub':
  4283. rand = random.randint(0,99)
  4284. if rand < 50:
  4285. replace = self.tilemap[y][x].replace
  4286. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  4287. self.tilemap[y][x].replace = replace
  4288. if tile.grow_group == 'scrub_buds':
  4289. rand = random.randint(0,99)
  4290. if rand < 90:
  4291. replace = self.tilemap[y][x].replace
  4292. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  4293. self.tilemap[y][x].replace = replace
  4294. if tile.grow_group == 'scrub_blossom':
  4295. rand = random.randint(0,99)
  4296. if rand < 80:
  4297. scrubs = random.randint(0,2)
  4298. replace = self.tilemap[y][x].replace
  4299. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[scrubs][0]][tile.conected_tiles[scrubs][1]])
  4300. self.tilemap[y][x].replace = replace
  4301. if tile.grow_group == 'scrub_berries':
  4302. rand = random.randint(0,99)
  4303. if rand < 50:
  4304. replace = self.tilemap[y][x].replace
  4305. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  4306. self.tilemap[y][x].replace = replace
  4307. elif rand > 49 and rand < 75:
  4308. numbers =(-1,1)
  4309. for yy in numbers:
  4310. for xx in numbers:
  4311. try:
  4312. if self.tilemap[y+yy][x+xx].can_grown == True:
  4313. coin = random.randint(0,99)
  4314. if coin < 25: #25%
  4315. replace = self.tilemap[y+yy][x+xx]
  4316. self.tilemap[y+yy][x+xx] = deepcopy([tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  4317. self.tilemap[y+yy][x+xx].replace = replace
  4318. except:
  4319. None
  4320. if tile.grow_group == 'scrub_scruffy':
  4321. rand = random.randint(0,99)
  4322. if rand < 90:
  4323. replace = self.tilemap[y][x].replace
  4324. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  4325. self.tilemap[y][x].replace = replace
  4326. else:
  4327. replace = self.tilemap[y][x].replace
  4328. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  4329. self.tilemap[y][x].replace = replace
  4330. if tile.grow_group == 'scrub_grow':
  4331. rand = random.randint(0,99)
  4332. if rand < 90:
  4333. replace = self.tilemap[y][x].replace
  4334. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  4335. self.tilemap[y][x].replace = replace
  4336. #2.Tree
  4337. if tile.grow_group == 'tree_grow':
  4338. rand = random.randint(0,99)
  4339. if rand < 80 and self.npcs[y][x] == 0:
  4340. replace = self.tilemap[y][x].replace
  4341. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  4342. self.tilemap[y][x].replace = replace
  4343. if tile.grow_group == 'tree':
  4344. rand = random.randint(0,99)
  4345. if rand < 5:
  4346. replace = self.tilemap[y][x].replace
  4347. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  4348. self.tilemap[y][x].replace = replace
  4349. elif rand > 69:
  4350. numbers =(-2,2)
  4351. for yy in numbers:
  4352. for xx in numbers:
  4353. try:
  4354. if self.tilemap[y+yy][x+xx].can_grown == True:
  4355. coin = random.randint(0,3)
  4356. if coin == 0:
  4357. replace = self.tilemap[y+yy][x+xx]
  4358. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  4359. self.tilemap[y+yy][x+xx].replace = replace
  4360. except:
  4361. None
  4362. #3.Herb
  4363. if tile.grow_group == 'herblike':
  4364. rand = random.randint(0,99)
  4365. if rand < 20:
  4366. replace = self.tilemap[y][x].replace
  4367. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  4368. self.tilemap[y][x].replace = replace
  4369. #4. Blue Mushrooms
  4370. if tile.grow_group == 'mushroom_mud':
  4371. rand = random.randint(0,99)
  4372. if rand < 5:
  4373. for yy in range(-1,1):
  4374. for xx in range(-1,1):
  4375. try:
  4376. if self.tilemap[y+yy][x+xx].techID == tl.tlist['misc'][1].techID:#here is mud
  4377. cent = random.randint(0,99)
  4378. if cent < 25 :
  4379. replace = self.tilemap[y+yy][x+xx]
  4380. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  4381. self.tilemap[y+yy][x+xx].replace = replace
  4382. except:
  4383. None
  4384. #5. Brown Mushrooms
  4385. if tile.grow_group == 'mushroom_treelike':
  4386. rand = random.randint(0,99)
  4387. if rand < 5:
  4388. for yy in range(-1,1):
  4389. for xx in range(-1,1):
  4390. try:
  4391. if self.tilemap[y+yy][x+xx].techID == tl.tlist['global_caves'][0].techID:#here is cave ground
  4392. cent = random.randint(0,99)
  4393. if cent < 25 :
  4394. replace = self.tilemap[y+yy][x+xx]
  4395. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]])
  4396. self.tilemap[y+yy][x+xx].replace = replace
  4397. except:
  4398. None
  4399. elif rand < 30:#make a giant mushroom
  4400. replace = self.tilemap[y][x].replace
  4401. self.tilemap[y][x] = deepcopy(tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]])
  4402. self.tilemap[y][x].replace = replace
  4403. #6. Purple Mushrooms
  4404. if tile.grow_group == 'mushroom': #let grow new mushrooms and let the old ones die(5%)
  4405. rand = random.randint(0,99)
  4406. if rand < 5:
  4407. for yy in range(-1,1):
  4408. for xx in range(-1,1):
  4409. try:
  4410. if self.tilemap[y+yy][x+xx].techID == tl.tlist['global_caves'][0].techID:#here is cave ground
  4411. cent = random.randint(0,99)
  4412. if cent < 25 :
  4413. replace = self.tilemap[y+yy][x+xx]
  4414. self.tilemap[y+yy][x+xx] = deepcopy(tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]])
  4415. self.tilemap[y+yy][x+xx].replace = replace
  4416. except:
  4417. None
  4418. #7. Agriculture
  4419. if tile.grow_group == 'agri0':
  4420. rand = random.randint(0,99)
  4421. if rand < 50:
  4422. if self.map_type == 'overworld':
  4423. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[0][0]][tile.conected_tiles[0][1]]
  4424. elif self.map_type == 'cave' or self.map_type == 'desert_cave':
  4425. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[1][0]][tile.conected_tiles[1][1]]
  4426. elif self.map_type == 'desert':
  4427. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[2][0]][tile.conected_tiles[2][1]]
  4428. if tile.grow_group == 'agri1': #let something grow on a acriculture (final, at the overworld) (50%)
  4429. rand = random.randint(0,99)
  4430. if rand < 50:
  4431. self.tilemap[y][x] = tl.tlist[tile.conected_tiles[0]][tile.conected_tiles[1]]
  4432. #8. Vanish
  4433. if tile.grow_group == 'vanish':
  4434. rand = random.randint(0,99)
  4435. if rand < 50:
  4436. self.tilemap[y][x] = self.tilemap[y][x].replace
  4437. self.containers[y][x] = 0
  4438. #9. Magic shops
  4439. if tile.techID == tl.tlist['shop'][4].techID and player.on_map != 'shop_0_0':
  4440. self.tilemap[y][x] = self.tilemap[y][x].replace
  4441. #######Misc#######
  4442. #0. Rubble
  4443. if tile.techID == tl.tlist['functional'][26].techID:
  4444. rand = random.randint(0,99)
  4445. if rand < 20:
  4446. count_rubble = 0
  4447. count_sand = 0
  4448. count_grass = 0
  4449. count_cave = 0
  4450. for yy in range(y-1,y+2):
  4451. for xx in range(x-1,x+2):
  4452. if self.tilemap[yy][xx].techID == tl.tlist['functional'][26]:#this is rubble
  4453. count_rubble += 1
  4454. elif self.tilemap[yy][xx].techID == tl.tlist['local'][0]:#this is grass
  4455. count_grass += 1
  4456. elif self.tilemap[yy][xx].techID == tl.tlist['extra'][0]:#this is sand
  4457. count_sand += 1
  4458. elif self.tilemap[yy][xx].techID == tl.tlist['global_caves'][0]:#this is cave
  4459. count_cave +=1
  4460. if count_rubble < 8: #this tile isnt surrounded by rubble
  4461. if count_cave > 1:
  4462. self.tilemap[y][x] = deepcopy(tl.tlist['global_caves'][0])
  4463. elif count_grass >= count_sand:
  4464. self.tilemap[y][x] = deepcopy(tl.tlist['local'][0])
  4465. else:
  4466. self.tilemap[y][x] = deepcopy(tl.tlist['extra'][0])
  4467. #1. nest box (with egg)
  4468. if tile.grow_group == 'hatch':
  4469. rand = random.randint(0,99)
  4470. if rand < 80 and self.npcs[y][x] == 0:
  4471. replace = self.tilemap[y][x].replace
  4472. self.tilemap[y][x] = deepcopy(tl.tlist['sanctuary'][4])
  4473. self.tilemap[y][x].replace = replace
  4474. pet_num = []
  4475. for i in range(0,len(ml.mlist['pet']),3):
  4476. pet_num.append(i)
  4477. ran = random.randint(0,len(pet_num)-1)
  4478. num = pet_num[ran]
  4479. self.npcs[y][x] = deepcopy(ml.mlist['pet'][num])
  4480. self.set_monster_strength(x,y,1)
  4481. #########add other events for growing plants etc here########
  4482. 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
  4483. for i in range(0,len(player.inventory.food)):#let the food rot in the players inventory
  4484. if player.inventory.food[i] != player.inventory.nothing:
  4485. player.inventory.food[i].rot()
  4486. if player.on_map != 'shop_0_0':
  4487. shop_num = int((max_map_size**2)/(50**2))
  4488. self.spawn_magic_shops(shop_num)
  4489. screen.render_load(5)
  4490. save(world,player,time,gods,save_path,os.sep)
  4491. def exchange(self,old_tile,new_tile,use_deepcopy=False):
  4492. for y in range (0,max_map_size):
  4493. for x in range (0,max_map_size):
  4494. if self.tilemap[y][x].techID == old_tile.techID:
  4495. if use_deepcopy == False:
  4496. self.tilemap[y][x] = new_tile
  4497. else:
  4498. self.tilemap[y][x] = deepcopy(new_tile)
  4499. def find_first(self,tile):
  4500. for y in range (0,max_map_size):
  4501. for x in range (0,max_map_size):
  4502. if self.tilemap[y][x].techID == tile.techID:
  4503. return [x,y]
  4504. if self.tilemap[y][x].name == tile.name:#fallback
  4505. return [x,y] #
  4506. return False
  4507. def find_any(self,tile):
  4508. found = []
  4509. for y in range(0,max_map_size):
  4510. for x in range(0,max_map_size):
  4511. if self.tilemap[y][x].techID == tile.techID and self.npcs[y][x] == 0:
  4512. found.append((x,y))
  4513. if found == []:
  4514. return False
  4515. elif len(found) == 1:
  4516. return found[0]
  4517. else:
  4518. ran = random.randint(0,len(found)-1)
  4519. return found[ran]
  4520. def find_all_moveable(self,ignore_water = True,ignore_player_pos = False, ignore_no_spawn = True):
  4521. cordinates_list = []
  4522. for y in range (0, max_map_size):
  4523. for x in range (0,max_map_size):
  4524. moveable = False
  4525. if ignore_water == True:
  4526. if self.tilemap[y][x].move_group == 'soil':
  4527. moveable = True
  4528. else:
  4529. if self.tilemap[y][x].move_group == 'soil' or self.tilemap[y][x].move_group == 'low_liquid':
  4530. moveable = True
  4531. if ignore_player_pos == True:
  4532. player_pos_check = False
  4533. else:
  4534. if (x - entrance_x < -7) or (y - entrance_y < -7) or (x - entrance_x > 7) or (y - entrance_y > 7):
  4535. player_pos_check = False
  4536. else:
  4537. player_pos_check = True
  4538. spawn_check = True
  4539. if ignore_no_spawn == False:
  4540. if self.tilemap[y][x].no_spawn == True:
  4541. spawn_check = False
  4542. 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:
  4543. cordinates_list.append((x,y))
  4544. if len(cordinates_list) > 0:
  4545. return cordinates_list
  4546. else:
  4547. return False
  4548. def add_container(self, inventory, x, y, deep_copy = True, checkIt = False):
  4549. self.containers[y][x] = container(inventory,deep_copy)
  4550. if checkIt == True:
  4551. if self.check_container(x,y) != True:
  4552. print('Container creation failed!')
  4553. self.containers[y][x] = 0
  4554. self.tilemap[y][x] = self.tilemap[y][x].replace
  4555. def check_container(self,x,y):
  4556. if self.tilemap[y][x].replace != None and len(self.containers[y][x].items) > 0:
  4557. return True
  4558. else:
  4559. return False
  4560. def special_check(self,x,y):
  4561. sfx_flame = False
  4562. sfx_vapor = False
  4563. for yy in range(y-7,y+8):
  4564. for xx in range(x-7,x+8):
  4565. try:
  4566. if (self.tilemap[yy][xx].special_group == 'flamable' or self.tilemap[yy][xx].special_group == 'highly flamable') and self.tilemap[yy][xx].replace != None:
  4567. heat_source = 0
  4568. for yyy in range(yy-1,yy+2):
  4569. for xxx in range(xx-1,xx+2):
  4570. try:
  4571. if self.tilemap[yyy][xxx].special_group == 'hot':
  4572. heat_source += 1
  4573. except:
  4574. None
  4575. if heat_source > 0:
  4576. if self.tilemap[yy][xx].special_group == 'flamable':
  4577. ran = random.randint(0,9)
  4578. else:
  4579. ran = 9
  4580. if ran > 5:
  4581. sfx_flame = True
  4582. self.containers[yy][xx] = 0
  4583. if world.maplist[player.pos[2]][player.on_map].npcs[yy][xx] != 0:
  4584. if world.maplist[player.pos[2]][player.on_map].npcs[yy][xx].techID == ml.mlist['special'][14].techID: #this is a demonic chest
  4585. world.maplist[player.pos[2]][player.on_map].monster_die(xx,yy)
  4586. self.countdowns.append(countdown('flame',xx,yy,self.tilemap[yy][xx].special_num))
  4587. replace = self.tilemap[yy][xx].replace
  4588. self.tilemap[yy][xx] = deepcopy(tl.tlist['effect'][4])
  4589. self.tilemap[yy][xx].replace = replace
  4590. elif self.tilemap[yy][xx].special_group == 'explosive' or self.tilemap[yy][xx].special_group == 'highly explosive':
  4591. heat_sources = 0
  4592. for yyy in range(yy-1,yy+2):
  4593. for xxx in range(xx-1,xx+2):
  4594. try:
  4595. if self.tilemap[yyy][xxx].special_group == 'hot':
  4596. heat_sources += 1
  4597. except:
  4598. None
  4599. if heat_sources > 0:
  4600. if self.tilemap[yyy][xxx].special_group == 'explosive':
  4601. ran = random.randint(0,9)
  4602. else:
  4603. ran = 9
  4604. if ran > 5:
  4605. self.countdowns.append(countdown('bomb1',xx,yy,1))
  4606. for yyy in range(yy-1,yy+2):
  4607. for xxx in range(xx-1,xx+2):
  4608. try:
  4609. if self.tilemap[yyy][xxx].special_group == 'explosive' or elf.tilemap[yyy][xxx].special_group == 'highly explosive':
  4610. self.countdowns.append(countdown('bomb1',xxx,yyy,1))
  4611. except:
  4612. None
  4613. elif self.tilemap[yy][xx].special_group == 'vaporable':
  4614. heat_sources = 0
  4615. for yyy in range(yy-1,yy+2):
  4616. for xxx in range(xx-1,xx+2):
  4617. try:
  4618. if self.tilemap[yyy][xxx].special_group == 'hot':
  4619. heat_sources += 1
  4620. except:
  4621. None
  4622. if heat_sources >= self.tilemap[yy][xx].special_num:
  4623. sfx.vapor = True
  4624. self.tilemap[yy][xx] = deepcopy(tl.tlist['misc'][1])#mud
  4625. except:
  4626. None
  4627. if sfx_flame == True:
  4628. sfx.play('flame')
  4629. if sfx_vapor == True:
  4630. sfx.play('steam')
  4631. def spawn_monster_groups(self,leader,follower,max_group_size):
  4632. for y in range(0,max_map_size):
  4633. for x in range(0,max_map_size):
  4634. if self.npcs[y][x] != 0 and self.npcs[y][x].techID == leader.techID:
  4635. m_count = 1
  4636. for yy in range(y-1,y+2):
  4637. for xx in range(x-1,x+2):
  4638. if m_count < max_group_size and self.npcs[yy][xx] == 0 and self.tilemap[yy][xx].move_group in follower.move_groups:
  4639. self.npcs[yy][xx] = deepcopy(follower)
  4640. self.set_monster_strength(xx,yy,max(self.npcs[y][x].lvl-5,1))
  4641. if player.difficulty == 4:
  4642. self.npcs[yy][xx].AI_style = 'ignore'
  4643. m_count += 1
  4644. def make_special_monsters(self, min_no, max_no, on_tile, depth, monster_type='vase'):
  4645. size = int((max_map_size*max_map_size)/(50*50))
  4646. for i in range(0,size):
  4647. num_monster = random.randint(min_no,max_no)
  4648. if num_monster > 0:
  4649. for z in range (0,num_monster):
  4650. pos = self.find_any(on_tile)
  4651. if monster_type == 'vase':
  4652. ran = random.randint(0,99)
  4653. if ran < 10:
  4654. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][1]) #spawn a monster vase
  4655. self.npcs[pos[1]][pos[0]].attribute = attribute(0,0,0,0,0,1,0)
  4656. else:
  4657. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][0]) #spawn a vase
  4658. self.npcs[pos[1]][pos[0]].attribute = attribute(0,0,0,0,0,1,0)
  4659. elif monster_type == 'mimic':
  4660. pos = self.find_any(on_tile)
  4661. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][3]) #spawn a sleeping mimic
  4662. self.npcs[pos[1]][pos[0]].attribute = attribute(0,0,0,0,0,1,0)
  4663. elif monster_type == 'demonic chest':
  4664. pos = self.find_any(on_tile)
  4665. self.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][4])#cest
  4666. self.tilemap[pos[1]][pos[0]].replace = deepcopy(on_tile)
  4667. 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],il.ilist['misc'][46],il.ilist['misc'][83])
  4668. ran1 = random.randint(0,len(sb)-1)
  4669. ran2 = random.randint(0,len(sb)-1)
  4670. items = [sb[ran1],sb[ran2]]
  4671. self.containers[pos[1]][pos[0]] = container(items,True)
  4672. self.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['special'][14])
  4673. self.set_monster_strength(pos[0],pos[1],depth)
  4674. #set monsters personal_id
  4675. 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))
  4676. def make_containers(self, min_no, max_no, on_tile, item_min, item_max, container_type='remains'):
  4677. size = int((max_map_size*max_map_size)/(50*50))
  4678. for i in range(0,size):
  4679. num_container = random.randint(min_no,max_no)
  4680. if num_container > 0:
  4681. for z in range (0,num_container):
  4682. c_type = container_type
  4683. if c_type == 'chest':
  4684. ch = random.randint(0,99)
  4685. if ch < 5:
  4686. c_type = 'fridge'
  4687. place = self.find_any(on_tile)
  4688. inventory = []
  4689. num_items = random.randint(item_min,item_max)##############item_min,item_max
  4690. for t in range (0,num_items):
  4691. if c_type == 'chest':
  4692. coin = random.randint(0,1)
  4693. if coin == 0:#add equipmen
  4694. classes = ['sword', 'axe', 'hammer', 'spear', 'helmet', 'armor', 'cuisse', 'shoes', 'wand', 'rune', 'rune staff', 'artefact', 'amulet', 'ring', 'talisman', 'necklace', 'pickaxe']
  4695. class_num = random.randint(0,len(classes)-1)
  4696. material = random.randint(0,20)
  4697. plus = random.randint(-3,3)
  4698. state = random.randint(80,100)
  4699. curse_chance = random.randint(0,30)
  4700. if curse_chance < material:
  4701. curse = 0
  4702. elif curse_chance == material:
  4703. curse = 2
  4704. else:
  4705. curse = 1
  4706. item = item_wear(classes[class_num], material, plus, state, curse, False)
  4707. inventory.append(item)
  4708. elif coin == 1:
  4709. items = []
  4710. for i in range(14,21):
  4711. items.append(il.ilist['misc'][i])
  4712. for i in range(22,40):
  4713. items.append(il.ilist['misc'][i])
  4714. for i in range(44,47):
  4715. items.append(il.ilist['misc'][i])
  4716. for j in range(6,9):
  4717. items.append(il.ilist['food'][j])
  4718. for j in range(13,25):
  4719. items.append(il.ilist['food'][j])
  4720. for j in range(29,32):
  4721. items.append(il.ilist['food'][j])
  4722. ran = random.randint(0,len(items)-1)
  4723. inventory.append(deepcopy(items[ran]))
  4724. elif c_type == 'remains':
  4725. classes = ['sword', 'axe', 'hammer', 'spear', 'helmet', 'armor', 'cuisse', 'shoes', 'wand', 'rune', 'rune staff', 'artefact', 'amulet', 'ring', 'talisman', 'necklace', 'pickaxe']
  4726. class_num = random.randint(0,len(classes)-1)
  4727. material = random.randint(0,20)
  4728. plus = random.randint(-3,3)
  4729. state = random.randint(20,60)
  4730. curses = (0,1,2)
  4731. curse_num = random.randint(0,2)
  4732. item = item_wear(classes[class_num], material, plus, state, curses[curse_num], False)
  4733. inventory.append(item)
  4734. elif c_type == 'fridge':
  4735. ran = random.randint(0,len(il.ilist['food'])-1)
  4736. inventory.append(deepcopy(il.ilist['food'][ran]))
  4737. if c_type == 'chest':
  4738. self.add_container(inventory, place[0], place[1])
  4739. replace = self.tilemap[place[1]][place[0]]
  4740. self.tilemap[place[1]][place[0]] = deepcopy(tl.tlist['functional'][4])#chest
  4741. self.tilemap[place[1]][place[0]].replace = replace
  4742. elif c_type == 'remains':
  4743. replace_tile = self.tilemap[place[1]][place[0]]
  4744. self.add_container(inventory, place[0], place[1])
  4745. self.tilemap[place[1]][place[0]] = deepcopy(tl.tlist['functional'][6])#remains
  4746. self.tilemap[place[1]][place[0]].replace = replace_tile
  4747. elif c_type == 'fridge':
  4748. replace_tile = self.tilemap[place[1]][place[0]]
  4749. self.add_container(inventory, place[0], place[1])
  4750. self.tilemap[place[1]][place[0]] = deepcopy(tl.tlist['functional'][25])#fridge
  4751. self.tilemap[place[1]][place[0]].replace = replace_tile
  4752. def exchange_when_surrounded(self, tile_check, tile_replace, number_neighbors):
  4753. #check all cordinates for their neighbors(including them self) and exchange th tile when the number of neighbors with the same techID => number_neighbors
  4754. for y in range (0,max_map_size):
  4755. for x in range (0,max_map_size):
  4756. count = 0
  4757. for yy in range (-1,2):
  4758. for xx in range (-1,2):
  4759. try:
  4760. if self.tilemap[y+yy][x+xx].techID == tile_check.techID or self.tilemap[y+yy][x+xx].techID == tile_replace.techID:
  4761. count += 1
  4762. except:
  4763. None
  4764. if count >= number_neighbors:
  4765. self.tilemap[y][x] = tile_replace
  4766. def sget(self):
  4767. string = ''
  4768. for c in range (0,max_map_size):
  4769. for d in range (0,max_map_size):
  4770. if d != player.pos[0] or c != player.pos[1]:
  4771. if self.known[c][d] != 0:
  4772. string = string + self.tilemap[c][d].char
  4773. else:
  4774. string += '\033[0;30;40m '
  4775. else:
  4776. string = string + player.char
  4777. string = string + '\n'
  4778. return string
  4779. def spawn_magic_shops(self,num=1):
  4780. if self.name == 'shop_0_0':
  4781. return False
  4782. pos = []
  4783. for i in range(0,num):
  4784. for y in range(0,max_map_size):
  4785. for x in range(0,max_map_size):
  4786. if self.tilemap[y][x].move_group == 'solid':
  4787. num_soil = 0
  4788. try:
  4789. if self.tilemap[y-1][x].move_group == 'soil':
  4790. num_soil += 1
  4791. except:
  4792. None
  4793. try:
  4794. if self.tilemap[y+1][x].move_group == 'soil':
  4795. num_soil += 1
  4796. except:
  4797. None
  4798. try:
  4799. if self.tilemap[y][x-1].move_group == 'soil':
  4800. num_soil += 1
  4801. except:
  4802. None
  4803. try:
  4804. if self.tilemap[y][x+1].move_group == 'soil':
  4805. num_soil += 1
  4806. except:
  4807. None
  4808. if num_soil > 0:
  4809. pos.append((x,y))
  4810. if len(pos) < 1:
  4811. return False
  4812. ran = random.randint(0,len(pos)-1)
  4813. replace = deepcopy(self.tilemap[pos[ran][1]][pos[ran][0]])
  4814. self.tilemap[pos[ran][1]][pos[ran][0]] = deepcopy(tl.tlist['shop'][4])
  4815. self.tilemap[pos[ran][1]][pos[ran][0]].replace = replace
  4816. def set_sanctuary(self,startx,starty):
  4817. for y in range (starty-2, starty+3):
  4818. for x in range (startx-2, startx+3):
  4819. self.tilemap[y][x] = deepcopy(tl.tlist['sanctuary'][0])#sanctuary floor
  4820. if x == startx-2 or x == startx or x == startx+2:
  4821. if y == starty-2 or y == starty or y == starty+2:
  4822. self.tilemap[y][x] = deepcopy(tl.tlist['sanctuary'][1])#sanctuary pilar
  4823. self.tilemap[starty][startx] = deepcopy(tl.tlist['sanctuary'][2])#sanctuary spawn point
  4824. self.tilemap[starty-1][startx] = deepcopy(tl.tlist['functional'][20])#divine gift
  4825. self.tilemap[starty-1][startx].replace = tl.tlist['sanctuary'][0]
  4826. self.countdowns.append(countdown('gift_to_workbench',startx,starty-1,1))
  4827. material_pick = random.randint(0,10)
  4828. material_axe = random.randint(0,10)
  4829. material_amo = random.randint(0,10)
  4830. amo_classes = ('shoes','cuisse','armor','helmet')
  4831. ran = random.randint(0,3)
  4832. amo_class = amo_classes[ran]
  4833. pick = item_wear('pickaxe', material_pick,0)
  4834. axe = item_wear('axe',material_axe,0)
  4835. amo = item_wear(amo_class,material_amo,0)
  4836. ran_tunica = random.randint(0,2)
  4837. #original
  4838. 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)
  4839. #/original
  4840. # statue demo:
  4841. #list_t = [pick,axe]
  4842. #for f in range(55,70):
  4843. # list_t.append(il.ilist['misc'][f])
  4844. #self.add_container(list_t,startx,starty-1)
  4845. # 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)
  4846. # 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)
  4847. # 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)
  4848. self.tilemap[starty+1][startx] = deepcopy(tl.tlist['functional'][1])#stair down
  4849. self.tilemap[starty+1][startx].damage = -1
  4850. self.tilemap[starty+1][startx].damage_mes = 'Your wounds are cured.'
  4851. self.tilemap[starty+1][startx].build_here = False
  4852. self.tilemap[starty+1][startx].move_group = 'holy'
  4853. class world_class():
  4854. def __init__(self,tilelist):
  4855. global max_map_size
  4856. screen.render_load(0)
  4857. name = save_path + os.sep + 'world.data'
  4858. self.map_size = 52
  4859. self.startx = 0
  4860. self.starty = 0
  4861. try:
  4862. f = open(name, 'rb')
  4863. temp = p.load(f)
  4864. screen.render_load(1)
  4865. self.maplist = temp.maplist
  4866. self.map_size = temp.map_size
  4867. max_map_size = self.map_size
  4868. self.startx = temp.startx
  4869. self.starty = temp.starty
  4870. except:
  4871. screen.render_load(2)
  4872. self.maplist = []
  4873. for x in range (0,7):
  4874. self.maplist.append({})
  4875. screen.render_load(3)
  4876. pos = self.grassland_generator(0,0,30,80,5,int((max_map_size*max_map_size)/20))
  4877. self.startx = pos[0]
  4878. self.starty = pos[1]
  4879. self.cave_generator(4)
  4880. self.border_generator(6)
  4881. screen.render_load(5)
  4882. self.elysium_generator()
  4883. def default_map_generator(self, name, tiles, tilelist): #check if tilelist can be deleted
  4884. tilemap = []
  4885. for i in range (0,max_map_size):
  4886. tilemap.append([])
  4887. a = 0
  4888. for b in range (0,max_map_size):
  4889. ran_num = random.randint(0,len(tl.tlist[tiles])-1)
  4890. tilemap[a].append(tl.tlist[tiles][ran_num])
  4891. b = 0
  4892. for a in range (1,max_map_size):
  4893. ran_num = random.randint(0,len(tl.tlist[tiles])-1)
  4894. tilemap[a].append(tl.tlist[tiles][ran_num])
  4895. for a in range (1,max_map_size):
  4896. for b in range (1,max_map_size):
  4897. ran_same = random.randint(0,9)
  4898. if ran_same < 5 :
  4899. tilemap[a].append(tilemap[a-1][b])
  4900. elif ran_same < 8:
  4901. tilemap[a].append(tilemap[a][b-1])
  4902. else:
  4903. ran_num = random.randint(0,len(tl.tlist[tiles])-1)
  4904. tilemap[a].append(tl.tlist[tiles][ran_num])
  4905. m = maP(name ,tilemap)
  4906. return m
  4907. def border_generator(self,layer,style='default'):
  4908. if style == 'default':
  4909. cave_name = 'local_0_0'
  4910. elif style == 'desert':
  4911. cave_name = 'desert_0_0'
  4912. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  4913. m.map_type = 'border'
  4914. m.fill(tl.tlist['functional'][0])#fill with border
  4915. self.maplist[layer][cave_name] = m
  4916. def grot_generator(self,layer):
  4917. screen.render_load(15,1)
  4918. cave_name = 'dungeon_0_0'
  4919. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  4920. m.map_type = 'grot'
  4921. m.set_music('grot','grot',True)
  4922. m.build_type = 'None'
  4923. m.fill(tl.tlist['global_caves'][3])#fill with hard rock
  4924. 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
  4925. m.set_frame(tl.tlist['functional'][0])
  4926. chance_ore = layer*5
  4927. chance_gem = layer*3
  4928. screen.render_load(15,10)
  4929. for y in range (0,max_map_size):
  4930. for x in range (0,max_map_size):
  4931. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  4932. replace = m.tilemap[y][x].replace
  4933. coin = random.randint(0,1)
  4934. percent = random.randint(1,100)
  4935. if coin == 0 and percent <= chance_ore:
  4936. m.tilemap[y][x] = tl.tlist['misc'][4]#set ore here
  4937. m.tilemap[y][x].replace = replace
  4938. elif coin == 1 and percent <= chance_gem:
  4939. m.tilemap[y][x] = tl.tlist['misc'][5]#set gem here
  4940. m.tilemap[y][x].replace = replace
  4941. screen.render_load(15,40)
  4942. for y in range (0,max_map_size):
  4943. for x in range (0,max_map_size):
  4944. if m.tilemap[y][x].techID == tl.tlist['misc'][1].techID:#this is mud
  4945. cent = random.randint(0,99)
  4946. if cent < 10: #its a chance of 10% that a blue mushroom spawns here
  4947. replace = m.tilemap[y][x]
  4948. m.tilemap[y][x] = tl.tlist['misc'][6]
  4949. m.tilemap[y][x].replace = replace
  4950. m.containers[y][x] = container([deepcopy(il.ilist['food'][1])])
  4951. screen.render_load(15,75)
  4952. num_lilys = int(((max_map_size*max_map_size)/100)*3)
  4953. for i in range (0,num_lilys):
  4954. pos = m.find_any(tl.tlist['misc'][0])#find low wather
  4955. try:
  4956. coin = random.randint(0,1)
  4957. if coin == 0:
  4958. m.tilemap[pos[1]][pos[0]] = tl.tlist['misc'][10]#set a water lily
  4959. else:
  4960. m.tilemap[pos[1]][pos[0]] = tl.tlist['misc'][14]#set a water lily with blossom
  4961. except:
  4962. None
  4963. screen.render_load(15,90)
  4964. pos = m.find_any(tl.tlist['misc'][0])#find any low water tile
  4965. m.tilemap[pos[1]][pos[0]] = tl.tlist['dungeon'][15]#set stair up
  4966. entrance_x = pos[0]
  4967. entrance_y = pos[1]
  4968. for sy in range(pos[1]-4,pos[1]+5):
  4969. for sx in range(pos[0]-4,pos[0]+5):
  4970. try:
  4971. if m.tilemap[sy][sx].move_group == 'soil':
  4972. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  4973. m.tilemap[sy][sx].move_group == 'dry_entrance'
  4974. elif m.tilemap[sy][sx].move_group == 'low_liquid':
  4975. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  4976. m.tilemap[sy][sx].move_group == 'wet_entrance'
  4977. except:
  4978. None
  4979. m.make_shops()
  4980. m.spawn_monsters(3)
  4981. screen.render_load(15,99)
  4982. self.maplist[layer][cave_name] = m
  4983. def elfish_generator(self,layer):
  4984. screen.render_load(16,1)
  4985. map_name = 'fortress_0_0'
  4986. m = self.default_map_generator(map_name,'global_caves', tilelist)
  4987. m.map_type = 'elfish_fortress'
  4988. m.set_music('elfish_fortress','elfish_fortress',True)
  4989. m.no_monster_respawn = True
  4990. m.build_type = 'None'
  4991. m.fill(tl.tlist['elfish'][0])
  4992. for y in range (10, max_map_size-10,10):
  4993. ran = random.randint(0,3)
  4994. for yy in range (y-1,y+2):
  4995. if ran < 3:
  4996. m.imp_connect((0,max_map_size-1),(yy,yy),tl.tlist['elfish'][1],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4997. if ran < 3:
  4998. m.imp_connect((0,max_map_size-1),(y-2,y-2),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  4999. m.imp_connect((0,max_map_size-1),(y+2,y+2),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  5000. screen.render_load(16,10)
  5001. for x in range (10, max_map_size-10,10):
  5002. ran = random.randint(0,3)
  5003. for xx in range (x-1,x+2):
  5004. if ran < 3:
  5005. m.imp_connect((xx,xx),(0,max_map_size-1),tl.tlist['elfish'][1],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  5006. if ran < 3:
  5007. m.imp_connect((x-2,x-2),(0,max_map_size-1),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  5008. m.imp_connect((x+2,x+2),(0,max_map_size-1),tl.tlist['elfish'][3],tl.tlist['elfish'][1],tl.tlist['elfish'][1])
  5009. m.cut(2,max_map_size-3,2,max_map_size-3,tl.tlist['elfish'][3])
  5010. building_count = 0
  5011. run = True
  5012. screen.render_load(16,30)
  5013. while run:
  5014. pos=m.find_first(tl.tlist['elfish'][0])
  5015. if pos != False:
  5016. m.floating(pos[0],pos[1],tl.tlist['elfish'][5],tl.tlist['elfish'][3])#fill with help passive
  5017. building_count += 1
  5018. else:
  5019. run = False
  5020. m.exchange(tl.tlist['elfish'][5],tl.tlist['elfish'][0])
  5021. screen.render_load(16,50)
  5022. if building_count < 6:
  5023. return False #return false to make a loop if there are to less buildings inside the map
  5024. num_temples = int((float(building_count)/100)*10)
  5025. if num_temples == 0:
  5026. num_temples = 1
  5027. num_agriculture = int((float(building_count)/100)*10)
  5028. if num_agriculture == 0:
  5029. num_agriculture=1
  5030. num_meetingarea = int((float(building_count)/100)*10)
  5031. if num_meetingarea == 0:
  5032. num_meetingarea = 1
  5033. num_marketplace = int((float(building_count)/100)*10)
  5034. if num_marketplace == 0:
  5035. num_marketplace = 1
  5036. num_libaries = int((float(building_count)/100)*10)
  5037. if num_libaries == 0:
  5038. num_libaries = 1
  5039. num_dwellings = building_count-num_temples-num_agriculture-num_meetingarea-num_marketplace-num_libaries
  5040. screen.render_load(16,60)
  5041. m.cut(2,max_map_size-3,2,max_map_size-3,tl.tlist['elfish'][1])
  5042. for i in range(0,num_agriculture):
  5043. pos = m.find_any(tl.tlist['elfish'][0])#find any elfish_floor_indoor
  5044. m.floating(pos[0],pos[1],tl.tlist['elfish'][2],tl.tlist['elfish'][1])#replace this building with elfish_agriculture
  5045. for y in range(0,max_map_size,2):
  5046. for x in range(0,max_map_size):
  5047. if m.tilemap[y][x].techID == tl.tlist['elfish'][2].techID:#this is elfish agriculture
  5048. m.tilemap[y][x] = tl.tlist['misc'][0]#set low water
  5049. for y in range(0,max_map_size):
  5050. for x in range(0,max_map_size):
  5051. if m.tilemap[y][x].techID == tl.tlist['elfish'][2].techID:#this is elfish agriculture
  5052. coin = random.randint(0,10)
  5053. if coin == 1:
  5054. m.npcs[y][x] = deepcopy(ml.mlist['elfish_special'][2])#elfish farmer
  5055. m.set_monster_strength(x,y,1,lvl_bonus=5)
  5056. screen.render_load(16,65)
  5057. m.cut(2,max_map_size-3,2,max_map_size-3,tl.tlist['elfish'][3])
  5058. for i in range(0,num_marketplace):#set marketplaces
  5059. pos = m.find_any(tl.tlist['elfish'][0])#find any elfish_floor_indoor
  5060. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  5061. pos = m.find_first(tl.tlist['elfish'][4])
  5062. size = m.get_quarter_size(pos[0],pos[1])
  5063. for y in range(pos[1]+1,pos[1]+size[1]-1,2):
  5064. for x in range(pos[0]+1,pos[0]+size[0]-1,3):
  5065. m.npcs[y][x] = ml.mlist['shop'][0]
  5066. m.set_monster_strength(x,y,5)
  5067. m.exchange(tl.tlist['elfish'][4],tl.tlist['shop'][0])
  5068. screen.render_load(16,70)
  5069. for i in range(0,num_temples):
  5070. pos = m.find_any(tl.tlist['elfish'][0])#find any elfish_floor_indoor
  5071. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  5072. pos = m.find_first(tl.tlist['elfish'][4])
  5073. size = m.get_quarter_size(pos[0],pos[1])
  5074. for y in range(pos[1],pos[1]+size[1],2):
  5075. for x in range(pos[0],pos[0]+size[0],2):
  5076. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][22])
  5077. m.tilemap[y][x].replace = tl.tlist['elfish'][0]
  5078. m.tilemap[y][x].civilisation = False
  5079. m.tilemap[pos[1]+int(size[1]/2)][pos[0]+int(size[0]/2)] = deepcopy(tl.tlist['functional'][15])#set a altar
  5080. m.tilemap[pos[1]+int(size[1]/2)][pos[0]+int(size[0]/2)].replace = tl.tlist['elfish'][0]
  5081. m.tilemap[pos[1]+int(size[1]/2)][pos[0]+int(size[0]/2)].civilisation = False
  5082. m.npcs[pos[1]+int(size[1]/2)][pos[0]+int(size[0]/2)] = deepcopy(ml.mlist['elfish_special'][3])
  5083. m.set_monster_strength(pos[0]+int(size[0]/2),pos[1]+int(size[1]/2),1,lvl_bonus=5)
  5084. m.exchange(tl.tlist['elfish'][4],tl.tlist['elfish'][5])
  5085. screen.render_load(16,75)
  5086. for i in range(0,num_meetingarea):
  5087. pos = m.find_any(tl.tlist['elfish'][0])
  5088. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  5089. pos = m.find_first(tl.tlist['elfish'][4])
  5090. size = m.get_quarter_size(pos[0],pos[1])
  5091. m.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['elfish_special'][0]) #set elfish landlord
  5092. m.set_monster_strength(pos[0],pos[1],1,lvl_bonus=5)
  5093. for y in range(pos[1]+2,pos[1]+size[1]-2):
  5094. for x in range(pos[0]+2,pos[0]+size[0]-1,4):
  5095. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][16]) #set table
  5096. m.tilemap[y][x].replace = tl.tlist['elfish'][0]
  5097. m.tilemap[y][x].civilisation = False
  5098. for xx in range(x-1,x+2):
  5099. if m.tilemap[y][xx].techID == tl.tlist['elfish'][4].techID:
  5100. m.tilemap[y][xx] = deepcopy(tl.tlist['functional'][18])
  5101. m.tilemap[y][xx].replace = tl.tlist['elfish'][0]
  5102. m.tilemap[y][xx].civilisation = False
  5103. coin = random.randint(0,3)
  5104. if coin == 1:
  5105. m.npcs[y][xx] = deepcopy(ml.mlist['elfish_special'][1]) #set elfish drunkard
  5106. m.set_monster_strength(xx,y,1,lvl_bonus=5)
  5107. for yy in range(y-1,y+2):
  5108. if m.tilemap[yy][x].techID == tl.tlist['elfish'][4].techID:
  5109. m.tilemap[yy][x] = deepcopy(tl.tlist['functional'][18])
  5110. m.tilemap[yy][x].replace = tl.tlist['elfish'][0]
  5111. m.tilemap[yy][x].civilisation = False
  5112. coin = random.randint(0,3)
  5113. if coin == 1:
  5114. m.npcs[yy][x] = deepcopy(ml.mlist['elfish_special'][1]) #set elfish drunkard
  5115. m.set_monster_strength(x,yy,1,lvl_bonus=5)
  5116. m.exchange(tl.tlist['elfish'][4],tl.tlist['elfish'][5])
  5117. screen.render_load(16,80)
  5118. for i in range(0,num_libaries):
  5119. pos = m.find_any(tl.tlist['elfish'][0])
  5120. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  5121. pos = m.find_first(tl.tlist['elfish'][4])
  5122. size = m.get_quarter_size(pos[0],pos[1])
  5123. for y in range(pos[1]+1,pos[1]+size[1]-1,2):
  5124. for x in range(pos[0]+1,pos[0]+size[0]-1,2):
  5125. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][19])
  5126. m.tilemap[y][x].civilisation = False
  5127. m.exchange(tl.tlist['elfish'][4],tl.tlist['elfish'][5])
  5128. screen.render_load(16,85)
  5129. for i in range(0,num_dwellings):
  5130. pos = m.find_any(tl.tlist['elfish'][0])
  5131. m.floating(pos[0],pos[1],tl.tlist['elfish'][4],tl.tlist['elfish'][3])#fill this building with elfish_active
  5132. pos = m.find_first(tl.tlist['elfish'][4])
  5133. pos_original = pos
  5134. size = m.get_quarter_size(pos[0],pos[1])
  5135. num_beds = int((size[0]*size[1])/9)
  5136. num_furniture = int((size[0]*size[1])/25)
  5137. for y in range(pos[1],pos[1]+size[1]):
  5138. for x in range(pos[0],pos[0]+size[0]):
  5139. m.tilemap[y][x] = tl.tlist['elfish'][5]
  5140. for y in range(pos[1]+1,pos[1]+size[1]-1):
  5141. for x in range(pos[0]+1,pos[0]+size[0]-1):
  5142. m.tilemap[y][x] = tl.tlist['elfish'][4]
  5143. for i in range(0,num_beds):#set beds
  5144. pos = m.find_any(tl.tlist['elfish'][4])
  5145. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][8])
  5146. m.tilemap[pos[1]][pos[0]].replace = deepcopy(tl.tlist['building'][9])
  5147. m.tilemap[pos[1]][pos[0]].civilisation = False
  5148. m.tilemap[pos[1]][pos[0]].replace.civilisation = False
  5149. for i in range(0,num_furniture):#set furnaces
  5150. pos = m.find_any(tl.tlist['elfish'][4])
  5151. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][14])
  5152. m.tilemap[pos[1]][pos[0]].replace = deepcopy(tl.tlist['building'][9])
  5153. m.tilemap[pos[1]][pos[0]].civilisation = False
  5154. m.tilemap[pos[1]][pos[0]].replace.civilisation = False
  5155. for i in range(0,num_furniture):#set wb's
  5156. pos = m.find_any(tl.tlist['elfish'][4])
  5157. ran = random.randint(9,13)
  5158. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][ran])
  5159. m.tilemap[pos[1]][pos[0]].replace = deepcopy(tl.tlist['building'][9])
  5160. m.tilemap[pos[1]][pos[0]].civilisation = False
  5161. m.tilemap[pos[1]][pos[0]].replace.civilisation = False
  5162. for y in range(pos_original[1]+1,pos_original[1]+size[1]-1):#set blue floor
  5163. for x in range(pos_original[0]+1,pos_original[0]+size[0]-1):
  5164. if m.tilemap[y][x].techID == tl.tlist['elfish'][4].techID:
  5165. m.tilemap[y][x] = deepcopy(tl.tlist['building'][9])
  5166. m.tilemap[y][x].civilisation = False
  5167. screen.render_load(16,90)
  5168. for yy in range(0,max_map_size,5):
  5169. for xx in range(0,max_map_size):
  5170. if m.tilemap[yy][xx].techID == tl.tlist['elfish'][3].techID:#this is elfish wall
  5171. m.tilemap[yy][xx] = deepcopy(tl.tlist['building'][2]) #set a open door here
  5172. m.tilemap[yy][xx].civilisation = False
  5173. for yyy in range(yy-1,yy+2):
  5174. for xxx in range(xx-1,xx+2):
  5175. if yyy >= 0 and xxx >= 0 and xxx < max_map_size and yyy < max_map_size:
  5176. 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:
  5177. #if a field next to a door isn't elfish_indoor, elfish_wall or shop_floor set it to elfish_indoor
  5178. m.tilemap[yyy][xxx] = tl.tlist['elfish'][0]
  5179. screen.render_load(16,95)
  5180. for yy in range(0,max_map_size):
  5181. for xx in range(0,max_map_size,5):
  5182. if m.tilemap[yy][xx].techID == tl.tlist['elfish'][3].techID:#this is elfish wall
  5183. m.tilemap[yy][xx] = deepcopy(tl.tlist['building'][2]) #set a open door here
  5184. m.tilemap[yy][xx].civilisation = False
  5185. for yyy in range(yy-1,yy+2):
  5186. for xxx in range(xx-1,xx+2):
  5187. if yyy >= 0 and xxx >= 0 and xxx < max_map_size and yyy < max_map_size:
  5188. 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:
  5189. #if a field next to a door isn't elfish_indoor, elfish_wall or shop_floor set it to elfish_indoor
  5190. m.tilemap[yyy][xxx] = tl.tlist['elfish'][0]
  5191. screen.render_load(16,97)
  5192. m.cut(2,max_map_size-3,2,max_map_size-3,tl.tlist['elfish'][3])
  5193. m.set_frame(tl.tlist['functional'][0])
  5194. #set fontains
  5195. for y in range(10,max_map_size-10,10):
  5196. for x in range(10,max_map_size-10,10):
  5197. if m.tilemap[y][x].techID == tl.tlist['elfish'][1].techID:
  5198. coin = random.randint(0,1)
  5199. if coin == 0:
  5200. m.tilemap[y][x] = deepcopy(tl.tlist['functional'][7])#set a fontain
  5201. m.tilemap[y][x].replace = tl.tlist['elfish'][1]
  5202. m.tilemap[y][x].civilisation = False #this is no players fontain
  5203. m.exchange(tl.tlist['elfish'][5],tl.tlist['elfish'][0])
  5204. pos = m.find_any(tl.tlist['functional'][7]) #set portal home
  5205. if pos == False:
  5206. pos = m.find_any(tl.tlist['elfish'][1])
  5207. replace = deepcopy(tl.tlist['elfish'][1])
  5208. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['portal'][2])
  5209. m.tilemap[pos[1]][pos[0]].replace = replace
  5210. m.spawn_monsters(6)
  5211. self.maplist[layer][map_name] = m
  5212. screen.render_load(16,00)
  5213. def mine_generator(self,layer):
  5214. screen.render_load(17,1)
  5215. cave_name = 'dungeon_0_0'
  5216. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  5217. m.map_type = 'orcish_mines'
  5218. m.set_music('orcish_mines','orcish_mines',True)
  5219. m.build_type = 'None'
  5220. m.monster_plus = 9
  5221. screen.render_load(17,10)
  5222. m.fill(tl.tlist['mine'][1])#fill with mine wall
  5223. screen.render_load(17,30)
  5224. m.drunken_walker(int(max_map_size/2),int(max_map_size/2),tl.tlist['mine'][0],((max_map_size**2/100)*45))
  5225. screen.render_load(17,50)
  5226. screen.render_load(17,60)
  5227. m.exchange_when_surrounded(tl.tlist['mine'][1],tl.tlist['global_caves'][3],8) #only the outer tiles become mine wall
  5228. screen.render_load(17,70)
  5229. for y in range (0, max_map_size):
  5230. for x in range(0,max_map_size):
  5231. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  5232. ran = random.randint(0,99)
  5233. if ran > 69:
  5234. m.tilemap[y][x] = tl.tlist['misc'][4]#set ore
  5235. m.tilemap[y][x].replace = tl.tlist['global_caves'][0]
  5236. elif ran < 10:
  5237. m.tilemap[y][x] = tl.tlist['misc'][5]#set gem
  5238. m.tilemap[y][x].replace = tl.tlist['global_caves'][0]
  5239. screen.render_load(17,80)
  5240. m.set_frame(tl.tlist['functional'][0])
  5241. m.make_shops()
  5242. m.make_containers(15,30,tl.tlist['mine'][0],1,4,'remains')
  5243. num_moss = int(((max_map_size*max_map_size)/100)*3)
  5244. for i in range (0,num_moss):
  5245. pos = m.find_any(tl.tlist['mine'][0])#find mine floor
  5246. try:
  5247. m.tilemap[pos[1]][pos[0]] = tl.tlist['mine'][2]#set blood moss
  5248. except:
  5249. None
  5250. screen.render_load(17,90)
  5251. pos = m.find_any(tl.tlist['mine'][0])#find any mine floor tile
  5252. m.tilemap[pos[1]][pos[0]] = tl.tlist['dungeon'][17]#set stair up
  5253. entrance_x = pos[0]
  5254. entrance_y = pos[1]
  5255. for sy in range(pos[1]-4,pos[1]+5):
  5256. for sx in range(pos[0]-4,pos[0]+5):
  5257. try:
  5258. if m.tilemap[sy][sx].move_group == 'soil':
  5259. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  5260. m.tilemap[sy][sx].move_group == 'dry_entrance'
  5261. elif m.tilemap[sy][sx].move_group == 'low_liquid':
  5262. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  5263. m.tilemap[sy][sx].move_group == 'wet_entrance'
  5264. except:
  5265. None
  5266. m.spawn_monsters(9)
  5267. screen.render_load(17,99)
  5268. self.maplist[layer][cave_name] = m
  5269. def cave_generator(self, deep, style='default'):
  5270. if style == 'desert':
  5271. cave_name='desert_0_0'
  5272. else:
  5273. cave_name = 'local_0_0'
  5274. p = 9
  5275. for d in range(1,deep+2):
  5276. screen.render_load(4,p+(d*20))
  5277. m = self.default_map_generator(cave_name,'global_caves', tilelist)
  5278. if d < 4:
  5279. if style == 'desert':
  5280. m.map_type = 'desert_cave'
  5281. m.monster_plus = 7
  5282. else:
  5283. m.map_type = 'cave'
  5284. m.set_music('cave','cave',True)
  5285. else:
  5286. if style == 'desert':
  5287. m.map_type = 'desert_lava_cave'
  5288. m.monster_plus = 7
  5289. else:
  5290. m.map_type = 'lava_cave'
  5291. m.set_music('lava_cave','lava_cave',True)
  5292. m.thirst_multi_day = 2
  5293. m.thirst_multi_night = 2
  5294. if d > 3:
  5295. m.exchange(tl.tlist['global_caves'][4],tl.tlist['misc'][2])#exchange lava against hot cave ground
  5296. m.exchange(tl.tlist['global_caves'][1],tl.tlist['misc'][28])#exchange worn rock against obsidian
  5297. if d > 4:
  5298. m.exchange_when_surrounded(tl.tlist['misc'][2],tl.tlist['global_caves'][4],8)#make lava spots between hot cave ground
  5299. num = int((max_map_size*max_map_size)/(50*50))
  5300. for i in range(0,num):
  5301. ran = random.randint(0,1)
  5302. if ran > 0:
  5303. pos = m.find_any(tl.tlist['global_caves'][0]) #cave ground
  5304. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['functional'][23])# make master forges
  5305. else:
  5306. m.exchange(tl.tlist['global_caves'][4],tl.tlist['misc'][1])#exchange lava against mud
  5307. m.exchange_when_surrounded(tl.tlist['misc'][1],tl.tlist['misc'][0],8)#make low water spots between mud
  5308. #######set mushrooms, ore and gems
  5309. chance_ore = d
  5310. chance_gem = d/2
  5311. for y in range (0,max_map_size):
  5312. for x in range (0,max_map_size):
  5313. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  5314. replace = m.tilemap[y][x].replace
  5315. coin = random.randint(0,1)
  5316. percent = random.randint(1,100)
  5317. if coin == 0 and percent <= chance_ore:
  5318. m.tilemap[y][x] = tl.tlist['misc'][4]#set ore here
  5319. m.tilemap[y][x].replace = replace
  5320. elif coin == 1 and percent <= chance_gem:
  5321. m.tilemap[y][x] = tl.tlist['misc'][5]#set gem here
  5322. m.tilemap[y][x].replace = replace
  5323. if m.tilemap[y][x].techID == tl.tlist['misc'][1].techID:#this is mud
  5324. cent = random.randint(0,99)
  5325. if cent < 10: #its a chance of 10% that a blue mushroom spawns here
  5326. replace = m.tilemap[y][x]
  5327. m.tilemap[y][x] = tl.tlist['misc'][6]
  5328. m.tilemap[y][x].replace = replace
  5329. if m.tilemap[y][x].techID == tl.tlist['global_caves'][0].techID:#this is cave ground
  5330. cent = random.randint(0,99)
  5331. if cent < 10: #its a chance of 10% that a brown mushroom spawns here
  5332. replace = m.tilemap[y][x]
  5333. m.tilemap[y][x] = tl.tlist['misc'][7]
  5334. m.tilemap[y][x].replace = replace
  5335. elif cent < 15: #its a chance of 5% that a purple mushroom spawns here
  5336. replace = m.tilemap[y][x]
  5337. m.tilemap[y][x] = tl.tlist['misc'][8]
  5338. m.tilemap[y][x].replace = replace
  5339. m.set_frame(tl.tlist['functional'][0])
  5340. if d == 1 and style == 'default':#set stair up on lvl 1
  5341. pos = (int(max_map_size/2),int(max_map_size/2))
  5342. m.tilemap[pos[1]+1][pos[0]] = deepcopy(tl.tlist['functional'][2])#stair down
  5343. m.tilemap[pos[1]+1][pos[0]].damage = -1
  5344. m.tilemap[pos[1]+1][pos[0]].damage_mes = 'Your wounds are cured.'
  5345. m.tilemap[pos[1]+1][pos[0]].build_here = False
  5346. for yy in range(pos[1]-3,pos[1]+4):
  5347. for xx in range(pos[0]-3,pos[0]+4):
  5348. m.tilemap[yy][xx].no_spawn = True
  5349. for x in range(0,max_map_size):
  5350. if m.tilemap[x][pos[0]].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  5351. ran = random.randint(1,2)
  5352. m.tilemap[x][pos[0]] = deepcopy(tl.tlist['global_caves'][ran])
  5353. for y in range(0,max_map_size):
  5354. if m.tilemap[pos[1]+1][y].techID == tl.tlist['global_caves'][3].techID:#this is hard rock
  5355. ran = random.randint(1,2)
  5356. m.tilemap[pos[1]+1][y] = deepcopy(tl.tlist['global_caves'][ran])
  5357. #set vaults
  5358. for i in range(0,int(max_map_size**2/50**2)):
  5359. m.make_vault(tl.tlist['global_caves'][0],d)
  5360. #set grot/mine at lvl 1 and 3
  5361. if style == 'default':
  5362. if d == 1:
  5363. ran_pos = m.find_any(tl.tlist['global_caves'][0])
  5364. m.tilemap[ran_pos[1]][ran_pos[0]] = tl.tlist['dungeon'][14]
  5365. if style == 'desert':
  5366. if d == 3:
  5367. ran_pos = m.find_any(tl.tlist['global_caves'][0])
  5368. m.tilemap[ran_pos[1]][ran_pos[0]] = tl.tlist['dungeon'][16]
  5369. m.make_containers(1,2,tl.tlist['global_caves'][0],2,5,'chest')#set some chests
  5370. m.make_special_monsters(0,1,tl.tlist['global_caves'][0],d,'mimic')#maybe set some mimics
  5371. m.make_special_monsters(15,25,tl.tlist['global_caves'][0],d,'vase')#set some vases
  5372. if m.map_type == 'desert_lava_cave':
  5373. m.make_special_monsters(1,2,tl.tlist['global_caves'][0],d,'demonic chest')#maybe set some demonic chests
  5374. m.spawn_monsters(d)
  5375. if style == 'desert': #replace rock etc.
  5376. for y in range(0,max_map_size):
  5377. for x in range(0,max_map_size):
  5378. if m.tilemap[y][x].techID == tl.tlist['global_caves'][3].techID: #this is hard rock
  5379. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][24])
  5380. elif m.tilemap[y][x].techID == tl.tlist['global_caves'][1].techID: #this is worn rock
  5381. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][23])
  5382. elif m.tilemap[y][x].techID == tl.tlist['global_caves'][2].techID: #this is soft soil
  5383. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][23])
  5384. elif m.tilemap[y][x].techID == tl.tlist['misc'][4].techID: #this is ore
  5385. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][21])
  5386. elif m.tilemap[y][x].techID == tl.tlist['misc'][5].techID: #this is gem
  5387. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][22])
  5388. elif m.tilemap[y][x].techID == tl.tlist['misc'][7].techID: #this is a brown mushroom
  5389. replace = m.tilemap[y][x].replace
  5390. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][25])
  5391. m.tilemap[y][x].replace = replace
  5392. elif m.tilemap[y][x].techID == tl.tlist['misc'][8].techID: #this is a purple mushroom
  5393. replace = m.tilemap[y][x].replace
  5394. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][27])
  5395. m.tilemap[y][x].replace = replace
  5396. elif m.tilemap[y][x].techID == tl.tlist['misc'][6].techID: #this is a blue mushroom
  5397. replace = m.tilemap[y][x].replace
  5398. m.tilemap[y][x] = deepcopy(tl.tlist['misc'][26])
  5399. m.tilemap[y][x].replace = replace
  5400. self.maplist[d][cave_name] = m
  5401. def elysium_generator(self):
  5402. name = 'elysium_0_0'
  5403. tilemap = []
  5404. for a in range (0,max_map_size):
  5405. tilemap.append([])
  5406. for b in range (0,max_map_size):
  5407. tilemap[a].append(0)
  5408. m = maP(name,tilemap)
  5409. m.map_type = 'elysium'
  5410. m.set_music('menu','menu',True)
  5411. m.build_type = 'None'
  5412. m.fill(tl.tlist['sanctuary'][0])
  5413. for x in range(0,max_map_size):
  5414. for y in range(0,max_map_size):
  5415. if x%2 == 0 and y%2 == 0:
  5416. m.tilemap[y][x] = deepcopy(tl.tlist['sanctuary'][1])
  5417. elif x%2 != 0 and y%2 != 0:
  5418. m.tilemap[y][x] = deepcopy(tl.tlist['sanctuary'][1])
  5419. center = int(max_map_size/2)
  5420. for yy in range(center-2,center+3):
  5421. for xx in range(center-2,center+3):
  5422. m.tilemap[yy][xx] = deepcopy(tl.tlist['sanctuary'][0])
  5423. m.tilemap[center][center] = deepcopy(tl.tlist['sanctuary'][2])
  5424. for yyy in range(center-7,center-3):
  5425. for xxx in range(center-2,center+3):
  5426. m.tilemap[yyy][xxx] = deepcopy(tl.tlist['sanctuary'][0])
  5427. for yyy in range(center-2,center+3):
  5428. for xxx in range(center-7,center-3):
  5429. m.tilemap[yyy][xxx] = deepcopy(tl.tlist['sanctuary'][0])
  5430. for yyy in range(center-2,center+3):
  5431. for xxx in range(center+4,center+8):
  5432. m.tilemap[yyy][xxx] = deepcopy(tl.tlist['sanctuary'][0])
  5433. help_map = deepcopy(m)
  5434. for yyy in range(0,max_map_size):
  5435. for xxx in range(0,max_map_size):
  5436. if m.tilemap[yyy][xxx].techID == tl.tlist['sanctuary'][0].techID:
  5437. count = 0
  5438. for yyyy in range(yyy-1,yyy+2):
  5439. for xxxx in range(xxx-1,xxx+2):
  5440. try:
  5441. if m.tilemap[yyyy][xxxx].techID == tl.tlist['sanctuary'][1].techID:
  5442. count += 1
  5443. except:
  5444. None
  5445. if count == 4:
  5446. help_map.tilemap[yyy][xxx] = deepcopy(tl.tlist['sanctuary'][1])
  5447. m = help_map
  5448. m.tilemap[center][center-1] = deepcopy(tl.tlist['sanctuary'][3])
  5449. m.tilemap[center][center+1] = deepcopy(tl.tlist['sanctuary'][3])
  5450. m.tilemap[center][center-5] = deepcopy(tl.tlist['sanctuary'][3])
  5451. m.tilemap[center][center+5] = deepcopy(tl.tlist['sanctuary'][3])
  5452. m.tilemap[center][center-1] = deepcopy(tl.tlist['sanctuary'][3])
  5453. m.tilemap[center-5][center] = deepcopy(tl.tlist['sanctuary'][3])
  5454. m.tilemap[center-7][center] = deepcopy(tl.tlist['portal'][6])
  5455. m.tilemap[center-7][center].replace = deepcopy(tl.tlist['sanctuary'][0])
  5456. m.tilemap[center-8][center+1] = deepcopy(tl.tlist['portal'][0])
  5457. m.tilemap[center-8][center+1].replace = deepcopy(tl.tlist['sanctuary'][0])
  5458. m.tilemap[center-8][center-1] = deepcopy(tl.tlist['portal'][3])
  5459. m.tilemap[center-8][center-1].replace = deepcopy(tl.tlist['sanctuary'][0])
  5460. #set nest boxes
  5461. m.tilemap[23][30] = deepcopy(tl.tlist['sanctuary'][4])
  5462. m.tilemap[23][30].replace = deepcopy(tl.tlist['sanctuary'][0])
  5463. m.tilemap[23][32] = deepcopy(tl.tlist['sanctuary'][4])
  5464. m.tilemap[23][32].replace = deepcopy(tl.tlist['sanctuary'][0])
  5465. m.tilemap[25][34] = deepcopy(tl.tlist['sanctuary'][4])
  5466. m.tilemap[25][34].replace = deepcopy(tl.tlist['sanctuary'][0])
  5467. m.tilemap[27][34] = deepcopy(tl.tlist['sanctuary'][4])
  5468. m.tilemap[27][34].replace = deepcopy(tl.tlist['sanctuary'][0])
  5469. m.tilemap[29][32] = deepcopy(tl.tlist['sanctuary'][4])
  5470. m.tilemap[29][32].replace = deepcopy(tl.tlist['sanctuary'][0])
  5471. m.tilemap[29][30] = deepcopy(tl.tlist['sanctuary'][4])
  5472. m.tilemap[29][30].replace = deepcopy(tl.tlist['sanctuary'][0])
  5473. #set tutorial npcs
  5474. m.npcs[center-3][center-6] = deepcopy(ml.mlist['seraph'][0])
  5475. m.set_monster_strength(center-6,center-3,1)
  5476. m.npcs[center-3][center-6].lp = 999
  5477. m.npcs[center][center+6] = deepcopy(ml.mlist['seraph'][1])
  5478. m.set_monster_strength(center+6,center,1)
  5479. m.npcs[center][center+6].lp = 999
  5480. m.npcs[center+3][center-2] = deepcopy(ml.mlist['seraph'][2])
  5481. m.set_monster_strength(center-2,center+3,1)
  5482. m.npcs[center+3][center-2].lp = 999
  5483. m.npcs[center+3][center+2] = deepcopy(ml.mlist['seraph'][3])
  5484. m.set_monster_strength(center+2,center+3,1)
  5485. m.npcs[center+3][center+2].lp = 999
  5486. m.npcs[center-3][center-4] = deepcopy(ml.mlist['seraph'][4])
  5487. m.set_monster_strength(center-4,center-3,1)
  5488. m.npcs[center-3][center-4].lp = 999
  5489. m.npcs[center+3][center] = deepcopy(ml.mlist['seraph'][5])
  5490. m.set_monster_strength(center,center+3,1)
  5491. m.npcs[center+3][center].lp = 999
  5492. m.npcs[center-6][center] = deepcopy(ml.mlist['seraph'][6])
  5493. m.set_monster_strength(center,center-6,1)
  5494. m.npcs[center-6][center].lp = 999
  5495. m.tilemap[center+2][center] = deepcopy(tl.tlist['functional'][9]) #carpenters workbench
  5496. m.tilemap[center+2][center].replace = tl.tlist['sanctuary'][0] #
  5497. self.maplist[0][name] = m
  5498. def grassland_generator(self,x,y,chance_scrubs, chance_trees, chance_herbs, number_rocks):
  5499. # chance_scrubs and chance_trees must be between 0 and 99
  5500. screen.render_load(3,1)
  5501. name = 'local_0_0'
  5502. helpmap = self.default_map_generator('1','help',tilelist)
  5503. tilemap = []
  5504. for a in range (0,max_map_size):
  5505. tilemap.append([])
  5506. for b in range (0,max_map_size):
  5507. tilemap[a].append(0)
  5508. m = maP(name,tilemap)
  5509. m.map_type = 'overworld'
  5510. m.set_music('overworld','night',True)
  5511. screen.render_load(3,2)
  5512. m.fill(tl.tlist['local'][0])#fill the map with grass
  5513. # set scrubs
  5514. for y in range (0,max_map_size):
  5515. for x in range (0,max_map_size):
  5516. if helpmap.tilemap[y][x].techID == tl.tlist['help'][0].techID: #<---scrub here
  5517. chance = random.randint(0,99)
  5518. if chance < chance_scrubs:
  5519. scrubs = (1,3,4,6,7,8,9)
  5520. coin = random.randint(0,len(scrubs)-1)
  5521. m.tilemap[y][x] = deepcopy(tl.tlist['local'][scrubs[coin]])
  5522. m.tilemap[y][x].replace = tl.tlist['local'][0]
  5523. screen.render_load(3,3)
  5524. #set trees
  5525. for y in range (0,max_map_size):
  5526. for x in range (0,max_map_size):
  5527. if helpmap.tilemap[y][x].techID == tl.tlist['help'][1].techID: #<---tree here
  5528. chance = random.randint(0,99)
  5529. if chance < chance_trees:
  5530. coin = random.randint(10,13)
  5531. m.tilemap[y][x] = tl.tlist['local'][coin]
  5532. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  5533. screen.render_load(3,4)
  5534. #set herbs
  5535. for y in range (0,max_map_size):
  5536. for x in range (0,max_map_size):
  5537. if helpmap.tilemap[y][x].techID == tl.tlist['help'][0].techID: #<---scrub here
  5538. chance = random.randint(0,99)
  5539. if chance < chance_herbs:
  5540. coin = random.randint(15,16)
  5541. m.tilemap[y][x] = tl.tlist['local'][coin]
  5542. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  5543. screen.render_load(3,5)
  5544. # set rocks
  5545. for n in range (0,number_rocks):
  5546. x = random.randint(0,max_map_size-1)
  5547. y = random.randint(0,max_map_size-1)
  5548. m.tilemap[y][x] = tl.tlist['local'][14]
  5549. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  5550. screen.render_load(3,6)
  5551. #set water
  5552. for y in range (0,max_map_size):
  5553. for x in range (0,max_map_size):
  5554. if helpmap.tilemap[y][x].techID == tl.tlist['help'][2].techID: #<---water here
  5555. m.tilemap[y][x] = tl.tlist['misc'][0] # set low water here
  5556. screen.render_load(3,7)
  5557. m.exchange_when_surrounded(tl.tlist['misc'][0],tl.tlist['misc'][3],8) # exchange low wather against deep water
  5558. pos = (int(max_map_size/2),int(max_map_size/2))
  5559. #set portal
  5560. m.tilemap[pos[1]][pos[0]-5] = deepcopy(tl.tlist['portal'][8])
  5561. m.tilemap[pos[1]][pos[0]-5].replace = tl.tlist['local'][0]
  5562. #set stair down
  5563. m.tilemap[pos[1]+1][pos[0]] = deepcopy(tl.tlist['functional'][1])
  5564. m.set_frame(tl.tlist['functional'][0])
  5565. screen.render_load(3,8)
  5566. #set dungeon
  5567. ran_pos = m.find_any(tl.tlist['local'][0])
  5568. m.tilemap[ran_pos[1]][ran_pos[0]] = deepcopy(tl.tlist['dungeon'][7])
  5569. for q in range(0,int(max_map_size**2/50**2)*3):
  5570. m.make_orc_cave(tl.tlist['local'][0])#generate orc caves on grass
  5571. m.spawn_monsters(0)
  5572. self.maplist[0][name] = m
  5573. screen.render_load(3,9)
  5574. return pos
  5575. def shop_generator(self,style):
  5576. #0: Basic initializing
  5577. screen.render_load(19,0)
  5578. name = 'shop_0_0'
  5579. tilemap = []
  5580. for a in range (0,max_map_size):
  5581. tilemap.append([])
  5582. for b in range (0,max_map_size):
  5583. tilemap[a].append(0)
  5584. m = maP(name,tilemap)
  5585. m.map_type = style
  5586. m.build_type = 'None'
  5587. m.monster_plus = 0
  5588. m.monster_num = 0
  5589. m.set_music('shop','shop',True)
  5590. m.fill(tl.tlist['functional'][0])
  5591. screen.render_load(19,10)
  5592. center_x = int(max_map_size/2)
  5593. center_y = int(max_map_size/2)
  5594. for y in range(center_y-4,center_y+5):
  5595. for x in range(center_x-4,center_x+5):
  5596. m.tilemap[y][x] = deepcopy(tl.tlist['shop'][1])#wall
  5597. screen.render_load(19,20)
  5598. for y in range(center_y-3,center_y+4):
  5599. for x in range(center_x-3,center_x+4):
  5600. m.tilemap[y][x] = deepcopy(tl.tlist['dungeon'][1])#corridor
  5601. screen.render_load(19,30)
  5602. for y in range(center_y-2,center_y+3):
  5603. for x in range(center_x-2,center_x+3):
  5604. m.tilemap[y][x] = deepcopy(tl.tlist['shop'][1])#shop wall
  5605. screen.render_load(19,50)
  5606. for y in range(center_y-1,center_y+2):
  5607. for x in range(center_x-1,center_x+2):
  5608. m.tilemap[y][x] = deepcopy(tl.tlist['shop'][0])#shop floor
  5609. screen.render_load(19,70)
  5610. m.tilemap[center_y-2][center_x] = deepcopy(tl.tlist['shop'][2])#shop door
  5611. m.tilemap[center_y-3][center_x-1] = deepcopy(tl.tlist['shop'][5])#sign
  5612. m.tilemap[center_y-3][center_x-1].replace = deepcopy(tl.tlist['dungeon'][1])
  5613. m.tilemap[center_y-3][center_x].techID = -9999#nothing shall spawn here
  5614. m.tilemap[center_y-4][center_x] = deepcopy(tl.tlist['shop'][3])#shop exit
  5615. if style == 'pharmacy':
  5616. m.tilemap[center_y-3][center_x-1].move_mes = '[Naeria\'s Pharmacy]'
  5617. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][3])
  5618. elif style == 'pickaxe':
  5619. m.tilemap[center_y-3][center_x-1].move_mes = '[Eklor\'s Pickaxe Empire]'
  5620. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][4])
  5621. elif style == 'hardware':
  5622. m.tilemap[center_y-3][center_x-1].move_mes = '[Grimork\'s Hardware Store]'
  5623. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][5])
  5624. elif style == 'deco':
  5625. m.tilemap[center_y-3][center_x-1].move_mes = '[Larosa\'s Decoration Store]'
  5626. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][6])
  5627. elif style == 'book':
  5628. m.tilemap[center_y-3][center_x-1].move_mes = '[Xirazzzia\'s Bookshelf]'
  5629. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][7])
  5630. elif style == 'bomb':
  5631. m.tilemap[center_y-3][center_x-1].move_mes = '[Torguly\'s eXplozives Of al kinD]'
  5632. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][8])
  5633. elif style == 'general':
  5634. m.tilemap[center_y-3][center_x-1].move_mes = '[Arialu\'s General Store]'
  5635. m.npcs[center_y][center_x] = deepcopy(ml.mlist['shop'][9])
  5636. screen.render_load(19,90)
  5637. coin = random.randint(0,1)
  5638. if coin == 1:
  5639. pos = m.find_any(tl.tlist['dungeon'][1])
  5640. coin2 = random.randint(0,3)
  5641. if coin2 == 0:
  5642. replace = m.tilemap[pos[1]][pos[0]]
  5643. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['misc'][9])
  5644. m.tilemap[pos[1]][pos[0]].replace = replace
  5645. elif coin2 == 1:
  5646. replace = m.tilemap[pos[1]][pos[0]]
  5647. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['misc'][11])
  5648. m.tilemap[pos[1]][pos[0]].replace = replace
  5649. elif coin2 == 2:
  5650. m.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['cave'][2])
  5651. m.set_monster_strength(pos[0],pos[1],1)
  5652. else:
  5653. m.make_special_monsters(1,2,tl.tlist['dungeon'][1],1,'vase')
  5654. self.maplist[1][name] = m
  5655. screen.render_load(19,99)
  5656. def dungeon_generator(self,monster_plus,stair_down=True,num_traps=10,style='Dungeon'):#possible other style = 'Tomb'
  5657. #0: Basic initializing
  5658. screen.render_load(19,0)#Render progress bar 0%
  5659. if player.pet_pos != False and player.pet_on_map != False:
  5660. pet_help = deepcopy(world.maplist[player.pet_pos[2]][player.pet_on_map].npcs[player.pet_pos[1]][player.pet_pos[0]])
  5661. world.maplist[player.pet_pos[2]][player.pet_on_map].npcs[player.pet_pos[1]][player.pet_pos[0]] = 0
  5662. player.pet_pos = [0,0,1]
  5663. player.pet_on_map = 'dungeon_0_0'
  5664. if style == 'Tomb': #Set the graphics
  5665. tl.tlist['dungeon'][1].tile_pos = (4,6) #
  5666. tl.tlist['dungeon'][6].tile_pos = (4,7) #Sandstone walls,hidden doors and corridors for the acient tomb
  5667. tl.tlist['dungeon'][9].tile_pos = (4,7) #
  5668. else: #
  5669. tl.tlist['dungeon'][1].tile_pos = (10,6) #
  5670. tl.tlist['dungeon'][6].tile_pos = (2,6) #Default walls,hidden doors and corridors for the default dungeon
  5671. tl.tlist['dungeon'][9].tile_pos = (2,6) #
  5672. name = 'dungeon_0_0'#map name
  5673. tilemap = [] #Initializing a empty tilemap
  5674. for a in range (0,max_map_size): #
  5675. tilemap.append([]) #
  5676. for b in range (0,max_map_size): #
  5677. tilemap[a].append(0) #
  5678. m = maP(name,tilemap) #Generate a Map-object
  5679. if style == 'Tomb': #
  5680. m.map_type = 'tomb' #
  5681. m.set_music('tomb','tomb',True) #
  5682. else: #
  5683. m.map_type = 'dungeon' #and set a few constants for the new map
  5684. m.set_music('dungeon','dungeon',True)#
  5685. m.build_type = 'None' #
  5686. m.monster_plus = monster_plus #
  5687. m.monster_num = 0.3 #
  5688. m.no_monster_respawn = True #
  5689. m.fill(tl.tlist['dungeon'][9])#fill the map with dungeon wall tiles
  5690. screen.render_load(19,10)#Render progress bar 10%
  5691. #1: Set rooms
  5692. #Important fact: No matter how big the mapsize is set,
  5693. #dundeons only use the 52x52 tiles in the upper left connor.
  5694. #Thats as big as a small map.
  5695. test_build = True #Seperate the dungeon in a 3x3 grit.
  5696. while test_build: #Every part of the grit has a 66% chance to be a room
  5697. parts_with_rooms = [] #
  5698. #
  5699. for part_y in range(0,3): #
  5700. for part_x in range(0,3): #
  5701. ran = random.randint(0,9) #
  5702. if ran > 3: #
  5703. pick = (part_x,part_y) #
  5704. parts_with_rooms.append(pick) #
  5705. if len(parts_with_rooms) > 5: #every dungeon level needs at least 5 rooms
  5706. test_build = False #
  5707. coord_x = [] #transform the coordinates from the 3x3 grit into
  5708. coord_y = [] #real coordinates on the tilemap(center of the rooms)
  5709. #
  5710. for c in parts_with_rooms: #
  5711. x_offset = random.randint(0,5) #
  5712. y_offset = random.randint(0,5) #
  5713. #
  5714. real_x = 9+(15*c[0])+x_offset #
  5715. real_y = 9+(15*c[1])+y_offset #
  5716. #
  5717. coord_x.append(real_x) #
  5718. coord_y.append(real_y) #
  5719. 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
  5720. for i in range(0,len(coord_x)-1):#set variable roome size for all rooms
  5721. x_minus = random.randint(2,4)#
  5722. x_plus = random.randint(3,5) #
  5723. y_minus = random.randint(2,4)#
  5724. y_plus = random.randint(3,5) #
  5725. for yy in range(coord_y[i]-y_minus-1,coord_y[i]+y_plus+1): #draw walls around the rooms
  5726. for xx in range(coord_x[i]-x_minus-1,coord_x[i]+x_plus+1): #
  5727. m.tilemap[yy][xx] = deepcopy(tl.tlist['dungeon'][9]) #
  5728. for yy in range(coord_y[i]-y_minus,coord_y[i]+y_plus): #draw the room floor
  5729. for xx in range(coord_x[i]-x_minus,coord_x[i]+x_plus): #
  5730. m.tilemap[yy][xx] = tl.tlist['dungeon'][0] #
  5731. screen.render_load(19,25) #progress bar 25%
  5732. #2: Set doors
  5733. for yyy in range(0,52):
  5734. for xxx in range(0,52): #the 52 is hard scripted to safe performance
  5735. 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
  5736. if m.tilemap[yyy-1][xxx].move_group == 'soil' and m.tilemap[yyy+1][xxx].move_group == 'soil': #
  5737. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][3] #
  5738. elif m.tilemap[yyy][xxx-1].move_group == 'soil' and m.tilemap[yyy][xxx+1].move_group == 'soil': #
  5739. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][3] #
  5740. for yyy in range(0,52):
  5741. for xxx in range(0,52): #the 52 is hard scripted to safe performance
  5742. if m.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][3].techID: #Remove all doors that are next to another door.
  5743. size = m.get_quarter_size(xxx,yyy) #Only spare one door per wall
  5744. if size[0] > 1: #
  5745. for rx in range(xxx,xxx+size[0]+1): #
  5746. m.tilemap[yyy][rx] = deepcopy(tl.tlist['dungeon'][9]) #
  5747. rrx = int(xxx+((rx-xxx)/2)) #
  5748. m.tilemap[yyy][rrx] = tl.tlist['dungeon'][3] #
  5749. #
  5750. if m.tilemap[yyy-1][rrx].move_group != 'soil': #
  5751. m.tilemap[yyy-1][rrx] = tl.tlist['dungeon'][1] #
  5752. if m.tilemap[yyy+1][rrx].move_group != 'soil': #
  5753. m.tilemap[yyy+1][rrx] = tl.tlist['dungeon'][1] #
  5754. #
  5755. if size[1] > 1: #
  5756. for ry in range(yyy,yyy+size[1]+1): #
  5757. m.tilemap[ry][xxx] = deepcopy(tl.tlist['dungeon'][9]) #
  5758. rry = int(yyy+((ry-yyy)/2)) #
  5759. m.tilemap[rry][xxx] = tl.tlist['dungeon'][3] #
  5760. #
  5761. if m.tilemap[rry][xxx-1].move_group != 'soil': #
  5762. m.tilemap[rry][xxx-1] = tl.tlist['dungeon'][1] #
  5763. if m.tilemap[rry][xxx+1].move_group != 'soil': #
  5764. m.tilemap[rry][xxx+1] = tl.tlist['dungeon'][1] #
  5765. screen.render_load(19,40)#Render progress bar 40%
  5766. test = deepcopy(m) #Make a copy of the map as is
  5767. pos = test.find_first(tl.tlist['dungeon'][0]) #and performe a float test,
  5768. test.floating(pos[0],pos[1],tl.tlist['misc'][0],tl.tlist['dungeon'][9]) #in order to find not conected parts.
  5769. screen.render_load(19,50) #Render progress bar 50%
  5770. for yyy in range(0,52): #Remove not connected parts
  5771. for xxx in range(0,52): #
  5772. if test.tilemap[yyy][xxx].techID != tl.tlist['dungeon'][9].techID and test.tilemap[yyy][xxx].techID != tl.tlist['misc'][0].techID: #
  5773. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][9] #
  5774. screen.render_load(19,60)#Render progress bar 60%
  5775. for yyy in range(0,52): #Randomize doors:
  5776. for xxx in range(0,52): #-normal door
  5777. #-resisting door
  5778. if m.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][3].techID: #-etc.
  5779. ran = random.randint(3,6) #
  5780. m.tilemap[yyy][xxx] = tl.tlist['dungeon'][ran] #
  5781. if m.tilemap[yyy][xxx].techID == tl.tlist['dungeon'][9].techID: #Randomize wall design
  5782. ran_test = random.randint(0,99) #
  5783. if ran_test > 75: #
  5784. if style == 'Dungeon': #
  5785. ran = random.randint(0,2) #
  5786. m.tilemap[yyy][xxx].tile_pos = (11,0+ran) #
  5787. if style == 'Tomb': #
  5788. ran = random.randint(0,2) #
  5789. m.tilemap[yyy][xxx].tile_pos = (12,0+ran) #
  5790. screen.render_load(19,70)#Render progress bar 70%
  5791. #3: Make stairs
  5792. stair_up_pos = m.find_any(tl.tlist['dungeon'][0]) #Set a up leading stair on any floor tile.
  5793. entrance_x = stair_up_pos[0] #
  5794. entrance_y = stair_up_pos[1] #
  5795. if style == 'Tomb': #
  5796. m.tilemap[stair_up_pos[1]][stair_up_pos[0]] = tl.tlist['dungeon'][19] #
  5797. else: #
  5798. m.tilemap[stair_up_pos[1]][stair_up_pos[0]] = tl.tlist['dungeon'][8] #
  5799. for sy in range(stair_up_pos[1]-4,stair_up_pos[1]+5):
  5800. for sx in range(stair_up_pos[0]-4,stair_up_pos[0]+5):
  5801. try:
  5802. if m.tilemap[sy][sx].move_group == 'soil':
  5803. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  5804. m.tilemap[sy][sx].move_group = 'dry_entrance'
  5805. elif m.tilemap[sy][sx].move_group == 'low_liquid':
  5806. m.tilemap[sy][sx] = deepcopy(m.tilemap[sy][sx])
  5807. m.tilemap[sy][sx].move_group = 'wet_entrance'
  5808. except:
  5809. None
  5810. if stair_down == True: #If we are not on the deepest lvl:
  5811. stair_down_pos = m.find_any(tl.tlist['dungeon'][0]) #Set a down leading stair on any floor tile.
  5812. if style == 'Tomb': #
  5813. m.tilemap[stair_down_pos[1]][stair_down_pos[0]] = tl.tlist['dungeon'][18] #
  5814. else: #
  5815. m.tilemap[stair_down_pos[1]][stair_down_pos[0]] = tl.tlist['dungeon'][7] #
  5816. else: #Make a chest whit a reward on the deepest lvl instead
  5817. chest_pos = m.find_any(tl.tlist['dungeon'][0]) #
  5818. m.tilemap[chest_pos[1]][chest_pos[0]] = tl.tlist['dungeon'][20] #
  5819. m.tilemap[chest_pos[1]][chest_pos[0]].replace = tl.tlist['dungeon'][0] #
  5820. if style == 'Tomb':
  5821. 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
  5822. else: #
  5823. m.add_container([il.ilist['special_clothe'][1],il.ilist['misc'][33],il.ilist['misc'][41]],chest_pos[0],chest_pos[1])#
  5824. egg_pos = stair_up_pos = m.find_any(tl.tlist['dungeon'][0]) #set monster egg
  5825. m.tilemap[egg_pos[1]][egg_pos[0]] = tl.tlist['functional'][34] #
  5826. m.tilemap[egg_pos[1]][egg_pos[0]].replace = tl.tlist['dungeon'][0] #
  5827. screen.render_load(19,80)#Render progress bar 80%
  5828. #4: Make Traps
  5829. for i in range(0,num_traps): #Set hidden traps on random floor tiles.
  5830. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5831. replace = m.tilemap[pos[1]][pos[0]] #
  5832. m.tilemap[pos[1]][pos[0]] = deepcopy(tl.tlist['dungeon'][10]) #Traps have to be deepcopied to work proper.
  5833. m.tilemap[pos[1]][pos[0]].replace = replace #
  5834. screen.render_load(19,90) #Render Progress bar 90%
  5835. #5: Make interior
  5836. num_rooms = len(parts_with_rooms) #Make chests with random loot
  5837. m.make_containers(int(num_rooms/3),int(num_rooms/2),tl.tlist['dungeon'][0],1,3,'chest') #
  5838. for c in range(0,num_rooms): #Set random fontains on floor tiles
  5839. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5840. ran = random.randint(0,99) #
  5841. if ran < 15: #
  5842. tile = deepcopy(tl.tlist['dungeon'][12]) #acid fontain
  5843. elif ran > 84: #
  5844. tile = deepcopy(tl.tlist['dungeon'][13]) #healing fontain
  5845. else: #
  5846. tile = deepcopy(tl.tlist['functional'][7]) #fontain
  5847. tile.civilisation = False #
  5848. tile.build_here = False #
  5849. tile.can_grown = False #
  5850. tile.replace = tl.tlist['dungeon'][0] #
  5851. m.tilemap[pos[1]][pos[0]] = tile #
  5852. coin = random.randint(0,1) #Set a Altar on 50% of all maps
  5853. if coin == 1: #that are generated with this function
  5854. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5855. tile = deepcopy(tl.tlist['functional'][15]) #
  5856. tile.civilisation = False #
  5857. tile.build_here = False #
  5858. tile.can_grown = False #
  5859. tile.replace = tl.tlist['dungeon'][0] #
  5860. m.tilemap[pos[1]][pos[0]] = tile #
  5861. num_statue = random.randint(4,6) #generate random statues
  5862. for l in range(0,num_statue): #
  5863. kind = random.randint(0,len(tl.tlist['statue'])-1) #
  5864. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5865. tile = deepcopy(tl.tlist['statue'][kind]) #
  5866. tile.replace = tl.tlist['dungeon'][0] #
  5867. m.tilemap[pos[1]][pos[0]] = tile #
  5868. num_deco = random.randint(8,10) #generate random deco
  5869. for l in range(0,num_deco): #
  5870. if style == 'Tomb': #
  5871. kind = random.randint(3,5) #
  5872. else: #
  5873. kind = random.randint(0,2) #
  5874. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5875. tile = deepcopy(tl.tlist['deco'][kind]) #
  5876. tile.replace = tl.tlist['dungeon'][0] #
  5877. m.tilemap[pos[1]][pos[0]] = tile #
  5878. coin_cage = random.randint(0,2) #spawn cages
  5879. if coin_cage == 1: #
  5880. pos = m.find_any(tl.tlist['dungeon'][0]) #
  5881. m.npcs[pos[1]][pos[0]] = deepcopy(ml.mlist['cage'][random.randint(0,len(ml.mlist['cage'])-1)]) #
  5882. m.set_monster_strength(pos[0],pos[1],1,lvl_bonus=9) #
  5883. pos2 = m.find_any(tl.tlist['dungeon'][0]) #
  5884. m.tilemap[pos2[1]][pos2[0]] = deepcopy(tl.tlist['portal'][9]) #
  5885. m.tilemap[pos2[1]][pos2[0]].replace = deepcopy(tl.tlist['dungeon'][0]) #
  5886. m.spawn_monsters(0) #Spawn initial monsters
  5887. m.make_special_monsters(10,20,tl.tlist['dungeon'][0],m.monster_plus,'vase') #
  5888. m.make_special_monsters(1,2,tl.tlist['dungeon'][0],m.monster_plus,'mimic') #
  5889. if style == 'Tomb': #
  5890. m.make_special_monsters(1,3,tl.tlist['dungeon'][0],m.monster_plus,'demonic chest') #
  5891. coin = random.randint(0,1)
  5892. if coin == 1:
  5893. m.spawn_magic_shops()
  5894. if player.pet_pos != False and player.pet_on_map != False:
  5895. m.npcs[0][0] = pet_help
  5896. self.maplist[1][name] = m # Add map to world.maplist
  5897. screen.render_load(19,99) #Render progress bar 99%
  5898. def desert_generator(self,chance_object):
  5899. #chance_objects must be between 0 and 99
  5900. screen.render_load(18,1)
  5901. name = 'desert_0_0'
  5902. tilemap = []
  5903. for a in range (0,max_map_size):
  5904. tilemap.append([])
  5905. for b in range (0,max_map_size):
  5906. tilemap[a].append(0)
  5907. m = maP(name,tilemap)
  5908. m.map_type = 'desert'
  5909. m.build_type = 'Full'
  5910. m.monster_plus = 7
  5911. m.thirst_multi_day = 2
  5912. m.set_music('desert','night',True)
  5913. m.fill(tl.tlist['extra'][0])
  5914. y_river = random.randint((17),(max_map_size-17))
  5915. river_offset = random.randint(-3,3)
  5916. plus = 0
  5917. minus = 0
  5918. screen.render_load(18,20)
  5919. for c in range (0,max_map_size):
  5920. for g in range (-2,7):
  5921. m.tilemap[y_river+river_offset+g][c] = tl.tlist['local'][0]#set grass
  5922. for w in range (0,5):
  5923. m.tilemap[y_river+river_offset+w][c] = tl.tlist['misc'][0]#set low water
  5924. if river_offset < 4:
  5925. plus = 1
  5926. else:
  5927. plus = 0
  5928. if river_offset > -4:
  5929. minus = -1
  5930. else:
  5931. minus = 0
  5932. offset_change = random.randint(minus,plus)
  5933. river_offset += offset_change
  5934. m.exchange_when_surrounded(tl.tlist['misc'][0],tl.tlist['misc'][3],7)
  5935. screen.render_load(18,40)
  5936. for b in range(2,max_map_size-2,10):
  5937. #north side of the river
  5938. building_offset =random.randint(0,4)
  5939. number_beds = 0
  5940. for y in range(y_river-12,y_river-7):
  5941. for x in range(b+building_offset,b+building_offset+5):
  5942. if x == b+building_offset or x == b+building_offset+4:
  5943. if y == y_river-10:
  5944. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5945. else:
  5946. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5947. elif y == y_river-12 or y == y_river-8:
  5948. if x == b+building_offset+2:
  5949. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5950. else:
  5951. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5952. else:
  5953. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][1])
  5954. if x == b+building_offset+1 or x == b+building_offset+3:
  5955. if y == y_river-11 or y == y_river-9:
  5956. obj_here = random.randint(0,2) #0: nothing, 1:bed 2:workbench
  5957. if number_beds == 0:
  5958. obj_here = 1
  5959. if obj_here != 0:
  5960. if obj_here == 1:
  5961. obj = ('functional',8)
  5962. number_beds += 1
  5963. else:
  5964. ran = random.randint(9,15)
  5965. obj = ('functional',ran)
  5966. m.tilemap[y][x] = deepcopy(tl.tlist[obj[0]][obj[1]])
  5967. m.tilemap[y][x].replace = deepcopy(tl.tlist['extra'][1])
  5968. m.tilemap[y][x].civilisation = False
  5969. m.tilemap[y][x].build_here = False
  5970. m.tilemap[y][x].move_group = 'house'
  5971. #south side of the river
  5972. building_offset = random.randint(0,4)
  5973. number_beds = 0
  5974. screen.render_load(18,60)
  5975. for y in range(y_river+8,y_river+13):
  5976. for x in range(b+building_offset,b+building_offset+5):
  5977. if x == b+building_offset or x == b+building_offset+4:
  5978. if y == y_river+10:
  5979. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5980. else:
  5981. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5982. elif y == y_river+12 or y == y_river+8:
  5983. if x == b+building_offset+2:
  5984. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][9])
  5985. else:
  5986. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][2])
  5987. else:
  5988. m.tilemap[y][x] = deepcopy(tl.tlist['extra'][1])
  5989. if x == b+building_offset+1 or x == b+building_offset+3:
  5990. if y == y_river+9 or y == y_river+11:
  5991. obj_here = random.randint(0,2) #0: nothing, 1:bed 2:workbench
  5992. if number_beds == 0:
  5993. obj_here = 1
  5994. if obj_here != 0:
  5995. if obj_here == 1:
  5996. obj = ('functional',8)
  5997. number_beds += 1
  5998. else:
  5999. ran = random.randint(9,15)
  6000. obj = ('functional',ran)
  6001. m.tilemap[y][x] = deepcopy(tl.tlist[obj[0]][obj[1]])
  6002. m.tilemap[y][x].replace = deepcopy(tl.tlist['extra'][1])
  6003. m.tilemap[y][x].civilisation = False
  6004. m.tilemap[y][x].build_here = False
  6005. m.tilemap[y][x].move_group = 'house'
  6006. make_bridges = True
  6007. num_bridges = 0
  6008. num_bridges_max = ((max_map_size/50)*3)+1
  6009. screen.render_load(18,80)
  6010. while num_bridges < num_bridges_max:
  6011. x_pos = random.randint(5,max_map_size-5)
  6012. num_wall = 0
  6013. for test in range(0,max_map_size):
  6014. if m.tilemap[test][x_pos].techID == tl.tlist['extra'][2].techID:
  6015. num_wall += 1
  6016. if num_wall == 0:
  6017. num_bridges += 1
  6018. for y in range(0,max_map_size):
  6019. 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
  6020. replace = deepcopy(m.tilemap[y][x_pos])
  6021. m.tilemap[y][x_pos] = deepcopy(tl.tlist['extra'][8])
  6022. m.tilemap[y][x_pos].replace = replace
  6023. for y in range (0,max_map_size):
  6024. for x in range (0,max_map_size):
  6025. if m.tilemap[y][x].techID == tl.tlist['extra'][0].techID:
  6026. chance = random.randint(0,99)
  6027. if chance < chance_object:
  6028. obj_numbers = (3,4,5,14)
  6029. coin = random.randint(0,len(obj_numbers)-1)
  6030. m.tilemap[y][x] = tl.tlist['extra'][obj_numbers[coin]]
  6031. m.tilemap[y][x].replace = tl.tlist['extra'][0]#sand
  6032. elif m.tilemap[y][x].techID == tl.tlist['local'][0].techID:
  6033. chance = random.randint(0,99)
  6034. if chance < chance_object:
  6035. coin = random.randint(10,13)
  6036. m.tilemap[y][x] = tl.tlist['extra'][coin]
  6037. m.tilemap[y][x].replace = tl.tlist['local'][0]#grass
  6038. elif m.tilemap[y][x].techID == tl.tlist['extra'][9].techID:
  6039. for yy in range(y-1,y+2):
  6040. if m.tilemap[yy][x].replace != None:
  6041. m.tilemap[yy][x] = m.tilemap[yy][x].replace
  6042. for xx in range(x-1,x+2):
  6043. if m.tilemap[y][xx].replace != None:
  6044. m.tilemap[y][xx] = m.tilemap[y][xx].replace
  6045. if m.tilemap[y][x].techID == tl.tlist['functional'][8].techID:#bed
  6046. ran = random.randint(5,6)
  6047. m.npcs[y][x] = deepcopy(ml.mlist['special'][ran])
  6048. m.set_monster_strength(x,y,0)
  6049. m.set_frame(tl.tlist['functional'][0])
  6050. screen.render_load(18,99)
  6051. #set portal
  6052. y = 2
  6053. x = random.randint(2,max_map_size-2)
  6054. m.tilemap[y][x] = tl.tlist['portal'][5]
  6055. m.tilemap[y][x].replace = tl.tlist['extra'][0]#sand
  6056. m.tilemap[y+1][x] = tl.tlist['extra'][0]#sand
  6057. #set tomb
  6058. ran_pos = m.find_any(tl.tlist['extra'][0])
  6059. m.tilemap[ran_pos[1]][ran_pos[0]] = tl.tlist['dungeon'][18]
  6060. m.spawn_monsters(0)
  6061. self.maplist[0][name] = m
  6062. class mob():
  6063. def __init__(self, name, on_map, attribute, pos =[40,40,0],glob_pos=[0,0],build='Manual'):
  6064. self.name = name
  6065. self.on_map = on_map
  6066. self.attribute = attribute
  6067. self.lp = attribute.max_lp
  6068. self.mp = attribute.max_mp
  6069. self.pos = pos
  6070. self.glob_pos = glob_pos
  6071. self.last_map = 'Foo'
  6072. self.cur_map = 'Bar'
  6073. self.cur_z = self.pos[2]
  6074. self.last_z = 'Baz'
  6075. def move(self, x=0, y=0):
  6076. mc = self.move_check(x,y)
  6077. tile_move_group = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group
  6078. player_move_groups = ['soil','low_liquid','shop','house','wet_entrance','dry_entrance']
  6079. swim_check = True
  6080. for i in ('Head','Body','Legs','Feet'):
  6081. if player.inventory.wearing[i] != player.inventory.nothing:
  6082. swim_check = False
  6083. if swim_check == True:
  6084. player_move_groups.append('swim')
  6085. if player.buffs.get_buff('hexed') < 1:
  6086. player_move_groups.append('holy')
  6087. if self.buffs.get_buff('immobilized') > 0:
  6088. player_move_groups = ['not_existent_group1','not_existent_group2']
  6089. move_check2 = False
  6090. for j in player_move_groups:
  6091. if j == tile_move_group:
  6092. move_check2 = True
  6093. if mc == True:
  6094. if x > 0 and move_check2 == True and self.pos[0] < max_map_size - 1:
  6095. if self.pet_pos != False and self.pet_on_map != False:
  6096. try:
  6097. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999 #set pets lp to 999 to make them unbreakable
  6098. world.maplist[self.pos[2]][self.on_map].npcs[self.pos[1]][self.pos[0]] = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]]
  6099. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = 0
  6100. self.pet_pos = deepcopy(self.pos)
  6101. self.pet_on_map = deepcopy(self.on_map)
  6102. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation += 1
  6103. relation = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation
  6104. evolve = False
  6105. if relation == 1000 and 'pet0' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6106. evolve = True
  6107. elif relation == 4000 and 'pet1' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6108. evolve = True
  6109. if evolve == True:
  6110. #screen.write_hit_matrix(self.pet_pos[0],self.pet_pos[1],7)
  6111. anger_monster = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].anger_monster #leveling monsters use the same mechanic like angering monsters
  6112. mo_name = deepcopy(world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name)
  6113. memory = deepcopy(world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory)
  6114. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = deepcopy(ml.mlist['pet'][anger_monster])
  6115. world.maplist[self.pet_pos[2]][self.pet_on_map].set_monster_strength(self.pet_pos[0],self.pet_pos[1],1)
  6116. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999
  6117. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation = relation
  6118. player.pet_lp = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].basic_attribute.max_lp
  6119. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory = memory
  6120. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].AI_style = 'company'
  6121. message.add(mo_name + 'envolved into a ' + world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name + '!')
  6122. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name = mo_name
  6123. except:
  6124. message.add('[PET ERROR: Unfollow pet]')
  6125. player.pet_pos = False
  6126. player.pet_on_map = False
  6127. self.pos[0] += 1
  6128. if x < 0 and move_check2 == True and self.pos[0] > 0:
  6129. if self.pet_pos != False and self.pet_on_map != False:
  6130. try:
  6131. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999 #set pets lp to 999 to make them unbreakable
  6132. world.maplist[self.pos[2]][self.on_map].npcs[self.pos[1]][self.pos[0]] = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]]
  6133. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = 0
  6134. self.pet_pos = deepcopy(self.pos)
  6135. self.pet_on_map = deepcopy(self.on_map)
  6136. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation += 1
  6137. relation = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation
  6138. evolve = False
  6139. if relation == 1000 and 'pet0' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6140. evolve = True
  6141. elif relation == 4000 and 'pet1' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6142. evolve = True
  6143. if evolve == True:
  6144. #screen.write_hit_matrix(self.pet_pos[0],self.pet_pos[1],7)
  6145. anger_monster = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].anger_monster #leveling monsters use the same mechanic like angering monsters
  6146. mo_name = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name
  6147. memory = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory
  6148. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = deepcopy(ml.mlist['pet'][anger_monster])
  6149. world.maplist[self.pet_pos[2]][self.pet_on_map].set_monster_strength(self.pet_pos[0],self.pet_pos[1],1)
  6150. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999
  6151. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation = relation
  6152. player.pet_lp = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].basic_attribute.max_lp
  6153. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory = memory
  6154. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].AI_style = 'company'
  6155. message.add(mo_name + 'envolved into a ' + world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name + '!')
  6156. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name = mo_name
  6157. except:
  6158. message.add('[PET ERROR: Unfollow pet]')
  6159. player.pet_pos = False
  6160. player.pet_on_map = False
  6161. self.pos[0] -= 1
  6162. if y > 0 and move_check2 == True and self.pos[1] < max_map_size - 1:
  6163. if self.pet_pos != False and self.pet_on_map != False:
  6164. try:
  6165. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999 #set pets lp to 999 to make them unbreakable
  6166. world.maplist[self.pos[2]][self.on_map].npcs[self.pos[1]][self.pos[0]] = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]]
  6167. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = 0
  6168. self.pet_pos = deepcopy(self.pos)
  6169. self.pet_on_map = deepcopy(self.on_map)
  6170. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation += 1
  6171. relation = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation
  6172. evolve = False
  6173. if relation == 1000 and 'pet0' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6174. evolve = True
  6175. elif relation == 4000 and 'pet1' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6176. evolve = True
  6177. if evolve == True:
  6178. #screen.write_hit_matrix(self.pet_pos[0],self.pet_pos[1],7)
  6179. anger_monster = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].anger_monster #leveling monsters use the same mechanic like angering monsters
  6180. mo_name = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name
  6181. memory = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory
  6182. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = deepcopy(ml.mlist['pet'][anger_monster])
  6183. world.maplist[self.pet_pos[2]][self.pet_on_map].set_monster_strength(self.pet_pos[0],self.pet_pos[1],1)
  6184. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999
  6185. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation = relation
  6186. player.pet_lp = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].basic_attribute.max_lp
  6187. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory = memory
  6188. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].AI_style = 'company'
  6189. message.add(mo_name + 'envolved into a ' + world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name + '!')
  6190. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name = mo_name
  6191. except:
  6192. message.add('[PET ERROR: Unfollow pet]')
  6193. player.pet_pos = False
  6194. player.pet_on_map = False
  6195. self.pos[1] += 1
  6196. if y < 0 and move_check2 == True and self.pos[1] > 0:
  6197. if self.pet_pos != False and self.pet_on_map != False:
  6198. try:
  6199. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999 #set pets lp to 999 to make them unbreakable
  6200. world.maplist[self.pos[2]][self.on_map].npcs[self.pos[1]][self.pos[0]] = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]]
  6201. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = 0
  6202. self.pet_pos = deepcopy(self.pos)
  6203. self.pet_on_map = deepcopy(self.on_map)
  6204. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation += 1
  6205. relation = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation
  6206. evolve = False
  6207. if relation == 1000 and 'pet0' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6208. evolve = True
  6209. elif relation == 4000 and 'pet1' in world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].properties:
  6210. evolve = True
  6211. if evolve == True:
  6212. #screen.write_hit_matrix(self.pet_pos[0],self.pet_pos[1],7)
  6213. anger_monster = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].anger_monster #leveling monsters use the same mechanic like angering monsters
  6214. mo_name = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name
  6215. memory = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory
  6216. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]] = deepcopy(ml.mlist['pet'][anger_monster])
  6217. world.maplist[self.pet_pos[2]][self.pet_on_map].set_monster_strength(self.pet_pos[0],self.pet_pos[1],1)
  6218. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].lp = 999
  6219. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].relation = relation
  6220. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].memory = memory
  6221. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].AI_style = 'company'
  6222. player.pet_lp = world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].basic_attribute.max_lp
  6223. message.add(mo_name + ' envolved into a ' + world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name + '!')
  6224. world.maplist[self.pet_pos[2]][self.pet_on_map].npcs[self.pet_pos[1]][self.pet_pos[0]].name = mo_name
  6225. except:
  6226. message.add('[PET ERROR: Unfollow pet]')
  6227. player.pet_pos = False
  6228. player.pet_on_map = False
  6229. self.pos[1] -= 1
  6230. self.stand_check()
  6231. def move_check(self,x,y):
  6232. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'door' or world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].techID == tl.tlist['dungeon'][6].techID:
  6233. 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:
  6234. #this is a resisting door or a hidden door
  6235. sfx.play('locked')
  6236. else:
  6237. sfx.play('open')
  6238. message.add(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_mes)
  6239. 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
  6240. return False
  6241. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'shop_enter':
  6242. sfx.play('open')
  6243. screen.render_fade(True,False)
  6244. shop_types = ('pharmacy','pickaxe','hardware','deco','book','bomb','general')
  6245. ran = random.randint(0,len(shop_types)-1)
  6246. world.shop_generator(shop_types[ran])
  6247. self.save_pos=(self.pos[0],self.pos[1],self.pos[2],self.on_map)
  6248. 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
  6249. shop_pos = world.maplist[1]['shop_0_0'].find_first(tl.tlist['shop'][3])
  6250. self.pos[0] = shop_pos[0]
  6251. self.pos[1] = shop_pos[1]+1
  6252. self.pos[2] = 1
  6253. self.on_map = 'shop_0_0'
  6254. player.stand_check()
  6255. screen.render_fade(False,True)
  6256. return False
  6257. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'shop_exit':
  6258. sfx.play('open')
  6259. self.pos[0] = self.save_pos[0]
  6260. self.pos[1] = self.save_pos[1]
  6261. self.pos[2] = self.save_pos[2]
  6262. self.on_map = self.save_pos[3]
  6263. player.stand_check()
  6264. screen.render_fade(False,True)
  6265. return False
  6266. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'holy' and player.buffs.get_buff('hexed') > 0:
  6267. message.add('You can\'t pass blessed ground while you are hexed!')
  6268. return False
  6269. try:
  6270. if world.maplist[self.pos[2]][self.on_map].npcs[self.pos[1]+y][self.pos[0]+x] != 0:
  6271. player.attack_monster(self.pos[0]+x,self.pos[1]+y)
  6272. return False
  6273. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].destroy != False: #for digging
  6274. 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
  6275. heated_stone = True
  6276. else:
  6277. heated_stone = False
  6278. if player.pos[2] > 3 and heated_stone == False:
  6279. brimstone = True
  6280. else:
  6281. brimstone = False
  6282. 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:
  6283. #this is not obsidian or soft soil
  6284. stone = True
  6285. else:
  6286. stone = False
  6287. 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:
  6288. if self == player:
  6289. message.add(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_mes)
  6290. 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
  6291. sfx.play('break')
  6292. try:
  6293. if self.skill.mining == 'Adept':
  6294. mat_addition = 2
  6295. elif self.skill.mining == 'Master':
  6296. mat_addition = 5
  6297. else:
  6298. mat_addition = 0
  6299. material = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[0]
  6300. mat_num = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[1] + mat_addition
  6301. mes = player.inventory.materials.add(material,mat_num)
  6302. message.add(mes)
  6303. if player.skill.mining != 'Master':
  6304. player.skill.mining_progress += 1
  6305. if player.skill.mining_progress == 200 and player.skill.mining != 'Adept':
  6306. player.skill.raise_skill('mining')
  6307. message.add('Your mining skill reaches adept level!')
  6308. sfx.play('lvl_up')
  6309. if player.skill.mining_progress == 1000 and player.skill.mining != 'Master':
  6310. player.skill.raise_skill('mining')
  6311. message.add('Your mining skill reaches master level!')
  6312. sfx.play('lvl_up')
  6313. except:
  6314. None
  6315. 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
  6316. world.maplist[self.pos[2]][self.on_map].countdowns.append(countdown('door', self.pos[0]+x, self.pos[1]+y,3))
  6317. sfx.play('open')
  6318. stone = False
  6319. heated_stone = False
  6320. brimstone = False
  6321. 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)
  6322. if heated_stone == True:#drop heated stone
  6323. ran = random.randint(0,99)
  6324. if ran < 5:
  6325. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x]
  6326. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][28])
  6327. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  6328. elif brimstone == True:#drop brimstone
  6329. ran = random.randint(0,99)
  6330. if ran < 5:
  6331. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x]
  6332. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][29])
  6333. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  6334. elif stone == True:#drop stone
  6335. ran = random.randint(0,99)
  6336. if ran < 5:
  6337. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x]
  6338. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][30])
  6339. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  6340. 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:
  6341. player.inventory.wearing['Pickaxe'].take_damage()
  6342. if player.inventory.wearing['Pickaxe'].state > 0:
  6343. player.inventory.wearing['Pickaxe'].set_name()
  6344. else:
  6345. message.add('Your tool breaks into pieces.')
  6346. player.inventory.wearing['Pickaxe'] = player.inventory.nothing
  6347. sfx.play('item_break')
  6348. else:
  6349. if self == player:
  6350. message.add('You are unable to destroy this with the tool in your hand.')
  6351. return False
  6352. else:
  6353. None
  6354. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].move_group == 'tree':
  6355. 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
  6356. apple = True
  6357. else:
  6358. apple = False
  6359. if player.inventory.wearing['Axe'] != player.inventory.nothing: #if player has a axe in his hand
  6360. chop_success = True
  6361. player.inventory.wearing['Axe'].take_damage()
  6362. if player.inventory.wearing['Axe'].state > 0:
  6363. player.inventory.wearing['Axe'].set_name()
  6364. else:
  6365. message.add('Your axe breaks into pieces.')
  6366. player.inventory.wearing['Axe'] = player.inventory.nothing
  6367. sfx.play('item_break')
  6368. else:
  6369. message.add('That hurts!')
  6370. player.lp -= 1
  6371. sfx.play('hit')
  6372. if random.randint(0,9) != 0: #90% to fail chopping down the wood with bare hands
  6373. chop_success = False
  6374. else:
  6375. chop_success = True
  6376. if chop_success == True:
  6377. if self.skill.woodcutting == 'Adept':
  6378. mat_addition = 2
  6379. elif self.skill.woodcutting == 'Master':
  6380. mat_addition = 5
  6381. else:
  6382. mat_addition = 0
  6383. material = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[0]
  6384. mat_num = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].conected_resources[1] + mat_addition
  6385. mes = player.inventory.materials.add(material,mat_num)
  6386. message.add(mes)
  6387. sfx.play('chop')
  6388. if player.skill.woodcutting != 'Master':
  6389. player.skill.woodcutting_progress += 1
  6390. if player.skill.woodcutting_progress == 200 and player.skill.woodcutting != 'Adept':
  6391. player.skill.raise_skill('woodcutting')
  6392. message.add('Your woodcutting skill reaches adept level!')
  6393. sfx.play('lvl_up')
  6394. if player.skill.woodcutting_progress == 1000 and player.skill.woodcutting != 'Master':
  6395. player.skill.raise_skill('woodcutting')
  6396. message.add('Your woodcutting skill reaches master level!')
  6397. sfx.play('lvl_up')
  6398. world.maplist[self.pos[2]][self.on_map].make_monsters_angry(self.pos[0],self.pos[1],'tree')
  6399. 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
  6400. if apple == True:
  6401. ran = random.randint(0,99)
  6402. if ran < 5:
  6403. ran2 = random.randint(0,99)
  6404. replace = deepcopy(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x])
  6405. if ran2 < 20:
  6406. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][32])
  6407. else:
  6408. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x] = deepcopy(tl.tlist['functional'][31])
  6409. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]+y][self.pos[0]+x].replace = replace
  6410. return False
  6411. if self.buffs.get_buff('immobilized') == 0:
  6412. 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':
  6413. sfx.play('walk_wet')
  6414. else:
  6415. sfx.play('walk_dry')
  6416. else:
  6417. sfx.play('immobilized')
  6418. return True
  6419. except:
  6420. None
  6421. def stand_check(self):
  6422. if self.on_map != 'shop_0_0':
  6423. if self.on_map != self.cur_map:
  6424. self.last_map = self.cur_map
  6425. self.cur_map = self.on_map
  6426. if self.pos[2] != self.cur_z:
  6427. self.last_z = self.cur_z
  6428. self.cur_z = self.pos[2]
  6429. world.maplist[self.pos[2]][self.on_map].special_check(self.pos[0],self.pos[1])
  6430. radius = 5
  6431. if player.pos[2] > 0:
  6432. radius = 2
  6433. elif player.pos[2] == 0:
  6434. if time.hour > 22 or time.hour < 4:
  6435. radius = 2
  6436. elif time.hour > 21 or time.hour < 5:
  6437. radius = 3
  6438. elif time.hour > 20 or time.hour < 6:
  6439. radius = 4
  6440. elif time.hour > 19 or time.hour < 7:
  6441. radius = 5
  6442. if player.buffs.get_buff('light') > 0 or player.buffs.get_buff('nightvision') > 0:
  6443. radius = 5
  6444. if player.buffs.get_buff('blind') > 0:
  6445. radius = 1
  6446. message.add(world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].move_mes,True)
  6447. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage > 0 and player.buffs.get_buff('fireresistance') == 0:
  6448. self.lp = self.lp - world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage
  6449. if self == player:
  6450. try:
  6451. 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)')
  6452. except:
  6453. None
  6454. 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':
  6455. sfx_flame = False
  6456. body_list = ('Head','Body','Legs','Feet','Hold(R)','Hold(L)','Neck','Hand','Pickaxe','Axe')
  6457. for i in body_list:
  6458. if player.inventory.wearing[i] != player.inventory.nothing and player.inventory.wearing[i].material == 'wooden':
  6459. ran = random.randint(0,9)
  6460. if ran < 4:
  6461. message.add('Your '+player.inventory.wearing[i].name+' burns to ashes!')
  6462. player.inventory.wearing[i] = player.inventory.nothing
  6463. sfx_flame = True
  6464. if sfx_flame == True:
  6465. sfx.play('flame')
  6466. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage < 0:
  6467. if self.lp < self.attribute.max_lp:
  6468. self.lp = self.lp - world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].damage
  6469. luck = player.attribute.luck + player.inventory.wearing['Neck'].attribute.luck
  6470. if player.buffs.get_buff('blessed') != 0:
  6471. luck += 2
  6472. for y in range(player.pos[1]-1,player.pos[1]+2):
  6473. for x in range(player.pos[0]-1,player.pos[0]+2):
  6474. if world.maplist[self.pos[2]][self.on_map].tilemap[y][x].techID == tl.tlist['dungeon'][6].techID:#this is a secret door
  6475. ran = random.randint(0,25)#check players luck
  6476. if ran < luck:
  6477. world.maplist[self.pos[2]][self.on_map].tilemap[y][x] = deepcopy(tl.tlist['dungeon'][3])
  6478. message.add('You notice a hidden door.')
  6479. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  6480. screen.write_hit_matrix(x,y,15)
  6481. sfx.play('found')
  6482. 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
  6483. ran = random.randint(0,25)#check players luck
  6484. if ran < luck:
  6485. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos = (10,8)
  6486. message.add('You notice a trap.')
  6487. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  6488. screen.write_hit_matrix(x,y,15)
  6489. sfx.play('found')
  6490. 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
  6491. ran = random.randint(0,15)#check players luck
  6492. if ran < luck:
  6493. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos = (12,11,12,12)
  6494. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].use_group = 'dont_drink'
  6495. message.add('You notice a strange smell.')
  6496. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  6497. screen.write_hit_matrix(x,y,15)
  6498. sfx.play('found')
  6499. 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
  6500. ran = random.randint(0,15)#check players luck
  6501. if ran < luck:
  6502. world.maplist[self.pos[2]][self.on_map].tilemap[y][x].tile_pos = (11,11,11,12)
  6503. message.add('You notice a strange sparkle.')
  6504. screen.write_hit_matrix(player.pos[0],player.pos[1],14)
  6505. screen.write_hit_matrix(x,y,15)
  6506. sfx.play('found')
  6507. for y in range (-radius,radius+1):#line of sight
  6508. for x in range (-radius,radius+1):
  6509. try:
  6510. dist = ((x)**2+(y)**2)**0.5
  6511. if dist <= radius+1 or dist >= radius-1:
  6512. run = True
  6513. c = 0
  6514. while run:
  6515. try:
  6516. yy = ((y*c)/dist)
  6517. except:
  6518. yy = 1
  6519. try:
  6520. xx = ((x*c)/dist)
  6521. except:
  6522. xx = 1
  6523. view_x = int(xx) + self.pos[0]
  6524. view_y = int(yy) + self.pos[1]
  6525. world.maplist[self.pos[2]][self.on_map].known[view_y][view_x] = 1
  6526. if world.maplist[self.pos[2]][self.on_map].tilemap[view_y][view_x].transparency == True and c < radius:
  6527. c+=1
  6528. else:
  6529. run = False
  6530. except:
  6531. None
  6532. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].techID == tl.tlist['dungeon'][10].techID:
  6533. kind =random.randint(0,3)
  6534. position = deepcopy(player.pos)#copy player pos before the trap is triggered because teleport traps could change it
  6535. if kind == 0:#dart trap
  6536. ran = random.randint(0,25)
  6537. if ran < luck:
  6538. screen.write_hit_matrix(player.pos[0],player.pos[1],3)
  6539. message.add('A flying dagger miss you.')
  6540. sfx.play('miss')
  6541. else:
  6542. player.lp -= 3
  6543. screen.write_hit_matrix(player.pos[0],player.pos[1],4)
  6544. message.add('A flying dagger hits you.')
  6545. sfx.play('hit')
  6546. elif kind == 1:#teleport trap
  6547. t=world.maplist[self.pos[2]][self.on_map].find_all_moveable()
  6548. if len(t) > 0:
  6549. rt = []
  6550. for i in t:
  6551. if world.maplist[self.pos[2]][self.on_map].npcs[i[1]][i[0]] == 0:
  6552. rt.append((i[0],i[1]))
  6553. if len(rt) > 0:
  6554. screen.render_fade(True,False)
  6555. ran = random.randint(0,len(rt)-1)
  6556. player.pos[0] = rt[ran][0]
  6557. player.pos[1] = rt[ran][1]
  6558. screen.reset_hit_matrix()
  6559. message.add('You are teleported randomly.')
  6560. sfx.play('teleport')
  6561. player.stand_check()
  6562. screen.render_fade(False,True)
  6563. else:
  6564. message.add('Nothing seems to happen.')
  6565. sfx.play('throw')
  6566. elif kind == 2:#blinding trap
  6567. ran = random.randint(10,30)
  6568. player.buffs.set_buff('blind',ran)
  6569. message.add('A garish flash blinds you.')
  6570. elif kind == 3:#magic trap
  6571. player.mp = 0
  6572. screen.write_hit_matrix(player.pos[0],player.pos[1],7)
  6573. message.add('You loose your focus.')
  6574. replace = world.maplist[self.pos[2]][self.on_map].tilemap[position[1]][position[0]].replace
  6575. world.maplist[self.pos[2]][self.on_map].tilemap[position[1]][position[0]] = deepcopy(tl.tlist['dungeon'][11])
  6576. world.maplist[self.pos[2]][self.on_map].tilemap[position[1]][position[0]].replace = replace
  6577. if player.lp <= 0:
  6578. screen.render_dead()
  6579. self.lp = int(self.lp)
  6580. bgm.check_for_song()
  6581. if time.hour%2 == 0 and time.minute == 0:
  6582. help_player = deepcopy(player)
  6583. help_player.on_map = 'local_0_0'
  6584. help_player.pos[0] = max_map_size/2
  6585. help_player.pos[1] = max_map_size/2
  6586. help_player.pos[2] = 0
  6587. save(None,help_player,time,gods,save_path,os.sep)
  6588. def enter(self):
  6589. if world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'stair_down':
  6590. 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
  6591. screen.render_fade(True,False)
  6592. player.pos[2] += 1
  6593. player.stand_check()#to unveil the surroundings
  6594. screen.render_fade(False,True)
  6595. else:
  6596. message.add('This stair seem to be blocked.')
  6597. 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
  6598. 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
  6599. screen.render_fade(True,False)
  6600. player.pos[2] -= 1
  6601. player.stand_check()#to unveil the surroundings
  6602. screen.render_fade(False,True)
  6603. else:
  6604. message.add('This stair seem to be blocked.')
  6605. 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
  6606. #drink water
  6607. if player.attribute.thirst < player.attribute.thirst_max:
  6608. sfx.play('no_fish')
  6609. message.add('You take a sip of water.')
  6610. player.attribute.thirst += 240 #this is 1/3 of the water te player needs per day
  6611. if player.attribute.thirst > player.attribute.thirst_max:
  6612. 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%
  6613. else:
  6614. message.add('You are not thirsty right now.')
  6615. 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
  6616. #drink acid water
  6617. if player.attribute.thirst < player.attribute.thirst_max:
  6618. message.add('You take a sip of water.')
  6619. player.lp -= 5
  6620. message.add('It hurts like acid.')
  6621. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].tile_pos = (12,11,12,12)
  6622. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group = 'dont_drink'
  6623. else:
  6624. message.add('You are not thirsty right now.')
  6625. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'dont_drink':
  6626. message.add('You shouldn\'t drink this water!')
  6627. 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
  6628. #drink healing water
  6629. if player.attribute.thirst < player.attribute.thirst_max:
  6630. message.add('You take a sip of water.')
  6631. if player.lp < player.attribute.max_lp:
  6632. player.lp += 5
  6633. if player.lp > player.attribute.max_lp:
  6634. player.lp = player.attribute.max_lp
  6635. message.add('Your wounds are cured.')
  6636. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6637. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = deepcopy(tl.tlist['functional'][7])
  6638. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].civilisation = False
  6639. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].build_here = False
  6640. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].can_grown = False
  6641. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace = replace
  6642. else:
  6643. message.add('You are not thirsty right now.')
  6644. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'resource':
  6645. res = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_resources[0]
  6646. num = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_resources[1]
  6647. try:
  6648. 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])
  6649. except:
  6650. None
  6651. test = player.inventory.materials.add(res,num)
  6652. if test != 'Full!':
  6653. sfx.play('pickup')
  6654. message.add(test)
  6655. replace = world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace
  6656. try:
  6657. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = deepcopy(tl.tlist[conected_tile[0]][conected_tile[1]])
  6658. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].replace = replace
  6659. except:
  6660. world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]] = replace
  6661. else:
  6662. message.add(test)
  6663. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'sleep':#this is a bed
  6664. #sleep a bit
  6665. sleep = True
  6666. lp = player.lp
  6667. while sleep:
  6668. screen.render_load(12)
  6669. time.tick()
  6670. player.attribute.tiredness += 5
  6671. if player.buffs.get_buff('adrenalised') > 0:
  6672. player.buffs.buff_list['adrenalised'] -= 5
  6673. if player.buffs.get_buff('adrenalised') < 0:
  6674. player.buffs.buff_list['adrenalised'] = 0
  6675. if player.lp < lp:
  6676. message.add('You were hurt!')
  6677. sleep = False
  6678. if player.attribute.tiredness >= player.attribute.tiredness_max:#wake up because you've slept enough
  6679. 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%
  6680. message.add('You feel refreshed.')
  6681. sleep = False
  6682. if int((player.attribute.hunger_max*100)/max(player.attribute.hunger,1)) < 11:
  6683. message.add('You feel hungry.')
  6684. sleep = False
  6685. if int((player.attribute.thirst_max*100)/max(player.attribute.thirst,1)) < 11:
  6686. message.add('You feel thirsty.')
  6687. sleep = False
  6688. monster_test = False
  6689. for y in range (player.pos[1]-1, player.pos[1]+2):#check for a monster
  6690. for x in range (player.pos[0]-1, player.pos[0]+2):
  6691. try:
  6692. 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
  6693. monster_test = True
  6694. except:
  6695. None
  6696. if monster_test == True:#wake up because a monster borders the players sleep
  6697. message.add('You wake up with a sense of danger.')
  6698. sleep = False
  6699. elif world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].use_group == 'gather':
  6700. help_container = container([world.maplist[self.pos[2]][self.on_map].tilemap[self.pos[1]][self.pos[0]].conected_items])
  6701. item_name