From f562a688c4542afa51832f6676194b07771cad3d Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Mon, 30 Nov 2015 21:50:51 +0100 Subject: [PATCH] Playground: try to unstuck spawned vehicles or the Clonk very scrupulously (#1442) --- .../PlayGround.ocs/SpawnMenu.ocd/Script.c | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/planet/Tutorials.ocf/PlayGround.ocs/SpawnMenu.ocd/Script.c b/planet/Tutorials.ocf/PlayGround.ocs/SpawnMenu.ocd/Script.c index b2a113720..c809bc631 100644 --- a/planet/Tutorials.ocf/PlayGround.ocs/SpawnMenu.ocd/Script.c +++ b/planet/Tutorials.ocf/PlayGround.ocs/SpawnMenu.ocd/Script.c @@ -439,6 +439,7 @@ private func SpawnObject(id obj_id) return; // Create object at the feet of the clonk. + var clonk_was_stuck = menu_controller->Stuck(); var obj = menu_controller->CreateObjectAbove(obj_id, 0, 9); // Clonk tries to collect the item. @@ -449,7 +450,39 @@ private func SpawnObject(id obj_id) if (menu_controller->Collect(obj, true)) return; } - + else if (obj->GetCategory() & C4D_Vehicle) + { + // Try to unstuck vehicles. + var original_x = obj->GetX(); + var original_y = obj->GetY(); + // Move up until not stuck anymore. + for (var i = 0; obj->Stuck() && (i < 52); i += 4) + obj->SetPosition(original_x, original_y - i); + // Still stuck? Nothing we can do for you (e.g. in tunnels). + if (obj->Stuck()) + { + obj->SetPosition(original_x, original_y); + } + else // Otherwise, gently put it down to the ground again. + { + for (var i = 0; !obj->Stuck() && (i < 5); ++i) + obj->SetPosition(original_x, obj->GetY() + 1); + obj->SetPosition(original_x, obj->GetY() - 1); + } + } + + // If whatever spawned made the Clonk stuck, free it. + if (!clonk_was_stuck && menu_controller->Stuck()) + { + var original_x = menu_controller->GetX(); + var original_y = menu_controller->GetY(); + // Move the Clonk up. + for (var i = 0; menu_controller->Stuck() && (i < 40); i += 2) + menu_controller->SetPosition(original_x, original_y - i); + // Still? Reset. + if (menu_controller->Stuck()) + menu_controller->SetPosition(original_x, original_y); + } return; }