Author Topic: [SOLVED] problems with plane spawn on my maps  (Read 325 times)

Offline blackwolf

  • Colonel
  • ****
  • Posts: 150
  • im back...i guess
    • View Profile
[SOLVED] problems with plane spawn on my maps
« on: February 05, 2024, 07:46:36 pm »
Hi everyone, I've run into some issues with my mod, and after exhausting all possible solutions on my own, I've decided to seek help here as I can't seem to find a clue about what to do.

Firstly, my problem has two aspects. I've edited the maps for the cruiser line (ported from TFTD by the CMP team) to include a 'helipad' at the stern. However, I'm not entirely sure how to determine the 'coordinates' that should be flagged to make my planes spawn there.

The second problem, I've encountered a persistent CTD issue when my planes, which are 20x20 in size, attempt to spawn on the map. I'm unsure about how to increase the size from the vanilla 10x20.

I've tried reading the rulesets, but it seems to work only on 'blocks generated' maps. When I attempt to adjust the numbers in this snippet:

```yaml
- type: CARGOSHIP
  commands:
    - type: addCraft
      rects:
        - [1, 0, 1, 2]
    - type: addBlock #Spawn Ship
      size: [3, 7]
```

My planes appear in some strange positions, including inside the walls. This makes me think that my theory about prop collision impeding ship generation was incorrect.

I've included the relevant lines of code below:

Spoiler:
#HERE IS THE PROBLEM
  - type: CRUISE_LINER # Thanks to Solarius Scorch!
    commands:
    - type: addBlock
      size: [3,2]
      rects:
        - [0,5,3,2]
    - type: addBlock
      size: [3,5]

#BEGIN CARGOSHIP
  - type: CARGOSHIP # Thanks to Hellrazor!
    commands:
    - type: addCraft #Size 10x20
      rects:
        - [1, 0, 1, 2]
    - type: addBlock #Spawn Ship
      size: [3, 7]
#END CARGOSHIP

#BEGIN LINERSHIP
  - type: LINERSHIP # Thanks to Hellrazor!
    commands: #No Craft spawning here, we have a entry area instead
    - type: addBlock
      size: [3,2]
      rects:
        - [0,5,3,2]
    - type: addBlock
      size: [3,5]
      rects:
        - [0,0,3,5]

Any help would be incredibly appreciated!
« Last Edit: February 09, 2024, 03:37:08 pm by blackwolf »

Offline CrazedHarpooner

  • Sergeant
  • **
  • Posts: 15
    • View Profile
Re: [Help Needed] problems with plane spawn on my maps
« Reply #1 on: February 05, 2024, 11:11:16 pm »
For said coordinates you need to take into account that rects is working with an implicit size of 10's. The top corner of the map is the most 'North-Western' corner and is the [0,0] block. The 1st value is the West-East placement of the block while the 2nd is the North-South. So with a value of [1,0,...,...] you're specifying the next block [1,0] which will be 10 tiles over (eastward) and 0 down. The last 2 values for the rect indicate how "wide" and "long" the rectangle is, so in [1,0,1,2] you're saying that the craft must be placed in a 10 wide by 20 long area but since you're saying your craft is actually 20x20 it can't fit it in said area, thus you will need to specify at least [1,0,2,2]

Now, for 'odd' placement of what you've tried, you need to take into consideration that crafts are spawned at map level 0 and WILL replace anything occupying the sprite space for that tile with the craft's sprites explaining the 'spawing in walls'. If you notice in vanilla TFTD, you can see all the helipad placements are placed at level 0.

The only thing that might help with the placement of the craft at a level different that 0 would be with 'verticalLevels' but it would require some experimenting to see if the results are desireable.
« Last Edit: February 06, 2024, 01:19:09 am by CrazedHarpooner »

Offline blackwolf

  • Colonel
  • ****
  • Posts: 150
  • im back...i guess
    • View Profile
Re: [SOLVED] problems with plane spawn on my maps
« Reply #2 on: February 08, 2024, 06:04:48 am »
you're saying that the craft must be placed in a 10 wide by 20 long area but since you're saying your craft is actually 20x20 it can't fit it in said area, thus you will need to specify at least [1,0,2,2]

Hi Crazyharponeer, just wanted to extend a big thank you for your assistance. I've managed to resolve the CTD issue related to the size of the ships in the cargo and cruiser liners, which is a huge relief. Additionally, I've made progress on getting the plane to spawn near the helipad, although there are still some errors to iron out. I'm still trying to determine if the values of the RECT related to the x and y position need to be multiples of ten, as adjusting them even by a single digit causes the spawning area to behave unpredictably.

