示例#1
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();
}
示例#2
0
ScriptModel script::getModel(const ScriptArguments& args, ScriptModel model) {
    if (model < 0) {
        /// @todo verify that this is how the game uses negative models
        const auto& m = args.getVM()->getFile()->getModels()[-model];
        return args.getWorld()->data->findModelObject(m);
    }
    return model;
}
示例#3
0
void game_set_close_object_visible(const ScriptArguments& args)
{
	glm::vec3 position(args[0].real, args[1].real, args[2].real);
	float radius = args[3].real;
	int modelid = 0;
	
	/// @todo fix this being a problem.
	switch(args[4].type) {
		case TInt8:
			modelid = (std::int8_t)args[4].integer;
			break;
		case TInt16:
			modelid = (std::int16_t)args[4].integer;
			break;
		default:
			RW_ERROR("Unhandled integer type");
			break;
	}
	
	if( std::abs(modelid) > 178 ) {
		/// @todo implement this path,
		return;
	}
	
	std::string model;
	
	if(modelid < 0) modelid = -modelid;
	
	model = args.getVM()->getFile()->getModels()[modelid];
	
	std::transform(model.begin(), model.end(), model.begin(), ::tolower);
	
	for(auto& p : args.getWorld()->instancePool.objects) {
		auto o = p.second;
		if( !o->model ) continue;
		if( o->model->name != model ) continue;
		float d = glm::distance(position, o->getPosition());
		if( d < radius ) {
			o->visible = !!args[5].integer;
		}
	}
}
示例#4
0
void game_change_nearest_model(const ScriptArguments& args)
{
	glm::vec3 position(args[0].real, args[1].real, args[2].real);
	float radius = args[3].real;
	int newid = 0, oldid = 0;
	
	/// @todo fix this being a problem.
	switch(args[4].type) {
		case TInt8:
			oldid = (std::int8_t)args[4].integer;
			break;
		case TInt16:
			oldid = (std::int16_t)args[4].integer;
			break;
		default:
			RW_ERROR("Unhandled integer type");
			break;
	}
	
	switch(args[5].type) {
		case TInt8:
			newid = (std::int8_t)args[5].integer;
			break;
		case TInt16:
			newid = (std::int16_t)args[5].integer;
			break;
		default:
			RW_ERROR("Unhandled integer type");
			break;
	}
	
	if( std::abs(newid) > 178 || std::abs(oldid) > 178 ) {
		/// @todo implement this path,
		return;
	}
	
	std::string newmodel;
	std::string oldmodel;
	
	if(newid < 0) newid = -newid;
	if(oldid < 0) oldid = -oldid;
	
	newmodel = args.getVM()->getFile()->getModels()[newid];
	oldmodel = args.getVM()->getFile()->getModels()[oldid];
	std::transform(newmodel.begin(), newmodel.end(), newmodel.begin(), ::tolower);
	std::transform(oldmodel.begin(), oldmodel.end(), oldmodel.begin(), ::tolower);
	
	auto newobjectid = args.getWorld()->data->findModelObject(newmodel);
	auto nobj = args.getWorld()->data->findObjectType<ObjectData>(newobjectid);
	
	/// @todo Objects need to adopt the new object ID, not just the model.
	for(auto p : args.getWorld()->instancePool.objects) {
		auto o = p.second;
		if( !o->model ) continue;
		if( o->model->name != oldmodel ) continue;
		float d = glm::distance(position, o->getPosition());
		if( d < radius ) {
			args.getWorld()->data->loadDFF(newmodel + ".dff", false);
			InstanceObject* inst = static_cast<InstanceObject*>(o);
			inst->changeModel(nobj);
			inst->model = args.getWorld()->data->models[newmodel];
		}
	}
}
示例#5
0
void game_create_pickup(const ScriptArguments& args)
{
	glm::vec3 pos (args[2].real, args[3].real, args[4].real);
	int id;
	int type = args[1].integer;
	
	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");
			*args[5].globalInteger = 0;
			return;
	}
	
	if ( id < 0 )
	{
		id = -id;
		
		auto model = args.getVM()->getFile()->getModels()[id];
		std::transform(model.begin(), model.end(), model.begin(), ::tolower);
	
		id = args.getWorld()->data->findModelObject(model);
		args.getWorld()->data->loadDFF(model+".dff");
		args.getWorld()->data->loadTXD("icons.txd");
	}
	else
	{
		auto data = args.getWorld()->data->findObjectType<ObjectData>(id);
		
		if ( ! ( id >= 170 && id <= 184 ) )
		{
			args.getWorld()->data->loadDFF(data->modelName+".dff");
		}
		args.getWorld()->data->loadTXD(data->textureName+".txd");
	}
	
	PickupObject* pickup = nullptr;

	if ( id >= 170 && id <= 184 )
	{
		// Find the item for this model ID
		auto world = args.getWorld();
		InventoryItem *item = nullptr;
		for (auto i = 0; i < maxInventorySlots; ++i)
		{
			item = world->getInventoryItem(i);
			if (item->getModelID() == id) {
				auto pickuptype = (PickupObject::PickupType)type;
				pickup = new ItemPickup(args.getWorld(), pos, pickuptype, item);
				world->pickupPool.insert( pickup );
				world->allObjects.push_back(pickup);
				*args[5].globalInteger = pickup->getGameObjectID();
			}
		}
	}
	else
	{
		RW_UNIMPLEMENTED("non-item pickups");
		*args[5].globalInteger = 0;
	}
	
}
示例#6
0
文件: VMModule.cpp 项目: darkf/openrw
void vm_start_mission(const ScriptArguments& args)
{
	auto offset = args.getVM()->getFile()->getMissionOffsets()[args[0].integer];
	args.getVM()->startThread(offset, true);
}
示例#7
0
文件: VMModule.cpp 项目: darkf/openrw
void vm_new_mission_thread(const ScriptArguments& args)
{
	args.getVM()->startThread(args[0].integer, true);
}