예제 #1
0
파일: level.c 프로젝트: MasterQ32/SQEditor
void qlevel_export(char *filename)
{
	FILE *f = fopen(filename, "wb+");
	
	TQLevelHeader header;
	header.a = 42;
	header.b = 1337;
	header.c = -55;
	fwrite(&header, sizeof(TQLevelHeader), 1, f);
	fflush(f);
	
	TQLevelItemHeader item;
	for(you = ent_next(NULL); you != NULL; you = ent_next(you))
	{
		switch(you->group)
		{
			case GROUP_LEVEL:
				item.type = GROUP_LEVEL;
				item.length = sizeof(TQLevelEntity);
				fwrite(&item, sizeof(TQLevelItemHeader), 1, f);
				
				TQLevelEntity entityEntry;
				strcpy(entityEntry.filename, _chr(you->type));
				vec_set(&entityEntry.pos, &you->x);
				vec_set(&entityEntry.angle, &you->pan);
				vec_set(&entityEntry.scale, &you->scale_x);
				entityEntry.actioncount = 0;
				ActionInformation *entry;
				for(entry = list_first(you->string1); entry != NULL; entry = list_next(you->string1, entry))
				{
					entityEntry.actioncount++;
				}
				fwrite(&entityEntry, sizeof(TQLevelEntity), 1, f);
				
				ActionInformation *entry;
				for(entry = list_first(you->string1); entry != NULL; entry = list_next(you->string1, entry))
				{
					TQLevelAction entryAction;
					strcpy(entryAction.actionname, entry->actionname);
					fwrite(&entryAction, sizeof(TQLevelAction), 1, f);					
				}
				break;
			case GROUP_LIGHT:
				item.type = GROUP_LIGHT;
				item.length = sizeof(TQLevelLight);
				fwrite(&item, sizeof(TQLevelItemHeader), 1, f);
				
				TQLevelLight lightEntry;
				
				vec_set(&lightEntry.pos, &you->x);
				vec_set(&lightEntry.angle, &you->pan);
				vec_set(&lightEntry.color, &you->blue);
				lightEntry.range = you->lightrange;
				
				if(you->string2 != NULL)
				{
					strcpy(lightEntry.lightmap, _chr(you->string2));
				}
				
				fwrite(&lightEntry, sizeof(TQLevelLight), 1, f);	
				break;
		}
	}
	
	item.type = -1;
	item.length = 0;
	fwrite(&item, sizeof(TQLevelItemHeader), 1, f);
	
	fclose(f);
}
예제 #2
0
파일: platform.c 프로젝트: Acknex/Ackmania
// uses: id, speed, idletime 
action moving_platform()
{
	set(my, is_platform);
	my->ptr_start = NULL;
	my->ptr_end   = NULL;
	if (my->idletime == 0) my->idletime = 0.001;
	
	wait (1);

	for(you = ent_next(NULL); (you != NULL) && (my->ptr_end == NULL); you = ent_next(you))
	{
		if ((your->id == my->id) && (my->id > 0) && is(you, is_marker))
		{
			if (my->ptr_start == NULL)
			{
				my->ptr_start = handle(you);
			}
			else if (my->ptr_end == NULL)
			{
				my->ptr_end = handle(you);
			}
			else
			{
				//do nothing
			}
		}
	}
	
	if ((my->ptr_end == NULL) || (my->id <= 0))
	{
		printf("incorrect platform marker for id %d", (int)my->id);
		return;
	}

	//platform start point
	VECTOR vecSpeed;
	VECTOR vecTemp;
	ENTITY *ent1, *ent2, *entTarget, *entCur, *entTemp;
	
	ent1 = ptr_for_handle(my->ptr_start);
	ent2 = ptr_for_handle(my->ptr_end);
	
	//directional speed
	vec_set(&vecSpeed, &ent2->x);
	vec_sub(&vecSpeed, &ent1->x);
	vec_normalize(&vecSpeed, my->speed);

	if (vec_dist(&ent1->x, &my->x) < vec_dist(&ent2->x, &my->x))
	{
		vec_set(&my->x, &ent1->x);
		entTarget = ent2;
		entCur    = ent1;
	}
	else
	{
		vec_set(&my->x, &ent2->x);			
		entTarget = ent1;
		entCur    = ent2;
		vec_scale(&vecSpeed, -1);
	}

	//entity loop
	while(1)
	{		
		vec_set(vecTemp, vecSpeed);
		vec_scale(vecTemp, time_step);
		vec_set(&my->absspeed_x, &vecTemp);
		
 		you = player;
		c_move(me, nullvector, &vecTemp, IGNORE_MODELS | IGNORE_SPRITES | IGNORE_YOU | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_MAPS);

		if(vec_dist(&entTarget->x, &my->x) < 20)
		{
			wait (1);
			vec_set(&my->absspeed_x, nullvector);
			wait(-(my->idletime));

			vec_scale(&vecSpeed, -1);
			entTemp   = entCur;
			entCur    = entTarget;
			entTarget = entTemp;			
		}
		
		wait (1);
	}
}
예제 #3
0
파일: level.c 프로젝트: MasterQ32/SQEditor
void qlevel_save(STRING *filename)
{
	STRING *file = "#256";
	make_path(file, filename);
	
	STRING *backup = "#256";
	str_cpy(backup, file);
	str_cat(backup, ".bak");
	file_delete(backup);
	file_rename(file, backup);
	
	ini_write_int(file, "Level Information", "EntityCount", 0);
	ini_write_int(file, "Level Information", "LightCount", 0);
	ini_write_int(file, "Level Information", "FogCount", 0);
	
	int countEntity = 0;
	int countLight = 0;
	int countFog = 0;
	
	STRING *section = "#64";
	for(you = ent_next(NULL); you != NULL; you = ent_next(you))
	{
		switch(you->group)
		{
			case GROUP_LEVEL:
				str_cpy(section, "Entity ");
				str_cat(section, str_for_int(NULL, countEntity));
				
				ini_write_string(file, section, "Model", you->type);
				ini_write_int(file, section, "ActionCount", 0);
				int actionCount = 0;
				STRING *actionName = "#64";
				ActionInformation *entry;
				for(entry = list_first(you->string1); entry != NULL; entry = list_next(you->string1, entry))
				{
					str_cpy(actionName, "Action");
					str_cat(actionName, str_for_int(NULL, actionCount));
					ini_write_string(file, section, actionName, _str(entry->actionname));
					actionCount++;
				}
				ini_write_int(file, section, "ActionCount", actionCount);
				
				ini_write_float(file, section, "X", you->x);
				ini_write_float(file, section, "Y", you->y);
				ini_write_float(file, section, "Z", you->z);
				ini_write_float(file, section, "Pan", cycle(you->pan, 0, 360));
				ini_write_float(file, section, "Tilt", cycle(you->tilt, 0, 360));
				ini_write_float(file, section, "Roll", cycle(you->roll, 0, 360));
				ini_write_float(file, section, "ScaleX", you->scale_x);
				ini_write_float(file, section, "ScaleY", you->scale_y);
				ini_write_float(file, section, "ScaleZ", you->scale_z);
				ini_write_float(file, section, "Lightrange", you->lightrange);

				countEntity++;
				break;
		}
	}
	
	ini_write_int(file, "Level Information", "EntityCount", countEntity);
	ini_write_int(file, "Level Information", "LightCount", countLight);
	ini_write_int(file, "Level Information", "FogCount", countFog);
}
예제 #4
0
파일: platform.c 프로젝트: Acknex/Ackmania
// uses: id, speed 
action rotating_platform()
{
	set(my, is_platform);
	my->ptr_start = NULL;
	my->ptr_end   = NULL;
	
	wait (1);

	for(you = ent_next(NULL); (you != NULL) && (my->ptr_end == NULL); you = ent_next(you))
	{
		if ((your->id == my->id) && (my->id > 0) && is(you, is_marker))
		{
			if (my->ptr_start == NULL)
			{
				my->ptr_start = handle(you);
			}
			else if (my->ptr_end == NULL)
			{
				my->ptr_end = handle(you);
			}
			else
			{
				//do nothing
			}
		}
	}
	
	if ((my->ptr_end == NULL) || (my->id <= 0))
	{
		printf("incorrect platform marker for id %d", (int)my->id);
		return;
	}

	//platform start point
	VECTOR vecSpeed, vecTemp;
	ENTITY *ent1, *ent2, *entCenter;
	var vRadius;
	var vAngle;
	
	ent1 = ptr_for_handle(my->ptr_start);
	ent2 = ptr_for_handle(my->ptr_end);
	
	if (vec_dist(&ent1->x, &my->x) < vec_dist(&ent2->x, &my->x))
	{
		vec_set(&my->x, &ent1->x);
		entCenter = ent2;
		ent2->y = ent1->y;
	}
	else
	{
		vec_set(&my->x, &ent2->x);			
		entCenter = ent1;
		ent1->y = ent2->y;
	}

	//directional speed
	vec_set(&vecSpeed, nullvector);
	vRadius = vec_dist(&ent1->x, &ent2->x);

	//entity loop
	while(1)
	{		
		vAngle += time_step * my->speed;
		vAngle = ang(vAngle);
		vec_set(&vecSpeed, nullvector);
		vecSpeed.x = vRadius;
		vec_rotate(&vecSpeed, vector(0, vAngle, 0));
		vec_add(&vecSpeed, &entCenter->x);
		vec_sub(&vecSpeed, &my->x);
		vec_scale(&vecSpeed, time_step);
		vec_set(&my->absspeed_x, &vecSpeed);
		
 		you = player;
		c_move(me, nullvector, &vecSpeed, IGNORE_MODELS | IGNORE_SPRITES | IGNORE_YOU | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_MAPS);

		wait (1);
	}
}