On another note, I've encountered a new issue where one of my ships mysteriously spawns embedded in the floor. It looks like I'll need to conduct further testing to pinpoint the cause. However, on the bright side, thanks to your input, I've managed to fix a really old CTD issue. Your help has been invaluable.
« Last Edit: February 09, 2024, 03:37:32 pm by blackwolf »

Offline CrazedHarpooner

  • Sergeant
  • **
  • Posts: 15
    • View Profile
Re: [Help Needed] problems with plane spawn on my maps
« Reply #3 on: February 08, 2024, 02:22:00 pm »
To clarify, the values for the coordinates are not tile coordinates, but block coordinates if this is clearer, blocks being a size of 10x10 tiles. Because of this, whenever you increase or decrease by 1 either coordinate, the placement will shift 10 tiles over in the corresponding direction. The same goes for the 2 last values, they are how many blocks wide and long, not tiles.

By what I can see in the images, some of the craft seem to be even larger than 20x20, maybe even using a 20x30 map definition, you would need to view the MAP files to verify those. And then you have other craft that appear to be smaller. In the case of the smaller craft, they will spawn within the rects area defined, but at a random block within it. Let's say you define a rects of [1,0,2,3] but the craft MAP only uses a size of 10x20 the game can allocate them to any of these 3 positions [1,0], [1,1] or [1,2] since they are all within the defined rect.

There's a technique you can try with labels and conditionals to get it to work with different size craft MAPs. Do note that the size taken into consideration is the size defined in the MAP file of the craft, not the size of the craft itself, if I've made sense there. Basically, you could have a craft defined in a MAP of 20x20 that only uses 1 quarter of said map, the size would still be a 20x20 as per the definition in the MAP file.

Anyway, a sample of the technique would be as follows:
Code: [Select]
mapScripts:
  - type: CARGOSHIP
    commands:
    - type: addCraft
      label: 1
      rects:
        - [1, 0, 1, 2] #Fits only size MAP crafts of 10x20 or smaller.
    - type: addCraft
      label: 2
      conditionals: [-1]
      rects:
        - [1, 0, 2, 2] #Fits only size MAP crafts of 20x20 or smaller.
    - type: addCraft
      label: 3 # Can be omitted if no other conditional checks are made.
      conditionals: [-1,-2]
      rects:
        - [1, 0, 2, 3] #Fits only size MAP crafts of 20x30 or smaller.
    - type: addBlock #Spawn Ship
      size: [3, 7]

This script will ensure the craft will spawn as close as possible to the North of the map. The engine will go sequentially through the addCraft attempting to fit the craft in the defined area, if it's succesful, then the remaining addCraft will be skipped since the conditionals requires the commands with the corresponding labels to fail. If on the other hand it can't fit the craft, that command will fail and the next one in line will be attempted. Note that for this to work properly, you must always go from the smallest to the largest rect size, otherwise a small craft map will always fit in the largest rect and placed randomly within it.

For your last issue... perhaps I'm not entirely correct about craft always spawning at map level 0 but the engine trying to fit the craft height wise with the floor it has, if the craft is too "tall" then it starts to embed them as needed. You could try defining a larger height for the map either in the deployments or with a resize command in the script and see if this is the case or not as I'm just speculating at this point.
« Last Edit: February 09, 2024, 07:02:02 pm by CrazedHarpooner »

Offline blackwolf

  • Colonel
  • ****
  • Posts: 150
  • im back...i guess
    • View Profile
Re: [SOLVED] problems with plane spawn on my maps
« Reply #4 on: February 09, 2024, 03:36:24 pm »
There's a technique you can try with labels and conditionals to get it to work with different size craft MAPs.

Code: [Select]
mapScripts:
  - type: CARGOSHIP
    commands:
    - type: addCraft
      label: 1
      rects:
        - [1, 0, 1, 2] #Fits only size MAP crafts of 10x20 or smaller.
    - type: addCraft
      label: 2
      conditionals: [-1]
      rects:
        - [1, 0, 2, 2] #Fits only size MAP crafts of 20x20 or smaller.
    - type: addCraft
      label: 3 # Can be omitted if no other conditional checks are made.
      conditionals: [-1,-2]
      rects:
        - [1, 0, 2, 3] #Fits only size MAP crafts of 20x30 or smaller.
    - type: addBlock #Spawn Ship
      size: [3, 7]


"Yeah, that did the trick! This solution helped me resolve the problem with all ships landing correctly, except for just one (the 20x20). At this stage, it seems more feasible for me to edit and 'enlarge' the helipad platform instead of attempting to move the plane inside the MAP file, which could potentially cause misbehavior when interacting with other map scripts.

Thanks a ton for your help. This solution resolved my issue perfectly, and I truly appreciate your assistance.

(PS: Just to clarify, there wasn't any 20x30 plane, only 10x20 and 20x20 )."