示例#1
0
/* Must be called after LmrModel init is called */
void SpaceStation::Init()
{
	if (stationTypesInitted) return;
	stationTypesInitted = true;
	for (int is_orbital=0; is_orbital<2; is_orbital++) {
		std::vector<LmrModel*> models;
		if (is_orbital) LmrGetModelsWithTag("orbital_station", models);
		else LmrGetModelsWithTag("surface_station", models);

		for (std::vector<LmrModel*>::iterator i = models.begin();
				i != models.end(); ++i) {
			SpaceStationType t;
			t.modelName = (*i)->GetName();
			t.model = LmrLookupModelByName(t.modelName);
			t.dockMethod = SpaceStationType::DOCKMETHOD(is_orbital);
			t.numDockingPorts = (*i)->GetIntAttribute("num_docking_ports");
			t.dockOneAtATimePlease = (*i)->GetBoolAttribute("dock_one_at_a_time_please");
			t.ReadStageDurations();
			//printf("one at a time? %s\n", t.dockOneAtATimePlease ? "yes" : "no");
			//printf("%s: %d docking ports\n", t.modelName, t.numDockingPorts);
			if (is_orbital) {
				t.angVel = (*i)->GetFloatAttribute("angular_velocity");
				orbitalStationTypes.push_back(t);
			}
			else surfaceStationTypes.push_back(t);
		}
	}
	//printf(SIZET_FMT " orbital station types and " SIZET_FMT " surface station types.\n", orbitalStationTypes.size(), surfaceStationTypes.size());
}
示例#2
0
static void _define_ships(const char *tag, ShipType::Tag stag, std::vector<ShipType::Type> &list)
{
	std::vector<LmrModel*> ship_models;
	LmrGetModelsWithTag(tag, ship_models);
	lua_State *L = LmrGetLuaState();
	int num = 0;

	for (std::vector<LmrModel*>::iterator i = ship_models.begin();
			i != ship_models.end(); ++i) {
		LmrModel *model = *i;
		model->PushAttributeToLuaStack("ship_defs");
		if (lua_isnil(L, -1)) {
			Error("Model %s is tagged as ship but has no ship_defs.",
					model->GetName());
		} else if (lua_istable(L, -1)) {
			// multiple ship-defs for 1 model
			for (unsigned int j=0; j<lua_objlen(L,-1); j++) {
				lua_pushinteger(L, j+1);
				lua_gettable(L, -2);
				_define_ship(L, model->GetName(), list, stag);
				num++;
				lua_pop(L, 1);
			}
		} else {
			Error("Model %s: ships_def is malformed", model->GetName());
		}
		lua_pop(L, 1);
	}
	printf("ShipType: %d ships with tag '%s'\n", num, tag);
}
示例#3
0
void ShipType::Init()
{
	static bool isInitted = false;
	if (isInitted) return;
	isInitted = true;

	std::vector<LmrModel*> ship_models;
	LmrGetModelsWithTag("ship", ship_models);
	lua_State *L = LmrGetLuaState();
	int num = 0;

	for (std::vector<LmrModel*>::iterator i = ship_models.begin();
			i != ship_models.end(); ++i) {
		LmrModel *model = *i;
		model->PushAttributeToLuaStack("ship_defs");
		if (lua_isnil(L, -1)) {
			Error("Model %s is tagged as ship but has no ship_defs.",
					model->GetName());
		} else if (lua_istable(L, -1)) {
			// multiple ship-defs for 1 model
			for (unsigned int i=0; i<lua_objlen(L,-1); i++) {
				lua_pushinteger(L, i+1);
				lua_gettable(L, -2);
				define_ship(L, model->GetName());
				num++;
				lua_pop(L, 1);
			}
		} else {
			Error("Model %s: ships_def is malformed", model->GetName());
		}
		lua_pop(L, 1);
	}
	printf("%d ship types.\n", num);
}
示例#4
0
void SpaceStation::Render(const vector3d &viewCoords, const matrix4x4d &viewTransform)
{
	/* Well this is nice... */
	static int poo=0;
	if (!poo) {
		poo = 1;
		LmrGetModelsWithTag("advert", s_advertModels);
	}
	// it is silly to do this every render call
	//
	// random advert models in pFlag[16 .. 19]
	// station name in pText[0]
	// docking port in pText[1]
	MTRand rand;
	rand.seed(m_sbody->seed);
	
	LmrObjParams &params = GetLmrObjParams();
	/* random advert models */
	params.argStrings[4] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName();
	params.argStrings[5] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName();
	params.argStrings[6] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName();
	params.argStrings[7] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName();
	params.argStrings[0] = GetLabel().c_str();
	SetLmrTimeParams();

	for (int i=0; i<MAX_DOCKING_PORTS; i++) {
		params.argDoubles[ARG_STATION_BAY1_STAGE + i] = double(m_shipDocking[i].stage);
		params.argDoubles[ARG_STATION_BAY1_POS + i] = m_shipDocking[i].stagePos;
	}

	RenderLmrModel(viewCoords, viewTransform);
	
	/* don't render city if too far away */
	if (viewCoords.Length() > 1000000.0) return;

	// find planet Body*
	Planet *planet;
	{
		Body *_planet = GetFrame()->m_astroBody;
		if ((!_planet) || !_planet->IsType(Object::PLANET)) {
			// orbital spaceport -- don't make city turds
		} else {
			planet = static_cast<Planet*>(_planet);
		
			if (!m_adjacentCity) {
				m_adjacentCity = new CityOnPlanet(planet, this, m_sbody->seed);
			}
			m_adjacentCity->Render(this, viewCoords, viewTransform);
		}
	}
}
示例#5
0
static void lookupBuildingListModels(citybuildinglist_t *list)
{
	//const char *modelTagName;
	std::vector<LmrModel*> models;
	LmrGetModelsWithTag(list->modelTagName, models);
	//printf("Got %d buildings of tag %s\n", models.size(), list->modelTagName);
	list->buildings = new citybuilding_t[models.size()];
	list->numBuildings = models.size();

	int i = 0;
	for (std::vector<LmrModel*>::iterator m = models.begin(); m != models.end(); ++m, i++) {
		list->buildings[i].resolvedModel = *m;
		const LmrCollMesh *collMesh = new LmrCollMesh(*m, &cityobj_params);
		list->buildings[i].collMesh = collMesh;
		double maxx = std::max(fabs(collMesh->GetAabb().max.x), fabs(collMesh->GetAabb().min.x));
		double maxy = std::max(fabs(collMesh->GetAabb().max.z), fabs(collMesh->GetAabb().min.z));
		list->buildings[i].xzradius = sqrt(maxx*maxx + maxy*maxy);
		//printf("%s: %f\n", list->buildings[i].modelname, list->buildings[i].xzradius);
	}
}