Example #1
0
int put_mark_on_position(int map_x, int map_y, char * name)
{
		if (map_x < 0
		|| map_x >= tile_map_size_x*6
		|| map_y < 0
		|| map_y >= tile_map_size_y*6
		|| max_mark>=MAX_USER_MARKS) {
						return 0;
		}
		marks[max_mark].x = map_x;
		marks[max_mark].y = map_y;
		memset(marks[max_mark].text,0,sizeof(marks[max_mark].text));
		
		my_strncp(marks[max_mark].text,name,sizeof(marks[max_mark].text));
		marks[max_mark].text[strlen(marks[max_mark].text)]=0;

		marks[max_mark].server_side=0;

		marks[max_mark].r=curmark_r;
		marks[max_mark].g=curmark_g;
		marks[max_mark].b=curmark_b;
		
		max_mark++;
		save_markings();
		return 1;
}
Example #2
0
void load_entrable_list()
{
	FILE *f = NULL;
	char strLine[255];
	int off;

	memset(entrable_objects, 0, sizeof(entrable_objects));
	nr_entrable_objects = 0;
	f=open_file_data("entrable.lst", "rb");
	if(f == NULL)
	{
		LOG_ERROR("%s: %s \"entrable.lst\": %s\n", reg_error_str, cant_open_file, strerror(errno));
		return;
	}
	while (nr_entrable_objects < MAX_ENTRABLE_OBJECTS)
	{
		if (fscanf(f, "%254s", strLine) != 1)
			break;
		my_tolower(strLine);
		off = *strLine == '/' ? 1 : 0;
		my_strncp(entrable_objects[nr_entrable_objects], strLine+off,
			OBJ_NAME_SIZE);
		nr_entrable_objects++;
		if (!fgets(strLine, sizeof(strLine), f))
			break;
	}
	fclose(f);

	// Sort the list so we can use binary search
	qsort(entrable_objects, nr_entrable_objects, OBJ_NAME_SIZE,
		(int(*)(const void*,const void*))strcmp);
}
Example #3
0
static obj_2d_def* load_obj_2d_def(const char *file_name)
{
	int f_size;
	el_file_ptr file = NULL;
	char cur_dir[200]={0};
	obj_2d_def *cur_object;
	const char *obj_file_mem;
	const char* sep;

	sep = strrchr(file_name, '/');
	if (!sep || sep == file_name)
		*cur_dir = '\0';
	else
		my_strncp(cur_dir, file_name, sep-file_name+1);

	file = el_open(file_name);
	if (!file)
	{
		LOG_ERROR("%s: %s \"%s\": %s\n", reg_error_str, cant_open_file, file_name, strerror(errno));
		return NULL;
	}

	obj_file_mem = el_get_pointer(file);
	if (!obj_file_mem)
	{
		LOG_ERROR("%s: %s (read)\"%s\"\n", reg_error_str, cant_open_file, file_name);
		el_close(file);
		return NULL;
	}
	f_size = el_get_size(file);

	//ok, the file is loaded, so parse it
	cur_object=calloc(1, sizeof(obj_2d_def));
	my_strncp(cur_object->file_name, file_name,
		sizeof(cur_object->file_name));
	parse_2d0(obj_file_mem, f_size, cur_dir, cur_object);

	el_close(file);

	return cur_object;
}
Example #4
0
void get_string_value(char *buf, size_t maxlen, const xmlNode *node)
{
	if (!node)
	{
		LOG_ERROR("Node is null!");
		buf[0] = '\0';
		return;
	}

	if (!node->children)
		buf[0] = '\0';
	else
		my_strncp(buf, (const char*)node->children->content, maxlen);
}
Example #5
0
void read_config()
{
	// Set our configdir
	const char * tcfg = get_path_config();

	my_strncp (configdir, tcfg , sizeof(configdir));

	if ( !read_el_ini () )
	{
		// oops, the file doesn't exist, give up
		LOG_ERROR("Failure reading mapedit.ini");
		SDL_Quit ();
		exit (1);
	}
}
Example #6
0
int command_storage(char *text, int len)
{
	int i;

	storage_filter[0] = '\0';

	for (i = 0; i < len; i++) {
		if (text[i] == ' ') {
			break;
		}
	}

	if (i < len)
	{
		int nb = len - i - 1;
		if (nb > sizeof (storage_filter) - 1)
			nb = sizeof (storage_filter) - 1;
		my_strncp (storage_filter, text+i+1, nb+1);
	}

	if (have_storage_list)
	{
		int size = strlen((char*)cached_storage_list)+1;
		unsigned char cached_storage_copy[sizeof(cached_storage_list)];
		unsigned char * endl;
		memcpy(cached_storage_copy, cached_storage_list, size);
		endl = (unsigned char*)strchr((char*)cached_storage_copy, '\n');
		if (endl == NULL)
		{
			// No newline? Our cached list isn't correct.
			return 0;
		}
		if (storage_filter[0] != '\0')
		{
			size = filter_storage_text((char*)endl+1, size, size);  //Note: filter from the first newline, which is where the item list starts
			size += (endl - cached_storage_copy +1);
		}
		put_text_in_buffer(CHAT_SERVER, cached_storage_copy, size);
		return 1;
	}
	return 0;
}
Example #7
0
int add_2d_obj(char * file_name, float x_pos, float y_pos, float z_pos,
			   float x_rot, float y_rot, float z_rot, unsigned int dynamic)
{
	int i;//,len,k;
	char	fname[128];
	obj_2d_def *returned_obj_2d_def;
	obj_2d *our_object;
#ifndef CLUSTER_INSIDES
	float len_x, len_y;
#endif
	unsigned int alpha_test, texture_id;
	AABBOX bbox;

	//find a free spot, in the obj_2d_list
	for(i=0; i<MAX_OBJ_2D; i++)
		{
			if(!obj_2d_list[i])break;
		}

	// but first convert to lower case and replace any '\' by '/'
	clean_file_name(fname, file_name, sizeof(fname));

	returned_obj_2d_def=load_obj_2d_def_cache(fname);
	if(!returned_obj_2d_def)
	{
		LOG_ERROR ("%s: %s: %s", reg_error_str, cant_load_2d_object, fname);
		return -1;
	}

	our_object = calloc(1, sizeof(obj_2d));
	my_strncp(our_object->file_name, fname, 80);
	our_object->x_pos=x_pos;
	our_object->y_pos=y_pos;
	our_object->z_pos=z_pos;

	our_object->x_rot=x_rot;
	our_object->y_rot=y_rot;
	our_object->z_rot=z_rot;
	our_object->obj_pointer=returned_obj_2d_def;
	our_object->display= 1;
	our_object->state= 0;

	obj_2d_list[i]=our_object;

#ifdef CLUSTER_INSIDES
	if (returned_obj_2d_def->object_type == PLANT)
	{
		x_rot += 90.0f;
		z_rot = 0.0f;
	}
	else if (returned_obj_2d_def->object_type == FENCE)
	{
		x_rot += 90.0f;
	}
	calc_rotation_and_translation_matrix(our_object->matrix, x_pos, y_pos, 0.0f, x_rot, y_rot, z_rot);

	our_object->cluster = get_cluster ((int)(x_pos/0.5f), (int)(y_pos/0.5f));
	current_cluster = our_object->cluster;
#else
	len_x = (returned_obj_2d_def->x_size);
	len_y = (returned_obj_2d_def->y_size);
	bbox.bbmin[X] = -len_x*0.5f;
	bbox.bbmax[X] = len_x*0.5f;
	if (returned_obj_2d_def->object_type == GROUND)
	{
		bbox.bbmin[Y] = -len_y*0.5f;
		bbox.bbmax[Y] = len_y*0.5f;
	}
	else
	{
		bbox.bbmin[Y] = 0.0f;
		bbox.bbmax[Y] = len_y;
		if (returned_obj_2d_def->object_type == PLANT)
		{
			x_rot += 90.0f;
			z_rot = 0.0f;
			bbox.bbmin[X] *= M_SQRT2;
			bbox.bbmax[X] *= M_SQRT2;
			bbox.bbmin[Y] *= M_SQRT2;
			bbox.bbmax[Y] *= M_SQRT2;
		}
		else if (returned_obj_2d_def->object_type == FENCE) x_rot += 90.0f;
	}
	bbox.bbmin[Z] = z_pos;
	bbox.bbmax[Z] = z_pos;
	
	calc_rotation_and_translation_matrix(our_object->matrix, x_pos, y_pos, 0.0f, x_rot, y_rot, z_rot);
	matrix_mul_aabb(&bbox, our_object->matrix);
#endif // CLUSTER_INSIDES

	if (returned_obj_2d_def->alpha_test) alpha_test = 1;
	else alpha_test = 0;

	texture_id = returned_obj_2d_def->texture_id;
	
#ifdef CLUSTER_INSIDES
	if (get_2d_bbox (i, &bbox))
	{
		if (main_bbox_tree_items != NULL && dynamic == 0)
			add_2dobject_to_list (main_bbox_tree_items, i, bbox, alpha_test, texture_id);
		else
			add_2dobject_to_abt (main_bbox_tree, i, bbox, alpha_test, texture_id, dynamic);
	}
#else
	if ((main_bbox_tree_items != NULL) && (dynamic == 0)) add_2dobject_to_list(main_bbox_tree_items, i, bbox, alpha_test, texture_id);
	else add_2dobject_to_abt(main_bbox_tree, i, bbox, alpha_test, texture_id, dynamic);
#endif // CLUSTER_INSIDES
	
	return i;
}
Example #8
0
void add_enhanced_actor_from_server(char * in_data)
{
	short actor_id;
	short x_pos;
	short y_pos;
	short z_pos;
	short z_rot;
	short max_health;
	short cur_health;
	Uint8 actor_type;
	Uint8 skin;
	Uint8 hair;
	Uint8 shirt;
	Uint8 pants;
	Uint8 boots;
	Uint8 frame;
	Uint8 cape;
	Uint8 head;
	Uint8 shield;
	Uint8 weapon;
	Uint8 helmet;
	int i;
	int dead=0;
	int kind_of_actor;
	enhanced_actor *this_actor;

	char cur_frame[20];
	double f_x_pos,f_y_pos,f_z_pos,f_z_rot;

	actor_id=*((short *)(in_data));
	x_pos=*((short *)(in_data+2));
	y_pos=*((short *)(in_data+4));
	z_pos=*((short *)(in_data+6));
	z_rot=*((short *)(in_data+8));
	actor_type=*(in_data+10);
	skin=*(in_data+12);
	hair=*(in_data+13);
	shirt=*(in_data+14);
	pants=*(in_data+15);
	boots=*(in_data+16);
	head=*(in_data+17);
	shield=*(in_data+18);
	weapon=*(in_data+19);
	cape=*(in_data+20);
	helmet=*(in_data+21);

	frame=*(in_data+22);
	max_health=*((short *)(in_data+23));
	cur_health=*((short *)(in_data+25));
	kind_of_actor=*(in_data+27);

	//translate from tile to world
	f_x_pos=x_pos*0.5;
	f_y_pos=y_pos*0.5;
	f_z_pos=z_pos;
	f_z_rot=z_rot;

	//get the current frame
	switch(frame) {
	case frame_walk:
		my_strcp(cur_frame,actors_defs[actor_type].walk_frame);break;
	case frame_run:
		my_strcp(cur_frame,actors_defs[actor_type].run_frame);break;
	case frame_die1:
		my_strcp(cur_frame,actors_defs[actor_type].die1_frame);
		dead=1;
		break;
	case frame_die2:
		my_strcp(cur_frame,actors_defs[actor_type].die2_frame);
		dead=1;
		break;
	case frame_pain1:
		my_strcp(cur_frame,actors_defs[actor_type].pain1_frame);break;
	case frame_pain2:
		my_strcp(cur_frame,actors_defs[actor_type].pain2_frame);break;
	case frame_pick:
		my_strcp(cur_frame,actors_defs[actor_type].pick_frame);break;
	case frame_drop:
		my_strcp(cur_frame,actors_defs[actor_type].drop_frame);break;
	case frame_idle:
		my_strcp(cur_frame,actors_defs[actor_type].idle_frame);break;
	case frame_sit_idle:
		my_strcp(cur_frame,actors_defs[actor_type].idle_sit_frame);break;
	case frame_harvest:
		my_strcp(cur_frame,actors_defs[actor_type].harvest_frame);break;
	case frame_cast:
		my_strcp(cur_frame,actors_defs[actor_type].attack_cast_frame);break;
	case frame_attack_up_1:
		my_strcp(cur_frame,actors_defs[actor_type].attack_up_1_frame);break;
	case frame_attack_up_2:
		my_strcp(cur_frame,actors_defs[actor_type].attack_up_2_frame);break;
	case frame_attack_up_3:
		my_strcp(cur_frame,actors_defs[actor_type].attack_up_3_frame);break;
	case frame_attack_up_4:
		my_strcp(cur_frame,actors_defs[actor_type].attack_up_4_frame);break;
	case frame_attack_down_1:
		my_strcp(cur_frame,actors_defs[actor_type].attack_down_1_frame);break;
	case frame_attack_down_2:
		my_strcp(cur_frame,actors_defs[actor_type].attack_down_2_frame);break;
	case frame_combat_idle:
		my_strcp(cur_frame,actors_defs[actor_type].combat_idle_frame);break;
	default:
		{
		}
	}

	//find out if there is another actor with that ID
	//ideally this shouldn't happen, but just in case
	for(i=0;i<max_actors;i++)
		{
			if(actors_list[i])
				{
					if(actors_list[i]->actor_id==actor_id)
						{
							char str[256];
							sprintf(str,"%s %d = %s => %s\n",duplicate_actors_str,actor_id, actors_list[i]->actor_name ,&in_data[28]);
							log_error(str);
							destroy_actor(actors_list[i]->actor_id);//we don't want two actors with the same ID
							i--;// last actor was put here, he needs to be checked too
						}
					else if(kind_of_actor==COMPUTER_CONTROLLED_HUMAN && (actors_list[i]->kind_of_actor==COMPUTER_CONTROLLED_HUMAN || actors_list[i]->kind_of_actor==PKABLE_COMPUTER_CONTROLLED) && !my_strcompare(&in_data[28], actors_list[i]->actor_name))
						{
							char str[256];
							sprintf(str,"%s(%d) = %s => %s\n",duplicate_npc_actor,actor_id, actors_list[i]->actor_name ,&in_data[28]);
							log_error(str);
							destroy_actor(actors_list[i]->actor_id);//we don't want two actors with the same ID
							i--;// last actor was put here, he needs to be checked too
						}
				}
		}

	this_actor=calloc(1,sizeof(enhanced_actor));

	//get the torso
	my_strcp(this_actor->arms_tex,actors_defs[actor_type].shirt[shirt].arms_name);
	my_strcp(this_actor->torso_tex,actors_defs[actor_type].shirt[shirt].torso_name);
	my_strcp(this_actor->torso_fn,actors_defs[actor_type].shirt[shirt].model_name);
	//skin
	my_strcp(this_actor->hands_tex,actors_defs[actor_type].skin[skin].hands_name);
	my_strcp(this_actor->hands_tex_save,actors_defs[actor_type].skin[skin].hands_name);
	my_strcp(this_actor->head_tex,actors_defs[actor_type].skin[skin].head_name);
	//hair
	my_strcp(this_actor->hair_tex,actors_defs[actor_type].hair[hair].hair_name);
	//boots
	my_strcp(this_actor->boots_tex,actors_defs[actor_type].boots[boots].boots_name);
	//legs
	my_strcp(this_actor->pants_tex,actors_defs[actor_type].legs[pants].legs_name);
	my_strcp(this_actor->legs_fn,actors_defs[actor_type].legs[pants].model_name);
	//cape
	if(cape!=CAPE_NONE)
		{
			my_strcp(this_actor->cape_tex,actors_defs[actor_type].cape[cape].skin_name);
			my_strcp(this_actor->cape_fn,actors_defs[actor_type].cape[cape].model_name);
		}
	else
		{
			my_strcp(this_actor->cape_tex,"");
			my_strcp(this_actor->cape_fn,"");
		}
	//head
	my_strcp(this_actor->head_fn,actors_defs[actor_type].head[head].model_name);

	//shield
	if(shield!=SHIELD_NONE)
		{
			my_strcp(this_actor->shield_tex,actors_defs[actor_type].shield[shield].skin_name);
			my_strcp(this_actor->shield_fn,actors_defs[actor_type].shield[shield].model_name);
		}
	else
		{
			my_strcp(this_actor->shield_tex,"");
			my_strcp(this_actor->shield_fn,"");
		}

	my_strcp(this_actor->weapon_tex,actors_defs[actor_type].weapon[weapon].skin_name);
	my_strcp(this_actor->weapon_fn,actors_defs[actor_type].weapon[weapon].model_name);
	this_actor->weapon_glow=actors_defs[actor_type].weapon[weapon].glow;
	if(weapon == GLOVE_FUR || weapon == GLOVE_LEATHER){
		my_strcp(this_actor->hands_tex, actors_defs[actor_type].weapon[weapon].skin_name);
	}

	//helmet
	if(helmet!=HELMET_NONE)
		{
			my_strcp(this_actor->helmet_tex,actors_defs[actor_type].helmet[helmet].skin_name);
			my_strcp(this_actor->helmet_fn,actors_defs[actor_type].helmet[helmet].model_name);
		}
	else
		{
			my_strcp(this_actor->helmet_tex,"");
			my_strcp(this_actor->helmet_fn,"");
		}

	i=add_enhanced_actor(this_actor,cur_frame,f_x_pos,f_y_pos,f_z_pos,f_z_rot,actor_id);

	actors_list[i]->x_tile_pos=x_pos;
	actors_list[i]->y_tile_pos=y_pos;
	actors_list[i]->actor_type=actor_type;
	actors_list[i]->damage=0;
	actors_list[i]->damage_ms=0;
	actors_list[i]->sitting=0;
	actors_list[i]->fighting=0;
	//test only
	actors_list[i]->max_health=max_health;
	actors_list[i]->cur_health=cur_health;
	if(frame==frame_sit_idle)
		{
			if(actors_list[i]->actor_id==yourself)you_sit_down();
			actors_list[i]->sitting=1;
		}
	else if(frame==frame_combat_idle)
		actors_list[i]->fighting=1;

	//ghost or not?
	actors_list[i]->ghost=0;

	actors_list[i]->dead=dead;
	actors_list[i]->stop_animation=1;//helps when the actor is dead...
	actors_list[i]->cur_weapon=weapon;
	actors_list[i]->kind_of_actor=kind_of_actor;
	if(strlen(&in_data[28]) >= 30)
		{
			char str[120];
			snprintf(str, 120, "%s (%d): %s/%d\n", bad_actor_name_length, actors_list[i]->actor_type,&in_data[28], (int)strlen(&in_data[28]));
			log_error(str);
			return;
		}

	my_strncp(actors_list[i]->actor_name,&in_data[28],30);
	if(caps_filter && my_isupper(actors_list[i]->actor_name, -1)) my_tolower(actors_list[i]->actor_name);
	unlock_actors_lists();  //unlock it

}
Example #9
0
void get_string_value (char *buf, size_t maxlen, xmlNode *node) {
	if (node->children == NULL)
		buf[0] = '\0';
	else 
		my_strncp (buf, node->children->content, maxlen);
}