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();
}
Beispiel #2
0
void game_create_object_world(const ScriptArguments& args)
{
	int id = 0;
	switch(args[0].type) {
		case TInt8:
			id = (std::int8_t)args[0].integer;
			break;
		case TInt16:
			id = (std::int16_t)args[0].integer;
			break;
		default:
			RW_ERROR("Unhandled integer type");
			break;
	}
	
	if( id < 0 ) {
		auto& modelname = args.getVM()->getFile()->getModels()[-id];
		id = args.getWorld()->data->findModelObject(modelname);
		if( id == (uint16_t)-1 ) {
			args.getWorld()->logger->error("SCM", "Failed to find model " + modelname);
		}
	}

	glm::vec3 position(args[1].real, args[2].real, args[3].real);

	auto inst = args.getWorld()->createInstance(id, position);

	*args[4].globalInteger = inst->getGameObjectID();
}
Beispiel #3
0
void game_create_vehicle(const ScriptArguments& args)
{
	auto id	= args[0].integer;
	glm::vec3 position(args[1].real, args[2].real, args[3].real);
	if( position.z < -99.f ) {
		position = args.getWorld()->getGroundAtPosition(position);
	}
	position += spawnMagic;

	auto vehicle = args.getWorld()->createVehicle(id, position);

	if ( args.getThread()->isMission )
	{
		args.getState()->missionObjects.push_back(vehicle->getGameObjectID());
	}

	*args[4].globalInteger = vehicle->getGameObjectID();
}
Beispiel #4
0
/// Remove object from cleanup at end of missions.
void game_dont_remove_object(const ScriptArguments& args)
{
    auto object = args.getObject<VehicleObject>(0);
    if(object)
    {
        auto id = object->getGameObjectID();
	
        auto& mO = args.getState()->missionObjects;
        mO.erase(std::remove(mO.begin(), mO.end(), id), mO.end());
    }
}
Beispiel #5
0
void game_create_character(const ScriptArguments& args)
{
	auto type = args[0].integer;
	auto id	= args[1].integer;
	glm::vec3 position(args[2].real, args[3].real, args[4].real);
	
	if( type == 21 ) {
		
	}
	if( position.z < -99.f ) {
		position = args.getWorld()->getGroundAtPosition(position);
	}
	
	auto character = args.getWorld()->createPedestrian(id, position + spawnMagic);
	/* Controller will give ownership to character */
	new DefaultAIController(character);
	
	if ( args.getThread()->isMission )
	{
		args.getState()->missionObjects.push_back(character->getGameObjectID());
	}
	
	*args[5].globalInteger = character->getGameObjectID();
}
Beispiel #6
0
void game_create_character_in_vehicle(const ScriptArguments& args)
{
	auto vehicle = static_cast<VehicleObject*>(args.getObject<VehicleObject>(0));
	auto type = args[1].integer;
	RW_UNUSED(type);
	RW_UNIMPLEMENTED("game_create_character_in_vehicle(): character type");
	auto id = args[2].integer;
	
	auto character = args.getWorld()->createPedestrian(id, vehicle->getPosition() + spawnMagic);
	new DefaultAIController(character);
	
	character->setCurrentVehicle(vehicle, 0);
	vehicle->setOccupant(0, character);
	
	*args[3].globalInteger = character->getGameObjectID();
}
Beispiel #7
0
void game_create_player(const ScriptArguments& args)
{
	auto id = args[0].integer;
	if (id != 0) {
		RW_UNIMPLEMENTED("Multiple player characters not supported");
	}

	glm::vec3 position(args[1].real, args[2].real, args[3].real);
	
	if( position.z < -99.f ) {
		position = args.getWorld()->getGroundAtPosition(position);
	}
	
	auto pc = args.getWorld()->createPlayer(position + spawnMagic);
    args.getState()->playerObject = pc->getGameObjectID();
    *args[4].globalInteger = args.getWorld()->players.size()-1;
}
Beispiel #8
0
void IngameState::startTest()
{
	auto playerChar = getWorld()->createPlayer({270.f, -605.f, 40.f});
	auto player = new PlayerController(playerChar);

	getWorld()->state->playerObject = playerChar->getGameObjectID();

	/*auto bat = new WeaponItem(getWorld()->data.weaponData["ak47"]);
	_playerCharacter->addToInventory(bat);
	_playerCharacter->setActiveItem(bat->getInventorySlot());*/

	glm::vec3 itemspawn( 276.5f, -609.f, 36.5f);
	for(int i = 1; i < maxInventorySlots; ++i) {
		ItemPickup* pickup =
					new ItemPickup(
						getWorld(),
						itemspawn,
						getWorld()->getInventoryItem(i));
		getWorld()->pickupPool.insert(pickup);
		getWorld()->allObjects.push_back(pickup);
		itemspawn.x += 2.5f;
	}

	auto carPos = glm::vec3( 286.f, -591.f, 37.f );
	auto carRot = glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f));
	//auto boatPos = glm::vec3( -1000.f, -1040.f, 5.f );
	int i = 0;
	for( auto& vi : getWorld()->data->objectTypes ) {
		switch( vi.first ) {
		case 140: continue;
		case 141: continue;
		}
		if( vi.second->class_type == ObjectInformation::_class("CARS") )
		{
			if ( i++ > 20 ) break;
			auto vehicle = std::static_pointer_cast<VehicleData>(vi.second);

			auto& sp = carPos;
			auto& sr = carRot;
			auto v = getWorld()->createVehicle(vi.first, sp, sr);

			sp += sr * glm::vec3( 2.f + v->info->handling.dimensions.x, 0.f, 0.f);
		}
	}
}
Beispiel #9
0
 int getScriptObjectID() const {
     return getGameObjectID();
 }