Fixed a compiler warning (#6216)
Fixes #5999 Thanks to @RadianFord, @CairoLee, @jasonch35 and @Daegaladh
This commit is contained in:
parent
5884953115
commit
5a25755386
@ -568,10 +568,26 @@ bool buyingstore_searchall(struct map_session_data* sd, const struct s_search_st
|
||||
;
|
||||
}
|
||||
|
||||
if( !searchstore_result(s->search_sd, sd->buyer_id, sd->status.account_id, sd->message, it->nameid, it->amount, it->price, buyingstore_blankslots, 0, 0) )
|
||||
{// result set full
|
||||
// Check if the result set is full
|
||||
if( s->search_sd->searchstore.items.size() >= (unsigned int)battle_config.searchstore_maxresults ){
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<s_search_store_info_item> ssitem = std::make_shared<s_search_store_info_item>();
|
||||
|
||||
ssitem->store_id = sd->buyer_id;
|
||||
ssitem->account_id = sd->status.account_id;
|
||||
safestrncpy( ssitem->store_name, sd->message, sizeof( ssitem->store_name ) );
|
||||
ssitem->nameid = it->nameid;
|
||||
ssitem->amount = it->amount;
|
||||
ssitem->price = it->price;
|
||||
for( int j = 0; j < MAX_SLOTS; j++ ){
|
||||
ssitem->card[j] = 0;
|
||||
}
|
||||
ssitem->refine = 0;
|
||||
ssitem->enchantgrade = 0;
|
||||
|
||||
s->search_sd->searchstore.items.push_back( ssitem );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -18880,7 +18880,7 @@ void clif_search_store_info_ack( struct map_session_data* sd ){
|
||||
}
|
||||
|
||||
unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
|
||||
unsigned int end = umin( sd->searchstore.count, start + SEARCHSTORE_RESULTS_PER_PAGE );
|
||||
unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
|
||||
int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
|
||||
|
||||
WFIFOHEAD( fd, len );
|
||||
@ -18894,7 +18894,7 @@ void clif_search_store_info_ack( struct map_session_data* sd ){
|
||||
p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
|
||||
|
||||
for( int i = 0; i < end - start; i++ ) {
|
||||
struct s_search_store_info_item* ssitem = &sd->searchstore.items[start + i];
|
||||
std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
|
||||
|
||||
p->items[i].storeId = ssitem->store_id;
|
||||
p->items[i].AID = ssitem->account_id;
|
||||
@ -18906,10 +18906,11 @@ void clif_search_store_info_ack( struct map_session_data* sd ){
|
||||
p->items[i].refine = ssitem->refine;
|
||||
|
||||
// make-up an item for clif_addcards
|
||||
struct item it;
|
||||
struct item it = {};
|
||||
|
||||
memset( &it, 0, sizeof( it ) );
|
||||
memcpy( &it.card, &ssitem->card, sizeof( it.card ) );
|
||||
for( int j = 0; j < MAX_SLOTS; j++ ){
|
||||
it.card[j] = ssitem->card[j];
|
||||
}
|
||||
it.nameid = ssitem->nameid;
|
||||
it.amount = ssitem->amount;
|
||||
|
||||
|
@ -196,9 +196,6 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
||||
// drop previous results
|
||||
searchstore_clear(sd);
|
||||
|
||||
// allocate max. amount of results
|
||||
sd->searchstore.items = (struct s_search_store_info_item*)aMalloc(sizeof(struct s_search_store_info_item)*battle_config.searchstore_maxresults);
|
||||
|
||||
// search
|
||||
s.search_sd = sd;
|
||||
s.itemlist = itemlist;
|
||||
@ -221,10 +218,7 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
||||
|
||||
dbi_destroy(iter);
|
||||
|
||||
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);
|
||||
|
||||
if( !sd->searchstore.items.empty() ) {
|
||||
// present results
|
||||
clif_search_store_info_ack(sd);
|
||||
|
||||
@ -249,7 +243,7 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned
|
||||
*/
|
||||
bool searchstore_querynext(struct map_session_data* sd)
|
||||
{
|
||||
if( sd->searchstore.count && ( sd->searchstore.count-1 )/SEARCHSTORE_RESULTS_PER_PAGE > sd->searchstore.pages )
|
||||
if( !sd->searchstore.items.empty() && ( sd->searchstore.items.size()-1 )/SEARCHSTORE_RESULTS_PER_PAGE > sd->searchstore.pages )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -261,7 +255,7 @@ bool searchstore_querynext(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
|
||||
if( !battle_config.feature_search_stores || !sd->searchstore.open || sd->searchstore.items.size() <= sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE ) // nothing (more) to display
|
||||
return;
|
||||
|
||||
// present results
|
||||
@ -279,12 +273,7 @@ void searchstore_clear(struct map_session_data* sd)
|
||||
{
|
||||
searchstore_clearremote(sd);
|
||||
|
||||
if( sd->searchstore.items ) { // release results
|
||||
aFree(sd->searchstore.items);
|
||||
sd->searchstore.items = NULL;
|
||||
}
|
||||
|
||||
sd->searchstore.count = 0;
|
||||
sd->searchstore.items.clear();
|
||||
sd->searchstore.pages = 0;
|
||||
}
|
||||
|
||||
@ -315,13 +304,13 @@ void searchstore_click(struct map_session_data* sd, uint32 account_id, int store
|
||||
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.items.empty() )
|
||||
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
|
||||
ARR_FIND( 0, sd->searchstore.items.size(), 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.items.size() ) { // no such result, crafted
|
||||
ShowWarning("searchstore_click: Received request with item %u 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;
|
||||
@ -376,7 +365,7 @@ void searchstore_click(struct map_session_data* sd, uint32 account_id, int store
|
||||
*/
|
||||
bool searchstore_queryremote(struct map_session_data* sd, uint32 account_id)
|
||||
{
|
||||
return (bool)( sd->searchstore.open && sd->searchstore.count && sd->searchstore.remote_id == account_id );
|
||||
return (bool)( sd->searchstore.open && !sd->searchstore.items.empty() && sd->searchstore.remote_id == account_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -387,36 +376,3 @@ void searchstore_clearremote(struct map_session_data* sd)
|
||||
{
|
||||
sd->searchstore.remote_id = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives results from a store-specific callback.
|
||||
* @param sd : player requesting
|
||||
* @param store_id : store ID generated by the client
|
||||
* @param account_id : account ID of owner's shop
|
||||
* @param store_name : name of store
|
||||
* @param nameid : item being searched
|
||||
* @param amount : count of item
|
||||
* @param price : zeny price of item
|
||||
* @param card : card in the item
|
||||
* @param refine : refine of the item
|
||||
*/
|
||||
bool searchstore_result(struct map_session_data* sd, int store_id, uint32 account_id, const char* store_name, t_itemid nameid, unsigned short amount, unsigned int price, const t_itemid* card, unsigned char refine, uint8 enchantgrade)
|
||||
{
|
||||
struct s_search_store_info_item* ssitem;
|
||||
|
||||
if( sd->searchstore.count >= (unsigned int)battle_config.searchstore_maxresults ) // no more
|
||||
return false;
|
||||
|
||||
ssitem = &sd->searchstore.items[sd->searchstore.count++];
|
||||
ssitem->store_id = store_id;
|
||||
ssitem->account_id = account_id;
|
||||
safestrncpy(ssitem->store_name, store_name, sizeof(ssitem->store_name));
|
||||
ssitem->nameid = nameid;
|
||||
ssitem->amount = amount;
|
||||
ssitem->price = price;
|
||||
memcpy(ssitem->card, card, sizeof(ssitem->card));
|
||||
ssitem->refine = refine;
|
||||
ssitem->enchantgrade = enchantgrade;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -4,6 +4,9 @@
|
||||
#ifndef SEARCHSTORE_HPP
|
||||
#define SEARCHSTORE_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "../common/cbasetypes.hpp"
|
||||
#include "../common/mmo.hpp"
|
||||
|
||||
@ -36,8 +39,7 @@ struct s_search_store_info_item {
|
||||
};
|
||||
|
||||
struct s_search_store_info {
|
||||
unsigned int count;
|
||||
struct s_search_store_info_item* items;
|
||||
std::vector<std::shared_ptr<s_search_store_info_item>> items;
|
||||
unsigned int pages; // amount of pages already sent to client
|
||||
unsigned int uses;
|
||||
int remote_id;
|
||||
@ -56,6 +58,5 @@ void searchstore_close(struct map_session_data* sd);
|
||||
void searchstore_click(struct map_session_data* sd, uint32 account_id, int store_id, t_itemid nameid);
|
||||
bool searchstore_queryremote(struct map_session_data* sd, uint32 account_id);
|
||||
void searchstore_clearremote(struct map_session_data* sd);
|
||||
bool searchstore_result(struct map_session_data* sd, int store_id, uint32 account_id, const char* store_name, t_itemid nameid, unsigned short amount, unsigned int price, const t_itemid* card, unsigned char refine, uint8 enchantgrade);
|
||||
|
||||
#endif /* SEARCHSTORE_HPP */
|
||||
|
@ -465,9 +465,26 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_
|
||||
}
|
||||
}
|
||||
|
||||
if( !searchstore_result(s->search_sd, sd->vender_id, sd->status.account_id, sd->message, it->nameid, sd->vending[i].amount, sd->vending[i].value, it->card, it->refine, it->enchantgrade ) ) { // result set full
|
||||
// Check if the result set is full
|
||||
if( s->search_sd->searchstore.items.size() >= (unsigned int)battle_config.searchstore_maxresults ){
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<s_search_store_info_item> ssitem = std::make_shared<s_search_store_info_item>();
|
||||
|
||||
ssitem->store_id = sd->vender_id;
|
||||
ssitem->account_id = sd->status.account_id;
|
||||
safestrncpy( ssitem->store_name, sd->message, sizeof( ssitem->store_name ) );
|
||||
ssitem->nameid = it->nameid;
|
||||
ssitem->amount = sd->vending[i].amount;
|
||||
ssitem->price = sd->vending[i].value;
|
||||
for( int j = 0; j < MAX_SLOTS; j++ ){
|
||||
ssitem->card[j] = it->card[j];
|
||||
}
|
||||
ssitem->refine = it->refine;
|
||||
ssitem->enchantgrade = it->enchantgrade;
|
||||
|
||||
s->search_sd->searchstore.items.push_back( ssitem );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user