Randomized Start Point

* Fixes #805
This commit is contained in:
aleos89 2016-01-08 12:27:10 -05:00
parent 85a4c272ca
commit a54bb653de
3 changed files with 43 additions and 20 deletions

View File

@ -108,9 +108,11 @@ autosave_time: 60
save_log: yes
// Starting point for new characters
// Format: <map_name>,<x>,<y>
start_point: iz_int,97,90
start_point_pre: new_1-1,53,111
// Format: <map_name>,<x>,<y>{:<map_name>,<x>,<y>...}
// Max number of start points is MAX_STARTPOINT in char.h (default 5)
// Location is randomly picked on character creation.
start_point: iz_int,97,90,iz_int01,97,90,iz_int02,97,90,iz_int03,97,90,iz_int04,97,90
start_point_pre: new_1-1,53,111,new_2-1,53,111,new_3-1,53,111,new_4-1,53,111,new_5-1,53,111
// Starting items for new characters
// Max number of items is MAX_STARTITEM in char.c (default 32)

View File

@ -1421,7 +1421,7 @@ int char_make_new_char_sql(struct char_session_data* sd, char* name_, int str, i
char name[NAME_LENGTH];
char esc_name[NAME_LENGTH*2+1];
uint32 char_id;
int flag, k;
int flag, k, start_point_idx = rand() % charserv_config.start_point_count;
safestrncpy(name, name_, NAME_LENGTH);
normalize_name(name,TRIM_CHARS);
@ -1473,7 +1473,7 @@ int char_make_new_char_sql(struct char_session_data* sd, char* name_, int str, i
"'%d', '%d', '%s', '%d', '%d','%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d')",
schema_config.char_db, sd->account_id , slot, esc_name, charserv_config.start_zeny, 48, str, agi, vit, int_, dex, luk,
(40 * (100 + vit)/100) , (40 * (100 + vit)/100 ), (11 * (100 + int_)/100), (11 * (100 + int_)/100), hair_style, hair_color,
mapindex_id2name(charserv_config.start_point.map), charserv_config.start_point.x, charserv_config.start_point.y, mapindex_id2name(charserv_config.start_point.map), charserv_config.start_point.x, charserv_config.start_point.y) )
mapindex_id2name(charserv_config.start_point[start_point_idx].map), charserv_config.start_point[start_point_idx].x, charserv_config.start_point[start_point_idx].y, mapindex_id2name(charserv_config.start_point[start_point_idx].map), charserv_config.start_point[start_point_idx].x, charserv_config.start_point[start_point_idx].y) )
{
Sql_ShowDebug(sql_handle);
return -2; //No, stop the procedure!
@ -1485,7 +1485,7 @@ int char_make_new_char_sql(struct char_session_data* sd, char* name_, int str, i
"'%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d', '%s', '%d', '%d', '%s', '%d', '%d')",
schema_config.char_db, sd->account_id , slot, esc_name, charserv_config.start_zeny, str, agi, vit, int_, dex, luk,
(40 * (100 + vit)/100) , (40 * (100 + vit)/100 ), (11 * (100 + int_)/100), (11 * (100 + int_)/100), hair_style, hair_color,
mapindex_id2name(charserv_config.start_point.map), charserv_config.start_point.x, charserv_config.start_point.y, mapindex_id2name(charserv_config.start_point.map), charserv_config.start_point.x, charserv_config.start_point.y) )
mapindex_id2name(charserv_config.start_point[start_point_idx].map), charserv_config.start_point[start_point_idx].x, charserv_config.start_point[start_point_idx].y, mapindex_id2name(charserv_config.start_point[start_point_idx].map), charserv_config.start_point[start_point_idx].x, charserv_config.start_point[start_point_idx].y) )
{
Sql_ShowDebug(sql_handle);
return -2; //No, stop the procedure!
@ -2635,9 +2635,10 @@ void char_set_defaults(){
charserv_config.char_check_db =1;
//see const.h to change those default
charserv_config.start_point.map = mapindex_name2id(MAP_DEFAULT_NAME);
charserv_config.start_point.x = MAP_DEFAULT_X;
charserv_config.start_point.y = MAP_DEFAULT_Y;
charserv_config.start_point[0].map = mapindex_name2id(MAP_DEFAULT_NAME);
charserv_config.start_point[0].x = MAP_DEFAULT_X;
charserv_config.start_point[0].y = MAP_DEFAULT_Y;
charserv_config.start_point_count = 0;
charserv_config.console = 0;
charserv_config.max_connect_user = -1;
@ -2747,17 +2748,34 @@ bool char_config_read(const char* cfgName, bool normal){
#else
} else if (strcmpi(w1, "start_point_pre") == 0) {
#endif
char map[MAP_NAME_LENGTH_EXT];
short x, y;
if (sscanf(w2, "%15[^,],%6hd,%6hd", map, &x, &y) < 3){
ShowWarning( "Specified start_point has an invalid format.\n" );
continue;
int i = 0, fields_length = 3 + 1;
char *lineitem, **fields;
fields = (char**)aMalloc(fields_length * sizeof(char*));
lineitem = strtok(w2, ":");
while (lineitem != NULL) {
int n = sv_split(lineitem, strlen(lineitem), 0, ',', fields, fields_length, SV_NOESCAPE_NOTERMINATE);
if (n + 1 < fields_length) {
ShowDebug("start_point: not enough arguments for %s! Skipping...\n", lineitem);
lineitem = strtok(NULL, ":"); //next itemline
continue;
}
if (i > MAX_STARTPOINT) {
ShowDebug("start_point: too many start points, only %d are allowed! Ignoring parameter %s...\n", MAX_STARTPOINT, lineitem);
} else {
charserv_config.start_point[i].map = mapindex_name2id(fields[1]);
if (!charserv_config.start_point[i].map)
ShowError("Specified start_point %s not found in map-index cache.\n", charserv_config.start_point[i].map);
charserv_config.start_point[i].x = max(0, atoi(fields[2]));
charserv_config.start_point[i].y = max(0, atoi(fields[3]));
charserv_config.start_point_count++;
}
lineitem = strtok(NULL, ":"); //next itemline
i++;
}
charserv_config.start_point.map = mapindex_name2id(map);
if (!charserv_config.start_point.map)
ShowError("Specified start_point %s not found in map-index cache.\n", map);
charserv_config.start_point.x = x;
charserv_config.start_point.y = y;
aFree(fields);
} else if (strcmpi(w1, "start_zeny") == 0) {
charserv_config.start_zeny = atoi(w2);
if (charserv_config.start_zeny < 0)

View File

@ -15,6 +15,8 @@
extern int login_fd; //login file descriptor
extern int char_fd; //char file descriptor
#define MAX_STARTPOINT 5
enum E_CHARSERVER_ST {
CHARSERVER_ST_RUNNING = CORE_ST_LAST,
CHARSERVER_ST_STARTING,
@ -142,7 +144,8 @@ struct CharServ_Config {
int log_inter; // loggin inter or not [devil]
int char_check_db; ///cheking sql-table at begining ?
struct point start_point; // Initial position the player will spawn on server
struct point start_point[MAX_STARTPOINT]; // Initial position the player will spawn on server
short start_point_count;
int console;
int max_connect_user;
int gm_allow_group;