Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *Adaptive Metaroom Placement Search by Amaikokonut (naturingnurturing.blogspot.com)
- *You are free to modify/build upon this script but please leave the attribution
- *intact and allow others to modify/build upon your derivative too!
- *!* For this test script we are going to inject a clone of the DS hub
- *(room structure only, no doors/agents)
- *I've tried to mark comments about hub-specific code with the symbol '*!*'
- *so if you are adapting this to your own metaroom you can hopefully find the
- *room-specific pieces of code and change them without looking too hard.
- *First we're going to make sure this room hasn't already been injected
- *!*We're going to do this by checking to see if the GAME variable "AMP_DS_Hub"
- *!*(or whatever name you want to give your metaroom) exists and contains a number
- *After sucessful injection this variable will be created and assigned the room number
- *so it can easily be referenced later by agents looking for that specific room
- *(This also means that AMP rooms can't have an ID of 0 but we'll address that issue later)
- *checks if the type is an integer (It really always should be but if for some reason
- *it's not and we try to run the second check anyway we get errors, so better safe)
- doif type game "AMP_DS_Hub" eq 0
- doif game "AMP_DS_Hub" > 0
- *a number is here, so the room has already been injected
- *so we'll just point the camera at the existing room to show the player it's there
- *and then stop the script
- meta game "AMP_DS_Hub" 0 0 0
- stop
- endi
- endi
- *otherwise, proceed
- *!* The DS Hub is 1124px width and 832px tall, those numbers are reflected below:
- *VA50, the width of the room you are trying to inject
- setv va50 1124
- *VA51, the height of the room
- setv va51 832
- *VA52, the density of room checks
- *(Setting this higher will result in faster checking but runs the risk of missing
- *any metarooms smaller than its check and throwing errors)
- setv va52 300
- *va00 and va01 define the x/y point that is currently being checked
- setv va00 0
- setv va01 0
- *va99 is the search status flag:
- * 0 = Empty spot not yet found (search in progress)
- * 1 = Empty spot found
- * 2 = Entire map searched but no empty spot was found (hopefully this won't happen)
- setv va99 0
- *va98 is another search status flag specified in the roomcheck subroutine
- *GMAP returns the ID of the metaroom at point x y.
- *if there is no metaroom, reports -1
- *so basically it needs to report -1 for all checks to be considered
- *a viable free space to inject the room.
- *starting the search loop:
- loop
- *first see if this va00 (x) and va01 (y) are valid to start from.
- doif gmap va00 va01 eq -1
- *It's valid, so go on.
- gsub roomcheck
- *when roomcheck returns it will hold flag va98 containing either 1 or 2
- *if va98 is 1, you have found a good spot
- doif va98 eq 1
- setv va99 1
- *if va98 is 2 (or anything else for some reason) it means those startcoords
- *didnt work, so run the startcoords routine to find new ones
- else
- gsub startcoords
- endi
- else
- gsub startcoords
- endi
- untl va99 gt 0
- *this loop ends when va99 (the search flag) is no longer marked as 'in progress'
- *if va99 is 2, there was no empty space found in the entire metaroom system, injection not
- *possible (should probably change this later to increase the size of the map
- *and try again)
- doif va99 eq 2
- outs "could not find space"
- stop
- endi
- *otherwise, va99 is 1 and we can proceed safely
- *!*TIME FOR ROOM CREATION! The lot of this is hub-specific.
- *!* The ORIGINAL code to inject the hub metaroom (found in !map.cos) is:
- **************************************************************
- * outv addm 2071 8732 1124 832 "SPRITE_CorridorBackdrop004" *
- **************************************************************
- *But this is our NEW, ADAPTIVE way:
- * a refresher: va00 and va01 are the x/y start coordinates we found with all the
- * previous scripts.
- * va50/va51 are the width and height (established early on in this file)
- *!* We're using the hub-room name for the last argument
- setv va60 addm va00 va01 va50 va51 "SPRITE_CorridorBackdrop004"
- *va60 now holds the room number for the new metaroom! We did it!
- *point your camera at it:
- cmra va00 va01 0
- *Set some gamevars for easy access/reference by agents later on:
- *!* Again, these use the hub-name
- setv game "AMP_DS_Hub" va60
- *Not sure if we strictly need these but it sure is easier than parsing MLOC every time.
- setv game "AMP_DS_Hub_x" va00
- setv game "AMP_DS_Hub_y" va01
- setv game "AMP_DS_Hub_w" va50
- setv game "AMP_DS_Hub_h" va51
- *I think having a string with the names of AMP-enabled rooms would be nice to be able to
- *call up, and parse as needed, like a named EMID"
- *this checks if the string already exists first (type is 2) and adds to it if it is.
- *Don't forget the space after the name!
- doif type game "AMP_listing" eq 2
- adds game "AMP_listing" "AMP_DS_Hub "
- *if it's not there, it starts the string itself
- else
- sets game "AMP_listing" "AMP_DS_Hub "
- endi
- *Okay this is possibly the hard/annoying part for converting: adding rooms
- *!*Also pretty much everything from here to the subroutines is hub-specific
- *With the 'static' hub it begins adding rooms from the number 600
- *We're obviously using adaptively-numbered rooms here so we can't rely on that
- *but to make things easier we're going use some temp game variables named
- *after the old room names so we know what's what when we are making doors later.
- *So the ORIGINAL code for the first room in the DS hub (found in !map.cos) is:
- ****************************************************
- * setv va00 addr 10 2195 2287 8999 8999 9161 9185 *
- ****************************************************
- * in which the numbers represent the following:
- *METAROOM_ID: 10
- *X_LEFT: 2195
- *X_RIGHT: 2287
- *Y_LEFT_CEILING: 8999
- *Y_RIGHT_CEILING: 8999
- *Y_LEFT_FLOOR: 9161
- *Y_RIGHT_FLOOR: 9185
- *But these assume that the room is starting at the original x/y coords which are:
- * 2071, 8732 *
- *meanwhile we are starting at va00/va01, so we have to do some math.
- *First by finding the difference between the coordinates of the original rooms
- *Like this:
- *diff X_LEFT: OLD X_LEFT (2195) - OLD X-coord (2071) = 124
- *diff X_RIGHT: OLD X_RIGHT (2287) - OLD X-coord (2071) = 216
- *diff Y_LEFT_CEILING: OLD Y_LEFT_CEILING (8999) - OLD Y-coord (8732) = 267
- *diff Y_RIGHT_CEILING: OLD Y_RIGHT_CEILING (8999) - OLD Y-coord (8732) = 267
- *diff Y_LEFT_FLOOR: OLD Y_LEFT_FLOOR (9161) - OLD Y-coord (8732) = 429
- *diff Y_RIGHT_FLOOR: OLD Y_RIGHT_FLOOR (9185) - OLD Y-coord (8732) = 453
- *Now that we've subtracted the old coord, we're going to re-add our now coords
- *(still va00 and va01)
- *We're going to use va70 (X_LEFT), va71 (X_RIGHT), va72 (Y_LEFT_CEILING),
- *va73 (Y_RIGHT_CEILING), va74 (Y_LEFT_FLOOR), and va75 (Y_RIGHT_FLOOR)
- setv va70 124
- addv va70 va00
- setv va71 216
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 429
- addv va74 va01
- setv va75 453
- addv va75 va01
- *And now that the calculations are complete, we're finally adding the room
- *Remember va60 holds the current metaroom ID
- *And again, this is originally room 600, so we're going to make a temp game var
- *so we can easily reference later:
- setv game "AMP_temp_room_600" addr va60 va70 va71 va72 va73 va74 va75
- *and set the room type same as it's set in the original cosfile (0 - air )
- rtyp game "AMP_temp_room_600" 0
- *Wow, that was a pain. Now we have to repeat this process for the SEVENTEEN OTHER ROOMS
- *THAT ARE IN THE DS HUB. Screw this, I'm going to write a python script to do this.
- **Here are the rest of the rooms after having python do the worst of the work
- **Also included, MMSC and RMSC (metaroom music and room music) conversions:
- *additional room 600 music
- setv va70 562
- addv va70 va00
- setv va71 416
- addv va71 va01
- mmsc va70 va71 "ds_music.mng\\MetallicChords"
- setv va70 170
- addv va70 va00
- setv va71 360
- addv va71 va01
- rmsc va70 va71 ""
- *room 601
- setv va70 216
- addv va70 va00
- setv va71 313
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 453
- addv va74 va01
- setv va75 460
- addv va75 va01
- setv game "AMP_temp_room_601" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_601" 0
- setv va70 264
- addv va70 va00
- setv va71 363
- addv va71 va01
- rmsc va70 va71 ""
- *room 602
- setv va70 313
- addv va70 va00
- setv va71 410
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 460
- addv va74 va01
- setv va75 464
- addv va75 va01
- setv game "AMP_temp_room_602" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_602" 0
- setv va70 361
- addv va70 va00
- setv va71 365
- addv va71 va01
- rmsc va70 va71 ""
- *room 603
- setv va70 410
- addv va70 va00
- setv va71 503
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 464
- addv va74 va01
- setv va75 453
- addv va75 va01
- setv game "AMP_temp_room_603" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_603" 0
- setv va70 456
- addv va70 va00
- setv va71 360
- addv va71 va01
- rmsc va70 va71 ""
- *room 604
- setv va70 503
- addv va70 va00
- setv va71 613
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 453
- addv va74 va01
- setv va75 453
- addv va75 va01
- setv game "AMP_temp_room_604" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_604" 0
- setv va70 558
- addv va70 va00
- setv va71 360
- addv va71 va01
- rmsc va70 va71 "ds_music.mng\\Tremelo"
- *room 605
- setv va70 613
- addv va70 va00
- setv va71 709
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 453
- addv va74 va01
- setv va75 462
- addv va75 va01
- setv game "AMP_temp_room_605" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_605" 0
- setv va70 661
- addv va70 va00
- setv va71 364
- addv va71 va01
- rmsc va70 va71 ""
- *room 606
- setv va70 709
- addv va70 va00
- setv va71 816
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 462
- addv va74 va01
- setv va75 461
- addv va75 va01
- setv game "AMP_temp_room_606" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_606" 0
- setv va70 762
- addv va70 va00
- setv va71 364
- addv va71 va01
- rmsc va70 va71 ""
- *room 607
- setv va70 816
- addv va70 va00
- setv va71 909
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 461
- addv va74 va01
- setv va75 452
- addv va75 va01
- setv game "AMP_temp_room_607" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_607" 0
- setv va70 862
- addv va70 va00
- setv va71 359
- addv va71 va01
- rmsc va70 va71 ""
- *room 608
- setv va70 909
- addv va70 va00
- setv va71 1006
- addv va71 va00
- setv va72 267
- addv va72 va01
- setv va73 267
- addv va73 va01
- setv va74 452
- addv va74 va01
- setv va75 430
- addv va75 va01
- setv game "AMP_temp_room_608" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_608" 0
- setv va70 957
- addv va70 va00
- setv va71 348
- addv va71 va01
- rmsc va70 va71 "ds_music.mng\\TremeloBleep"
- *room 609
- setv va70 909
- addv va70 va00
- setv va71 991
- addv va71 va00
- setv va72 176
- addv va72 va01
- setv va73 247
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_609" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_609" 0
- setv va70 950
- addv va70 va00
- setv va71 221
- addv va71 va01
- rmsc va70 va71 ""
- *room 610
- setv va70 816
- addv va70 va00
- setv va71 909
- addv va71 va00
- setv va72 150
- addv va72 va01
- setv va73 176
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_610" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_610" 0
- setv va70 862
- addv va70 va00
- setv va71 208
- addv va71 va01
- rmsc va70 va71 ""
- *room 611
- setv va70 709
- addv va70 va00
- setv va71 816
- addv va71 va00
- setv va72 150
- addv va72 va01
- setv va73 150
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_611" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_611" 0
- setv va70 762
- addv va70 va00
- setv va71 208
- addv va71 va01
- rmsc va70 va71 ""
- *room 612
- setv va70 613
- addv va70 va00
- setv va71 709
- addv va71 va00
- setv va72 150
- addv va72 va01
- setv va73 150
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_612" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_612" 0
- setv va70 661
- addv va70 va00
- setv va71 208
- addv va71 va01
- rmsc va70 va71 ""
- *room 613
- setv va70 503
- addv va70 va00
- setv va71 613
- addv va71 va00
- setv va72 148
- addv va72 va01
- setv va73 150
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_613" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_613" 0
- setv va70 558
- addv va70 va00
- setv va71 207
- addv va71 va01
- rmsc va70 va71 ""
- *room 614
- setv va70 410
- addv va70 va00
- setv va71 503
- addv va71 va00
- setv va72 146
- addv va72 va01
- setv va73 148
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_614" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_614" 0
- setv va70 456
- addv va70 va00
- setv va71 206
- addv va71 va01
- rmsc va70 va71 ""
- *room 615
- setv va70 313
- addv va70 va00
- setv va71 410
- addv va71 va00
- setv va72 146
- addv va72 va01
- setv va73 146
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_615" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_615" 0
- setv va70 361
- addv va70 va00
- setv va71 206
- addv va71 va01
- rmsc va70 va71 ""
- *room 616
- setv va70 216
- addv va70 va00
- setv va71 313
- addv va71 va00
- setv va72 181
- addv va72 va01
- setv va73 146
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_616" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_616" 0
- setv va70 264
- addv va70 va00
- setv va71 224
- addv va71 va01
- rmsc va70 va71 ""
- *room 617
- setv va70 124
- addv va70 va00
- setv va71 216
- addv va71 va00
- setv va72 243
- addv va72 va01
- setv va73 181
- addv va73 va01
- setv va74 267
- addv va74 va01
- setv va75 267
- addv va75 va01
- setv game "AMP_temp_room_617" addr va60 va70 va71 va72 va73 va74 va75
- rtyp game "AMP_temp_room_617" 0
- setv va70 170
- addv va70 va00
- setv va71 255
- addv va71 va01
- rmsc va70 va71 ""
- ****************************************************************************
- *good lord that was annoying. Note to self: find a way to rewrite this more
- *efficiently
- **And now DOORS
- **We stored all the NEW room numbers in variables named after their old room numbers
- *just so this part would be easier. The original script sets doors according to their
- *room numbers IE:
- *door 600 601 100
- *door 600 617 100
- * So to convert them we just have to call the the variables we set:
- door game "AMP_temp_room_600" game "AMP_temp_room_601" 100
- door game "AMP_temp_room_600" game "AMP_temp_room_617" 100
- door game "AMP_temp_room_601" game "AMP_temp_room_602" 100
- door game "AMP_temp_room_601" game "AMP_temp_room_616" 100
- door game "AMP_temp_room_602" game "AMP_temp_room_603" 100
- door game "AMP_temp_room_602" game "AMP_temp_room_615" 100
- door game "AMP_temp_room_603" game "AMP_temp_room_604" 100
- door game "AMP_temp_room_603" game "AMP_temp_room_614" 100
- door game "AMP_temp_room_604" game "AMP_temp_room_605" 100
- door game "AMP_temp_room_604" game "AMP_temp_room_613" 100
- door game "AMP_temp_room_605" game "AMP_temp_room_606" 100
- door game "AMP_temp_room_605" game "AMP_temp_room_612" 100
- door game "AMP_temp_room_606" game "AMP_temp_room_607" 100
- door game "AMP_temp_room_606" game "AMP_temp_room_611" 100
- door game "AMP_temp_room_607" game "AMP_temp_room_608" 100
- door game "AMP_temp_room_607" game "AMP_temp_room_610" 100
- door game "AMP_temp_room_608" game "AMP_temp_room_609" 100
- door game "AMP_temp_room_609" game "AMP_temp_room_610" 100
- door game "AMP_temp_room_610" game "AMP_temp_room_611" 100
- door game "AMP_temp_room_611" game "AMP_temp_room_612" 100
- door game "AMP_temp_room_612" game "AMP_temp_room_613" 100
- door game "AMP_temp_room_613" game "AMP_temp_room_614" 100
- door game "AMP_temp_room_614" game "AMP_temp_room_615" 100
- door game "AMP_temp_room_615" game "AMP_temp_room_616" 100
- door game "AMP_temp_room_616" game "AMP_temp_room_617" 100
- *Almost there: Now we just have to make a standard favico!
- *I think using "metaroom number + 100" is probably an okay standard for AMP-icons species
- *classifier numbers.
- *It's high enough not to clash with static C3/DS favicos (afaik) and low enough not to
- *interfere in most 3rd party classifiers:
- setv va61 va60
- addv va61 100
- new: simp 1 3 va61 "fav_place_corridor" 1 0 1
- attr 272
- mvto va00 va01
- tick 10
- *One last thing: we're gonna cleanup all the temp gamevars:
- delg "AMP_temp_room_600"
- delg "AMP_temp_room_601"
- delg "AMP_temp_room_602"
- delg "AMP_temp_room_603"
- delg "AMP_temp_room_604"
- delg "AMP_temp_room_605"
- delg "AMP_temp_room_606"
- delg "AMP_temp_room_607"
- delg "AMP_temp_room_608"
- delg "AMP_temp_room_609"
- delg "AMP_temp_room_610"
- delg "AMP_temp_room_611"
- delg "AMP_temp_room_612"
- delg "AMP_temp_room_613"
- delg "AMP_temp_room_614"
- delg "AMP_temp_room_615"
- delg "AMP_temp_room_616"
- delg "AMP_temp_room_617"
- **THE END**
- **SUBRS** (You shouldn't have to modify these)
- **Finds some empty coords to start with
- **va00/va01 are the current candidates for startcoords
- **va52 is the room check density (checks for an empty space every va52px)
- subr startcoords
- *if you're not at the max world x, add va52
- doif va00 le mapw
- addv va00 va52
- *if you are at the max world x, set it to 0 and add va52 to Y
- elif va01 le maph
- setv va00 0
- addv va01 va52
- *if you've maxed out both you have a problem, stop and set status flag to 2
- elif va00 ge mapw and va01 ge maph
- setv va99 2
- endi
- retn
- *roomcheck executes after proper startcoords hace been found (va00/va01)
- **va52 is the room check density (checks for an empty space every va52px)
- **va98 comes up in here too, it's another status flag
- ** 0 - So far so good
- ** 1 - Everything checks out
- ** 2 - Something is in the way (this will return to the main script where it will
- ** attempt to find new startcoords and try again)
- subr roomcheck
- *so in this you have to check 0 0, 0 va52, 0 va52 + va52, then va52 0, va52 va52,
- *va52 va52 + va52, etc etc...
- setv va02 va00
- setv va03 va01
- *va02 and 03 are going to be your little "tester" x/y
- setv va04 va02
- setv va05 va03
- addv va04 va50
- addv va05 va51
- *va04 and va05 are your bottom-right coords, the endpoints.
- *found by adding your start coords to the height/width of the room
- *go ahead and make sure those are valid too before starting...
- doif gmap va04 va05 eq -1 and va04 lt mapw and va05 lt maph
- setv va98 0
- *If your start and end points are both valid, start the loop to check
- *everything in between.
- loop
- *check validity
- doif gmap va02 va03 eq -1
- *now, how are the x's?
- doif va02 lt va04
- *add va52 to the x
- addv va02 va52
- *now, have you checked all the x's but not all the y's?
- elif va02 ge va04 and va03 lt va05
- *add va52 to the y, and reset the x
- setv va02 va00
- addv va03 va52
- *have you checked them all?
- elif va02 ge va04 and va03 ge va05
- *Success!
- setv va98 1
- endi
- else
- *if it didn't check out, you'll have to start again.
- setv va98 2
- endi
- untl va98 gt 0
- else
- setv va98 2
- endi
- retn
- **REMOVE SCRIPT TO BE ADDED (I'm tired right now and want to get this posted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement