Skip to content

Commit

Permalink
Randomized Start Point
Browse files Browse the repository at this point in the history
* Fixes #805
  • Loading branch information
aleos89 committed Jan 8, 2016
1 parent 85a4c27 commit a54bb65
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
8 changes: 5 additions & 3 deletions conf/char_athena.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@Atemo

Atemo Jan 8, 2016

Contributor

The format should be with : as delimiter isn't it?

This comment has been minimized.

Copy link
@aleos89

aleos89 Jan 8, 2016

Author Contributor

Yeah it should be. I changed the format and forgot to adjust this!

I have another commit to apply anyways to fix @go.

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)
Expand Down
50 changes: 34 additions & 16 deletions src/char/char.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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!
Expand All @@ -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!
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/char/char.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a54bb65

Please sign in to comment.