Beispiel #1
0
void game_create_character_as_passenger(const ScriptArguments& args)
{
	auto vehicle = static_cast<VehicleObject*>(args.getObject<VehicleObject>(0));
	auto type = args[1].integerValue();
	RW_UNUSED(type);
	RW_UNIMPLEMENTED("game_create_character_as_passenger(): character type");
	auto id = args[2].integerValue();
	auto seat = args[3].integerValue();

	auto character = args.getWorld()->createPedestrian(id, vehicle->getPosition() + spawnMagic);
	new DefaultAIController(character);

	if (seat <= -1) {
		for (seat = 0; seat < static_cast<int>(vehicle->info->seats.size()); seat++) {
			if (vehicle->getOccupant(seat) == nullptr && !vehicle->isOccupantDriver(seat)) {
				break;
			}
		}
	} else {
		/// @todo 0 - passenger seat (or back seat of bike); 1 - left rear seat; 2 - right rear seat
		seat++;
	}

	RW_CHECK(seat < static_cast<int>(vehicle->info->seats.size()), "Seat index too high");
	RW_CHECK(vehicle->getOccupant(seat) == nullptr, "Seat is not free");
	RW_CHECK(vehicle->isOccupantDriver(seat) == false, "Seat is not a passenger seat");

	character->setCurrentVehicle(vehicle, seat);
	vehicle->setOccupant(seat, character);

	*args[4].globalInteger = character->getGameObjectID();
}
bool Activities::ExitVehicle::update(CharacterObject *character,
                                     CharacterController *controller) {
    RW_UNUSED(controller);

    if (jacked) {
        const auto jacked_lhs = AnimCycle::CarJackedLHS;
        const auto jacked_rhs = AnimCycle::CarJackedRHS;
        const auto cycle_current = character->getCurrentCycle();

        if (cycle_current == jacked_lhs || cycle_current == jacked_rhs) {
            if (character->animator->isCompleted(AnimIndexAction)) {
                return true;
            }
        } else {
            if (character->getCurrentVehicle() == nullptr) return true;

            auto vehicle = character->getCurrentVehicle();
            auto seat = character->getCurrentSeat();
            auto door = vehicle->getSeatEntryDoor(seat);
            RW_UNUSED(door);
            auto exitPos = vehicle->getSeatEntryPositionWorld(seat);
            auto exitPosLocal = vehicle->getSeatEntryPosition(seat);

            character->rotation = vehicle->getRotation();

            // Exit the vehicle immediatley
            character->enterVehicle(nullptr, seat);
            character->setPosition(exitPos);

            if (exitPosLocal.x > 0.f) {
                character->playCycle(jacked_rhs);
            } else {
                character->playCycle(jacked_lhs);
            }
            // No need to open the door, it should already be open.
        }
        return false;
    }

    if (character->getCurrentVehicle() == nullptr) return true;

    auto vehicle = character->getCurrentVehicle();
    auto seat = character->getCurrentSeat();
    auto door = vehicle->getSeatEntryDoor(seat);
    auto exitPos = vehicle->getSeatEntryPositionWorld(seat);
    auto exitPosLocal = vehicle->getSeatEntryPosition(seat);

    auto cycle_exit = AnimCycle::CarGetOutLHS;

    if (exitPosLocal.x > 0.f) {
        cycle_exit = AnimCycle::CarGetOutRHS;
    }

    if (vehicle->getVehicle()->vehicletype_ == VehicleModelInfo::BOAT) {
        auto ppos = character->getPosition();
        character->enterVehicle(nullptr, seat);
        character->setPosition(ppos);
        return true;
    }

    bool isDriver = vehicle->isOccupantDriver(character->getCurrentSeat());

    // If the vehicle is going too fast, slow down
    if (isDriver) {
        if (!vehicle->canOccupantExit()) {
            vehicle->setBraking(1.f);
            return false;
        }
    }

    if (character->getCurrentCycle() == cycle_exit) {
        if (character->animator->isCompleted(AnimIndexAction)) {
            character->enterVehicle(nullptr, seat);
            character->setPosition(exitPos);

            if (isDriver) {
                // Apply the handbrake
                vehicle->setHandbraking(true);
                vehicle->setThrottle(0.f);
            }

            return true;
        }
    } else {
        character->playCycle(cycle_exit);
        if (door) {
            vehicle->setPartTarget(door, true, door->openAngle);
        }
    }

    return false;
}