CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.32k stars 4.14k forks source link

The problem with importing vehicles #76687

Open IdleSol opened 4 days ago

IdleSol commented 4 days ago

Describe the bug

I will cite the error itself below. But it is not important. The problem is in the order of reading the json file created when exporting transport. If I understand correctly.

The situation is as follows. There is a truck in the game. It is possible to spawn it. There will be no errors. It can be exported to a file. Then put this file in the json folder and get an error preventing loading.

 DEBUG    : installing hdframe would make invalid vehicle: Part needs to be adjacent to or on existing structure.

 FUNCTION : int vehicle::install_part(const point&, vehicle_part&&)
 FILE     : src/vehicle.cpp
 LINE     : 1494
 VERSION  : cdda-experimental-2024-09-27-0529 918a370

 DEBUG    : init_vehicles: 'TEST' part 'hdframe'(31) can't be installed to -3,-1

 FUNCTION : void vehicles::finalize_prototypes()
 FILE     : src/veh_type.cpp
 LINE     : 1559
 VERSION  : cdda-experimental-2024-09-27-0529 918a370

Attach save file

123.json

Steps to reproduce

  1. Standard world and character

  2. Debug menu - spawning - vehicle - Semi Truck (semi_truck) - undamaged 1

  3. Debug menu - vehicle... - export vehicle as prototype - 123

  4. Quit the game

  5. Move the 123.json file from the ./export_dir folder to the ./data/json folder

  6. Change the id and name of the transport (optional)

    ...
    --  "id":"/TO_BE_REPLACED/",
    ++  "id":"test_123",
    "type":"vehicle",
    --  "name":"/TO_BE_REPLACED/",
    ++  "name":"test123",
    ...
  7. Save file

  8. Load a new world/save

  9. Get an error message

  10. Ignore error

  11. Debug menu - spawning - vehicle - test123 - undamaged

  12. Let's see the result 2

Expected behavior

n/a

Screenshots

No response

Versions and configuration

Additional context

No response

SurFlurer commented 4 days ago

Would you like to test whether this bug started to happen before 2024-09-16 or not?

IdleSol commented 4 days ago
 DEBUG    : init_vehicles: 'test123' part 'hdframe'(31) can't be installed to -3,-1

 FUNCTION : void vehicles::finalize_prototypes()
 FILE     : src/veh_type.cpp
 LINE     : 1591
 VERSION  : cdda-experimental-2024-08-01-0043 1fd261f

UPD. cdda-windows-tiles-x64-2023-12-01-0145 Same thing.

 DEBUG    : init_vehicles: 'test123' part 'hdframe'(31) can't be installed to -3,-1

 FUNCTION : void vehicles::finalize_prototypes()
 FILE     : src/veh_type.cpp
 LINE     : 1585
 VERSION  : d1c72bc

cdda-windows-tiles-x64-2023-05-29-0601 In this version, the vehicle parts are not known.

IdleSol commented 4 days ago

Why is there no error with the “original” truck? Because the order of parts in the trucks.json file is different from the order in the export file.

The export file sorts (maybe) by X coordinates, then Y coordinates. From negative numbers, to positive numbers. That is, in ascending order.

The file with the original truck starts from coordinates 0.0. But in this variant, we just got lucky.

If we talk about theoretical ways of fixing, then:

  1. Adding fake parts on empty tiles if they are bordered by vehicle parts. These fake parts can provide support and do not participate in the vehicle integrity check. Once spawning is complete, are replaced with open space
  2. Modifying the vehicle integrity check. Read all tiles first, then check.