|
@@ -12,8 +12,7 @@
|
|
|
|
|
|
|
|
|
/// failure constants for clif functions
|
|
|
-enum e_searchstore_failure
|
|
|
-{
|
|
|
+enum e_searchstore_failure {
|
|
|
SSI_FAILED_NOTHING_SEARCH_ITEM = 0, // "No matching stores were found."
|
|
|
SSI_FAILED_OVER_MAXCOUNT = 1, // "There are too many results. Please enter more detailed search term."
|
|
|
SSI_FAILED_SEARCH_CNT = 2, // "You cannot search anymore."
|
|
@@ -22,15 +21,13 @@ enum e_searchstore_failure
|
|
|
};
|
|
|
|
|
|
|
|
|
-enum e_searchstore_searchtype
|
|
|
-{
|
|
|
+enum e_searchstore_searchtype {
|
|
|
SEARCHTYPE_VENDING = 0,
|
|
|
SEARCHTYPE_BUYING_STORE = 1,
|
|
|
};
|
|
|
|
|
|
|
|
|
-enum e_searchstore_effecttype
|
|
|
-{
|
|
|
+enum e_searchstore_effecttype {
|
|
|
EFFECTTYPE_NORMAL = 0,
|
|
|
EFFECTTYPE_CASH = 1,
|
|
|
EFFECTTYPE_MAX
|
|
@@ -90,15 +87,12 @@ static int searchstore_getstoreid(struct map_session_data* sd, unsigned char typ
|
|
|
}
|
|
|
|
|
|
|
|
|
-bool searchstore_open(struct map_session_data* sd, unsigned int uses, unsigned short effect)
|
|
|
-{
|
|
|
- if( !battle_config.feature_search_stores || sd->searchstore.open )
|
|
|
- {
|
|
|
+bool searchstore_open(struct map_session_data* sd, unsigned int uses, unsigned short effect) {
|
|
|
+ if( !battle_config.feature_search_stores || sd->searchstore.open ) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if( !uses || effect >= EFFECTTYPE_MAX )
|
|
|
- {// invalid input
|
|
|
+ if( !uses || effect >= EFFECTTYPE_MAX ) {// invalid input
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -116,63 +110,53 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
|
|
{
|
|
|
unsigned int i;
|
|
|
struct map_session_data* pl_sd;
|
|
|
- struct s_mapiterator* iter;
|
|
|
+ struct DBIterator *iter;
|
|
|
struct s_search_store_search s;
|
|
|
searchstore_searchall_t store_searchall;
|
|
|
time_t querytime;
|
|
|
|
|
|
- if( !battle_config.feature_search_stores )
|
|
|
- {
|
|
|
+ if( !battle_config.feature_search_stores ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if( !sd->searchstore.open )
|
|
|
- {
|
|
|
+ if( !sd->searchstore.open ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if( ( store_searchall = searchstore_getsearchallfunc(type) ) == NULL )
|
|
|
- {
|
|
|
+ if( ( store_searchall = searchstore_getsearchallfunc(type) ) == NULL ) {
|
|
|
ShowError("searchstore_query: Unknown search type %u (account_id=%d).\n", (unsigned int)type, sd->bl.id);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
time(&querytime);
|
|
|
|
|
|
- if( sd->searchstore.nextquerytime > querytime )
|
|
|
- {
|
|
|
+ if( sd->searchstore.nextquerytime > querytime ) {
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_LIMIT_SEARCH_TIME);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if( !sd->searchstore.uses )
|
|
|
- {
|
|
|
+ if( !sd->searchstore.uses ) {
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_SEARCH_CNT);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// validate lists
|
|
|
- for( i = 0; i < item_count; i++ )
|
|
|
- {
|
|
|
- if( !itemdb_exists(itemlist[i]) )
|
|
|
- {
|
|
|
+ for( i = 0; i < item_count; i++ ) {
|
|
|
+ if( !itemdb_exists(itemlist[i]) ) {
|
|
|
ShowWarning("searchstore_query: Client resolved item %hu is not known.\n", itemlist[i]);
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- for( i = 0; i < card_count; i++ )
|
|
|
- {
|
|
|
- if( !itemdb_exists(cardlist[i]) )
|
|
|
- {
|
|
|
+ for( i = 0; i < card_count; i++ ) {
|
|
|
+ if( !itemdb_exists(cardlist[i]) ) {
|
|
|
ShowWarning("searchstore_query: Client resolved card %hu is not known.\n", cardlist[i]);
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if( max_price < min_price )
|
|
|
- {
|
|
|
+ if( max_price < min_price ) {
|
|
|
swap(min_price, max_price);
|
|
|
}
|
|
|
|
|
@@ -194,26 +178,23 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
|
|
s.card_count = card_count;
|
|
|
s.min_price = min_price;
|
|
|
s.max_price = max_price;
|
|
|
- iter = mapit_geteachpc();
|
|
|
+ DBMap *vending_db = vending_getdb();
|
|
|
+ iter = db_iterator(vending_db);
|
|
|
|
|
|
- for( pl_sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); pl_sd = (struct map_session_data*)mapit_next(iter) )
|
|
|
- {
|
|
|
- if( sd == pl_sd )
|
|
|
- {// skip own shop, if any
|
|
|
+ for( pl_sd = dbi_first(iter); dbi_exists(iter); pl_sd = dbi_next(iter) ) {
|
|
|
+ if( sd == pl_sd ) {// skip own shop, if any
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if( !store_searchall(pl_sd, &s) )
|
|
|
- {// exceeded result size
|
|
|
+ if( !store_searchall(pl_sd, &s) ) {// exceeded result size
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_OVER_MAXCOUNT);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- mapit_free(iter);
|
|
|
+ dbi_destroy(iter);
|
|
|
|
|
|
- if( sd->searchstore.count )
|
|
|
- {
|
|
|
+ if( sd->searchstore.count ) {
|
|
|
// reclaim unused memory
|
|
|
sd->searchstore.items = (struct s_search_store_info_item*)aRealloc(sd->searchstore.items, sizeof(struct s_search_store_info_item)*sd->searchstore.count);
|
|
|
|
|
@@ -222,9 +203,7 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
|
|
|
|
|
// one page displayed
|
|
|
sd->searchstore.pages++;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
// cleanup
|
|
|
searchstore_clear(sd);
|
|
|
|
|
@@ -238,10 +217,8 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
|
|
|
|
|
|
|
|
/// checks whether or not more results are available for the client
|
|
|
-bool searchstore_querynext(struct map_session_data* sd)
|
|
|
-{
|
|
|
- if( sd->searchstore.count && ( sd->searchstore.count-1 )/SEARCHSTORE_RESULTS_PER_PAGE < sd->searchstore.pages )
|
|
|
- {
|
|
|
+bool searchstore_querynext(struct map_session_data* sd) {
|
|
|
+ if( sd->searchstore.count && ( sd->searchstore.count-1 )/SEARCHSTORE_RESULTS_PER_PAGE < sd->searchstore.pages ) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -249,8 +226,7 @@ bool searchstore_querynext(struct map_session_data* sd)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void searchstore_next(struct map_session_data* sd)
|
|
|
-{
|
|
|
+void searchstore_next(struct map_session_data* sd) {
|
|
|
if( !battle_config.feature_search_stores || !sd->searchstore.open || sd->searchstore.count <= sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE )
|
|
|
{// nothing (more) to display
|
|
|
return;
|
|
@@ -264,12 +240,10 @@ void searchstore_next(struct map_session_data* sd)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void searchstore_clear(struct map_session_data* sd)
|
|
|
-{
|
|
|
+void searchstore_clear(struct map_session_data* sd) {
|
|
|
searchstore_clearremote(sd);
|
|
|
|
|
|
- if( sd->searchstore.items )
|
|
|
- {// release results
|
|
|
+ if( sd->searchstore.items ) {// release results
|
|
|
aFree(sd->searchstore.items);
|
|
|
sd->searchstore.items = NULL;
|
|
|
}
|
|
@@ -279,10 +253,8 @@ void searchstore_clear(struct map_session_data* sd)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void searchstore_close(struct map_session_data* sd)
|
|
|
-{
|
|
|
- if( sd->searchstore.open )
|
|
|
- {
|
|
|
+void searchstore_close(struct map_session_data* sd) {
|
|
|
+ if( sd->searchstore.open ) {
|
|
|
searchstore_clear(sd);
|
|
|
|
|
|
sd->searchstore.uses = 0;
|
|
@@ -291,29 +263,25 @@ void searchstore_close(struct map_session_data* sd)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void searchstore_click(struct map_session_data* sd, int account_id, int store_id, unsigned short nameid)
|
|
|
-{
|
|
|
+void searchstore_click(struct map_session_data* sd, int account_id, int store_id, unsigned short nameid) {
|
|
|
unsigned int i;
|
|
|
struct map_session_data* pl_sd;
|
|
|
searchstore_search_t store_search;
|
|
|
|
|
|
- if( !battle_config.feature_search_stores || !sd->searchstore.open || !sd->searchstore.count )
|
|
|
- {
|
|
|
+ if( !battle_config.feature_search_stores || !sd->searchstore.open || !sd->searchstore.count ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
searchstore_clearremote(sd);
|
|
|
|
|
|
ARR_FIND( 0, sd->searchstore.count, i, sd->searchstore.items[i].store_id == store_id && sd->searchstore.items[i].account_id == account_id && sd->searchstore.items[i].nameid == nameid );
|
|
|
- if( i == sd->searchstore.count )
|
|
|
- {// no such result, crafted
|
|
|
+ if( i == sd->searchstore.count ) {// no such result, crafted
|
|
|
ShowWarning("searchstore_click: Received request with item %hu of account %d, which is not part of current result set (account_id=%d, char_id=%d).\n", nameid, account_id, sd->bl.id, sd->status.char_id);
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if( ( pl_sd = map_id2sd(account_id) ) == NULL )
|
|
|
- {// no longer online
|
|
|
+ if( ( pl_sd = map_id2sd(account_id) ) == NULL ) {// no longer online
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
|
|
|
return;
|
|
|
}
|
|
@@ -326,23 +294,18 @@ void searchstore_click(struct map_session_data* sd, int account_id, int store_id
|
|
|
|
|
|
store_search = searchstore_getsearchfunc(sd->searchstore.type);
|
|
|
|
|
|
- if( !store_search(pl_sd, nameid) )
|
|
|
- {// item no longer being sold/bought
|
|
|
+ if( !store_search(pl_sd, nameid) ) {// item no longer being sold/bought
|
|
|
clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- switch( sd->searchstore.effect )
|
|
|
- {
|
|
|
+ switch( sd->searchstore.effect ) {
|
|
|
case EFFECTTYPE_NORMAL:
|
|
|
// display coords
|
|
|
|
|
|
- if( sd->bl.m != pl_sd->bl.m )
|
|
|
- {// not on same map, wipe previous marker
|
|
|
+ if( sd->bl.m != pl_sd->bl.m ) {// not on same map, wipe previous marker
|
|
|
clif_search_store_info_click_ack(sd, -1, -1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
clif_search_store_info_click_ack(sd, pl_sd->bl.x, pl_sd->bl.y);
|
|
|
}
|
|
|
|
|
@@ -368,15 +331,13 @@ void searchstore_click(struct map_session_data* sd, int account_id, int store_id
|
|
|
|
|
|
|
|
|
/// checks whether or not sd has opened account_id's shop remotely
|
|
|
-bool searchstore_queryremote(struct map_session_data* sd, int account_id)
|
|
|
-{
|
|
|
+bool searchstore_queryremote(struct map_session_data* sd, int account_id) {
|
|
|
return (bool)( sd->searchstore.open && sd->searchstore.count && sd->searchstore.remote_id == account_id );
|
|
|
}
|
|
|
|
|
|
|
|
|
/// removes range-check bypassing for remotely opened stores
|
|
|
-void searchstore_clearremote(struct map_session_data* sd)
|
|
|
-{
|
|
|
+void searchstore_clearremote(struct map_session_data* sd) {
|
|
|
sd->searchstore.remote_id = 0;
|
|
|
}
|
|
|
|
|
@@ -386,8 +347,7 @@ bool searchstore_result(struct map_session_data* sd, int store_id, int account_i
|
|
|
{
|
|
|
struct s_search_store_info_item* ssitem;
|
|
|
|
|
|
- if( sd->searchstore.count >= (unsigned int)battle_config.searchstore_maxresults )
|
|
|
- {// no more
|
|
|
+ if( sd->searchstore.count >= (unsigned int)battle_config.searchstore_maxresults ) {// no more
|
|
|
return false;
|
|
|
}
|
|
|
|