Add totally repair car (#190)

* Implement TotallyRepairCar

* Implement ResetCarScreens

* Implement CarWorldOffFallenCheckThingy

* Implement MungeRearviewSky

* Add comment about BrModelUpdate(..., 0x3)
This commit is contained in:
Anonymous Maarten 2022-10-16 10:11:51 +02:00 committed by GitHub
parent bec1e51e02
commit 4689b4e9a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 5 deletions

View File

@ -4446,7 +4446,15 @@ void ResetCarScreens() {
int i;
tCar_spec* the_car;
LOG_TRACE("()");
STUB();
for (cat = eVehicle_self; cat < eVehicle_drone; cat++) {
car_count = (cat == eVehicle_self) ? 1 : GetCarCount(cat);
for (i = 0; i < car_count; i++) {
the_car = (cat == eVehicle_self) ? &gProgram_state.current_car : GetCarSpec(cat, i);
the_car->last_special_volume = NULL;
}
}
MungeCarGraphics(gFrame_period);
}
// IDA: tCar_spec* __cdecl GetRaceLeader()

View File

@ -27,6 +27,7 @@
#include "piping.h"
#include "powerup.h"
#include "pratcam.h"
#include "raycast.h"
#include "replay.h"
#include "s3/s3.h"
#include "sound.h"
@ -1185,8 +1186,41 @@ int CarWorldOffFallenCheckThingy(tCar_spec* pCar, int pCheck_around) {
int result;
LOG_TRACE("(%p, %d)", pCar, pCheck_around);
STUB_ONCE();
return 0;
if (pCar->number_of_wheels_on_ground != 0) {
return 0;
}
if (pCar->driver == eDriver_local_human && gCar_flying) {
return 0;
}
if (gAction_replay_mode) {
return 0;
}
BrVector3Copy(&car_pos, &pCar->car_master_actor->t.t.translate.t);
if (FindYVerticallyBelow2(&car_pos) >= -100.f) {
return 0;
}
BrVector3Set(&offset_c, 0.f, 1.f, 0.f);
BrMatrix34ApplyV(&offset_w, &offset_c, &pCar->car_master_actor->t.t.mat);
if (FindYVerticallyBelow2(&car_pos) >= -100.f) {
// FIXME: testing twice using `FindYVerticallyBelow2' is meaningless
return 0;
}
if (!pCheck_around) {
return 1;
}
pCar->car_master_actor->t.t.translate.t.v[0] += 0.05f;
result = CarWorldOffFallenCheckThingy(pCar, 0);
pCar->car_master_actor->t.t.translate.t.v[0] -= 0.05f;
if (!result) {
return 0;
}
pCar->car_master_actor->t.t.translate.t.v[2] += 0.05f;
result = CarWorldOffFallenCheckThingy(pCar, 0);
pCar->car_master_actor->t.t.translate.t.v[2] -= 0.05f;
if (!result) {
return 0;
}
return 1;
}
// IDA: int __usercall HasCarFallenOffWorld@<EAX>(tCar_spec *pCar@<EAX>)

View File

@ -453,7 +453,47 @@ void TotallyRepairACar(tCar_spec* pCar) {
br_bounds storage_bounds;
LOG_TRACE("(%p)", pCar);
STUB();
StopCarSmokingInstantly(pCar);
if (IsActionReplayAvailable()) {
PipeInstantUnSmudge(pCar);
}
pCar->repair_time += 100000;
for (i = 0; i < COUNT_OF(pCar->damage_units); i++) {
pCar->damage_units[i].damage_level = 0;
pCar->damage_units[i].last_level = 0;
pCar->damage_units[i].smoke_last_level = 0;
}
memcpy(&storage_bounds, &pCar->bounds[1], sizeof(br_bounds));
memcpy(&pCar->bounds[1], &pCar->max_bounds[1], sizeof(br_bounds));
if (TestForCarInSensiblePlace(pCar)) {
for (j = 0; j < pCar->car_actor_count; j++) {
the_car_actor = &pCar->car_model_actors[j];
if (the_car_actor->undamaged_vertices != NULL) {
pipe_vertex_count = 0;
for (k = 0; k < the_car_actor->actor->model->nvertices; k++) {
if (pipe_vertex_count < COUNT_OF(pipe_array)) {
BrVector3Sub(&pipe_array[pipe_vertex_count].delta_coordinates,
&the_car_actor->undamaged_vertices[k].p, &the_car_actor->actor->model->vertices[k].p);
if (!Vector3IsZero(&pipe_array[pipe_vertex_count].delta_coordinates)) {
pipe_array[pipe_vertex_count].vertex_index = k;
pipe_vertex_count++;
}
}
}
memcpy(the_car_actor->actor->model->vertices,
the_car_actor->undamaged_vertices,
the_car_actor->actor->model->nvertices * sizeof(br_vertex));
// FIXME: BrModelUpdate(..., BR_MODU_EDGES | BR_MODU_NORMALS) fails on TELL_ME_IF_WE_PASS_THIS_WAY
// BrModelUpdate(the_car_actor->actor->model, BR_MODU_EDGES | BR_MODU_NORMALS);
BrModelUpdate(the_car_actor->actor->model, BR_MODU_ALL);
if (pipe_vertex_count != 0 && IsActionReplayAvailable()) {
PipeSingleModelGeometry(pCar->car_ID, j, pipe_vertex_count, pipe_array);
}
}
}
} else {
memcpy(&pCar->bounds[1], &storage_bounds, sizeof(br_bounds));
}
}
// IDA: void __cdecl TotallyRepairCar()

View File

@ -949,5 +949,8 @@ void MungeForwardSky() {
// IDA: void __cdecl MungeRearviewSky()
void MungeRearviewSky() {
LOG_TRACE("()");
STUB();
if (gSky_image_width != 0) {
MungeSkyModel(gRearview_camera, gRearview_sky_model);
}
}