Upd Documentation

Update some src documentation for doxygen
Fix typo in [hash:9cca188] in clif, making it uncompilable
This commit is contained in:
lighta 2013-12-21 04:41:11 -05:00
parent 9cca188908
commit 00e63be81c
8 changed files with 663 additions and 516 deletions

View File

@ -1931,6 +1931,7 @@ void clif_scriptclear(struct map_session_data *sd, int npcid)
struct s_packet_db* info; struct s_packet_db* info;
int16 len; int16 len;
int cmd = 0; int cmd = 0;
int fd;
nullpo_retv(sd); nullpo_retv(sd);
@ -1938,6 +1939,7 @@ void clif_scriptclear(struct map_session_data *sd, int npcid)
if(!cmd) cmd = 0x8d6; //default if(!cmd) cmd = 0x8d6; //default
info = &packet_db[sd->packet_ver][cmd]; info = &packet_db[sd->packet_ver][cmd];
len = info->len; len = info->len;
fd = sd->fd;
WFIFOHEAD(fd, len); WFIFOHEAD(fd, len);
WFIFOW(fd,0)=0x8d6; WFIFOW(fd,0)=0x8d6;

View File

@ -1412,6 +1412,8 @@ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, in
} }
// Always run NPC scripts for players last // Always run NPC scripts for players last
//FIXME those ain't always run if a player die if he was resurect meanwhile
//cf SC_REBIRTH, SC_LIGHT_OF_REGENE, SC_KAIZEL, pc_dead...
if(target->type == BL_PC) { if(target->type == BL_PC) {
TBL_PC *sd = BL_CAST(BL_PC,target); TBL_PC *sd = BL_CAST(BL_PC,target);
if( sd->bg_id ) { if( sd->bg_id ) {
@ -1431,7 +1433,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, in
* @param bl: Object to heal [PC|MOB|HOM|MER|ELEM] * @param bl: Object to heal [PC|MOB|HOM|MER|ELEM]
* @param hhp: How much HP to heal * @param hhp: How much HP to heal
* @param hsp: How much SP to heal * @param hsp: How much SP to heal
* @param flag: Whether it's Forced(&1) or gives HP/SP(&2) heal effect * @param flag: Whether it's Forced(&1) or gives HP/SP(&2) heal effect \n
* Forced healing overrides heal impedement statuses (Berserk) * Forced healing overrides heal impedement statuses (Berserk)
* @return hp+sp * @return hp+sp
**/ **/
@ -1512,7 +1514,8 @@ int status_heal(struct block_list *bl,int64 hhp,int64 hsp, int flag)
* @param target: Object to modify HP/SP * @param target: Object to modify HP/SP
* @param hp_rate: Percentage of HP to modify * @param hp_rate: Percentage of HP to modify
* @param sp_rate: Percentage of SP to modify * @param sp_rate: Percentage of SP to modify
* @param flag: 0: Heal target * @param flag: \n
* 0: Heal target \n
* 2: Target must not die from subtraction * 2: Target must not die from subtraction
* @return hp+sp through status_heal() * @return hp+sp through status_heal()
**/ **/

View File

@ -24,11 +24,15 @@
#include <string.h> #include <string.h>
static DBMap* guild_storage_db; // int guild_id -> struct guild_storage* static DBMap* guild_storage_db; ///Databases of guild_storage : int guild_id -> struct guild_storage*
/*========================================== /**
* Sort items in the warehouse * Storage item comparator (for qsort)
*------------------------------------------*/ * sort by itemid and amount
* @param _i1 : item a
* @param _i2 : item b
* @return i1<=>i2
*/
static int storage_comp_item(const void *_i1, const void *_i2) static int storage_comp_item(const void *_i1, const void *_i2)
{ {
struct item *i1 = (struct item *)_i1; struct item *i1 = (struct item *)_i1;
@ -43,7 +47,12 @@ static int storage_comp_item(const void *_i1, const void *_i2)
return i1->nameid - i2->nameid; return i1->nameid - i2->nameid;
} }
//Sort item by storage_comp_item (nameid) /**
* Sort item by storage_comp_item (nameid)
* used when we open up our storage or guild_storage
* @param items : list of items to sort
* @param size : number of item in list
*/
static void storage_sortitem(struct item* items, unsigned int size) static void storage_sortitem(struct item* items, unsigned int size)
{ {
nullpo_retv(items); nullpo_retv(items);
@ -54,22 +63,32 @@ static void storage_sortitem(struct item* items, unsigned int size)
} }
} }
/*========================================== /**
* Init/Terminate * Initiate storage module
*------------------------------------------*/ * Called from map.c::do_init()
int do_init_storage(void) // Called from map.c::do_init() * @return 1
*/
int do_init_storage(void) //
{ {
guild_storage_db=idb_alloc(DB_OPT_RELEASE_DATA); guild_storage_db=idb_alloc(DB_OPT_RELEASE_DATA);
return 1; return 1;
} }
void do_final_storage(void) // by [MC Cameri]
/**
* Destroy storage module
* @author : [MC Cameri]
* Called from map.c::do_final()
*/
void do_final_storage(void)
{ {
guild_storage_db->destroy(guild_storage_db,NULL); guild_storage_db->destroy(guild_storage_db,NULL);
} }
/** /**
* Parses storage and saves 'dirty' ones upon reconnect. [Skotlex] * Parses storage and saves 'dirty' ones upon reconnect.
* @author [Skotlex]
* @see DBApply * @see DBApply
* @return 0
*/ */
static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap) static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap)
{ {
@ -80,17 +99,20 @@ static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap)
return 0; return 0;
} }
//Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex] /**
* Function to be invoked upon server reconnection to char. To save all 'dirty' storages
* @author [Skotlex]
*/
void do_reconnect_storage(void) void do_reconnect_storage(void)
{ {
guild_storage_db->foreach(guild_storage_db, storage_reconnect_sub); guild_storage_db->foreach(guild_storage_db, storage_reconnect_sub);
} }
/*========================================== /**
* Opens a storage. Returns: * Player attempt tp open his storage.
* 0 - success * @param sd : player
* 1 - fail * @return 0:success, 1:fail
*------------------------------------------*/ */
int storage_storageopen(struct map_session_data *sd) int storage_storageopen(struct map_session_data *sd)
{ {
nullpo_ret(sd); nullpo_ret(sd);
@ -111,8 +133,11 @@ int storage_storageopen(struct map_session_data *sd)
return 0; return 0;
} }
/* helper function /**
* checking if 2 item structure are identique * check if 2 item a and b have same values
* @param a : item 1
* @param b : item 2
* @return 1:same, 0:are different
*/ */
int compare_item(struct item *a, struct item *b) int compare_item(struct item *a, struct item *b)
{ {
@ -130,9 +155,13 @@ int compare_item(struct item *a, struct item *b)
return 0; return 0;
} }
/*========================================== /**
* Internal add-item function. * Make a player add an item to his storage
*------------------------------------------*/ * @param sd : player
* @param item_data : item to add
* @param amount : quantity of items
* @return 0:success, 1:failed
*/
static int storage_additem(struct map_session_data* sd, struct item* item_data, int amount) static int storage_additem(struct map_session_data* sd, struct item* item_data, int amount)
{ {
struct storage_data* stor = &sd->status.storage; struct storage_data* stor = &sd->status.storage;
@ -190,9 +219,13 @@ static int storage_additem(struct map_session_data* sd, struct item* item_data,
return 0; return 0;
} }
/*========================================== /**
* Internal del-item function * Make a player delete an item from his storage
*------------------------------------------*/ * @param sd : player
* @param n : idx on storage to remove the item from
* @param amount :number of item to remove
* @return 0:sucess, 1:fail
*/
int storage_delitem(struct map_session_data* sd, int n, int amount) int storage_delitem(struct map_session_data* sd, int n, int amount)
{ {
if( sd->status.storage.items[n].nameid == 0 || sd->status.storage.items[n].amount < amount ) if( sd->status.storage.items[n].nameid == 0 || sd->status.storage.items[n].amount < amount )
@ -209,13 +242,13 @@ int storage_delitem(struct map_session_data* sd, int n, int amount)
return 0; return 0;
} }
/*========================================== /**
* Add an item to the storage from the inventory. * Add an item to the storage from the inventory.
* @index : inventory idx * @param sd : player
* return * @param index : inventory index to take the item from
* 0 : fail * @param amount : number of item to take
* 1 : success * @return 0:fail, 1:success
*------------------------------------------*/ */
int storage_storageadd(struct map_session_data* sd, int index, int amount) int storage_storageadd(struct map_session_data* sd, int index, int amount)
{ {
nullpo_ret(sd); nullpo_ret(sd);
@ -242,13 +275,13 @@ int storage_storageadd(struct map_session_data* sd, int index, int amount)
return 1; return 1;
} }
/*========================================== /**
* Retrieve an item from the storage into inventory * Retrieve an item from the storage into inventory
* @index : storage idx * @param sd : player
* return * @param index : storage index to take the item from
* 0 : fail * @param amount : number of item to take
* 1 : success * @return 0:fail, 1:success
*------------------------------------------*/ */
int storage_storageget(struct map_session_data* sd, int index, int amount) int storage_storageget(struct map_session_data* sd, int index, int amount)
{ {
int flag; int flag;
@ -270,13 +303,13 @@ int storage_storageget(struct map_session_data* sd, int index, int amount)
return 1; return 1;
} }
/*========================================== /**
* Move an item from cart to storage. * Move an item from cart to storage.
* @index : cart inventory index * @param sd : player
* return * @param index : cart index to take the item from
* 0 : fail * @param amount : number of item to take
* 1 : success * @return 0:fail, 1:success
*------------------------------------------*/ */
int storage_storageaddfromcart(struct map_session_data* sd, int index, int amount) int storage_storageaddfromcart(struct map_session_data* sd, int index, int amount)
{ {
nullpo_ret(sd); nullpo_ret(sd);
@ -299,13 +332,13 @@ int storage_storageaddfromcart(struct map_session_data* sd, int index, int amoun
return 1; return 1;
} }
/*========================================== /**
* Get from Storage to the Cart inventory * Get from Storage to the Cart inventory
* @index : storage index * @param sd : player
* return * @param index : storage index to take the item from
* 0 : fail * @param amount : number of item to take
* 1 : success * @return 0:fail, 1:success
*------------------------------------------*/ */
int storage_storagegettocart(struct map_session_data* sd, int index, int amount) int storage_storagegettocart(struct map_session_data* sd, int index, int amount)
{ {
short flag; short flag;
@ -331,9 +364,11 @@ int storage_storagegettocart(struct map_session_data* sd, int index, int amount)
} }
/*========================================== /**
* Modified By Valaris to save upon closing [massdriller] * Make player close his storage
*------------------------------------------*/ * @author : [massdriller] / modified by [Valaris]
* @param sd : player
*/
void storage_storageclose(struct map_session_data* sd) void storage_storageclose(struct map_session_data* sd)
{ {
nullpo_retv(sd); nullpo_retv(sd);
@ -346,9 +381,14 @@ void storage_storageclose(struct map_session_data* sd)
sd->state.storage_flag = 0; sd->state.storage_flag = 0;
} }
/*========================================== /**
* When quitting the game. * Force closing the storage for player without displaying result
*------------------------------------------*/ * (exemple when quitting the game)
* @param sd : player to close storage
* @param flag : \n
* 1: Character is quitting \n
* 2(x): Character is changing map-servers
*/
void storage_storage_quit(struct map_session_data* sd, int flag) void storage_storage_quit(struct map_session_data* sd, int flag)
{ {
nullpo_retv(sd); nullpo_retv(sd);
@ -360,7 +400,11 @@ void storage_storage_quit(struct map_session_data* sd, int flag)
} }
/** /**
* Create a guild_storage stucture and add it into the db
* @see DBCreateData * @see DBCreateData
* @param key
* @param args
* @return
*/ */
static DBData create_guildstorage(DBKey key, va_list args) static DBData create_guildstorage(DBKey key, va_list args)
{ {
@ -370,6 +414,12 @@ static DBData create_guildstorage(DBKey key, va_list args)
return db_ptr2data(gs); return db_ptr2data(gs);
} }
/**
* Retrieve the guild_storage of a guild
* will create a new storage if none found for the guild
* @param guild_id : id of the guild
* @return guild_storage
*/
struct guild_storage *guild2storage(int guild_id) struct guild_storage *guild2storage(int guild_id)
{ {
struct guild_storage *gs = NULL; struct guild_storage *gs = NULL;
@ -378,25 +428,33 @@ struct guild_storage *guild2storage(int guild_id)
return gs; return gs;
} }
//For just locating a storage without creating one. [Skotlex] /**
* See if the guild_storage exist in db and fetch it if it,s the case
* @author : [Skotlex]
* @param guild_id : guild_id to search the storage
* @return guild_storage or NULL
*/
struct guild_storage *guild2storage2(int guild_id) struct guild_storage *guild2storage2(int guild_id)
{ {
return (struct guild_storage*)idb_get(guild_storage_db,guild_id); return (struct guild_storage*)idb_get(guild_storage_db,guild_id);
} }
/**
* Delete a guild_storage and remove it from db
* @param guild_id : guild to remove the storage from
* @return 0
*/
int guild_storage_delete(int guild_id) int guild_storage_delete(int guild_id)
{ {
idb_remove(guild_storage_db,guild_id); idb_remove(guild_storage_db,guild_id);
return 0; return 0;
} }
/*========================================== /**
* Attempt to open guild storage for sd * Attempt to open guild storage for player
* return * @param sd : player
* 0 : success (open or req to create a new one) * @return * 0 : success, 1 : fail, 2 : no guild found
* 1 : fail */
* 2 : no guild for sd
*------------------------------------------*/
int storage_guild_storageopen(struct map_session_data* sd) int storage_guild_storageopen(struct map_session_data* sd)
{ {
struct guild_storage *gstor; struct guild_storage *gstor;
@ -432,12 +490,14 @@ int storage_guild_storageopen(struct map_session_data* sd)
return 0; return 0;
} }
/*========================================== /**
* Attempt to add an item in guild storage, then refresh it * Attempt to add an item in guild storage, then refresh it
* return * @param sd : player attempting to open the guild_storage
* 0 : success * @param stor : guild_storage
* 1 : fail * @param item_data : item to add
*------------------------------------------*/ * @param amount : number of item to add
* @return 0 : success, 1 : fail
*/
int guild_storage_additem(struct map_session_data* sd, struct guild_storage* stor, struct item* item_data, int amount) int guild_storage_additem(struct map_session_data* sd, struct guild_storage* stor, struct item* item_data, int amount)
{ {
struct item_data *data; struct item_data *data;
@ -495,12 +555,14 @@ int guild_storage_additem(struct map_session_data* sd, struct guild_storage* sto
return 0; return 0;
} }
/*========================================== /**
* Attempt to delete an item in guild storage, then refresh it * Attempt to delete an item in guild storage, then refresh it
* return * @param sd : player
* 0 : success * @param stor : guild_storage
* 1 : fail * @param n : index of item in guild storage
*------------------------------------------*/ * @param amount : number of item to delete
* @return 0 : success, 1 : fail
*/
int guild_storage_delitem(struct map_session_data* sd, struct guild_storage* stor, int n, int amount) int guild_storage_delitem(struct map_session_data* sd, struct guild_storage* stor, int n, int amount)
{ {
nullpo_retr(1, sd); nullpo_retr(1, sd);
@ -520,13 +582,12 @@ int guild_storage_delitem(struct map_session_data* sd, struct guild_storage* sto
return 0; return 0;
} }
/*========================================== /**
* Attempt to add an item in guild storage from inventory, then refresh it * Attempt to add an item in guild storage from inventory, then refresh it
* @index : inventory idx * @param sd : player
* return * @param amount : number of item to delete
* 0 : fail * @return 1:success, 0:fail
* 1 : succes */
*------------------------------------------*/
int storage_guild_storageadd(struct map_session_data* sd, int index, int amount) int storage_guild_storageadd(struct map_session_data* sd, int index, int amount)
{ {
struct guild_storage *stor; struct guild_storage *stor;
@ -561,13 +622,13 @@ int storage_guild_storageadd(struct map_session_data* sd, int index, int amount)
return 1; return 1;
} }
/*========================================== /**
* Attempt to retrieve an item from guild storage to inventory, then refresh it * Attempt to retrieve an item from guild storage to inventory, then refresh it
* @index : storage idx * @param sd : player
* return * @param index : index of item in storage
* 0 : fail * @param amount : number of item to get
* 1 : succes * @return 1:success, 0:fail
*------------------------------------------*/ */
int storage_guild_storageget(struct map_session_data* sd, int index, int amount) int storage_guild_storageget(struct map_session_data* sd, int index, int amount)
{ {
struct guild_storage *stor; struct guild_storage *stor;
@ -595,20 +656,22 @@ int storage_guild_storageget(struct map_session_data* sd, int index, int amount)
if((flag = pc_additem(sd,&stor->items[index],amount,LOG_TYPE_GSTORAGE)) == 0) if((flag = pc_additem(sd,&stor->items[index],amount,LOG_TYPE_GSTORAGE)) == 0)
guild_storage_delitem(sd,stor,index,amount); guild_storage_delitem(sd,stor,index,amount);
else //inform fail else {//inform fail
clif_additem(sd,0,0,flag); clif_additem(sd,0,0,flag);
return 0;
}
// log_fromstorage(sd, index, 1); // log_fromstorage(sd, index, 1);
return 0; return 1;
} }
/*========================================== /**
* Attempt to add an item in guild storage from cart, then refresh it * Attempt to add an item in guild storage from cart, then refresh it
* @index : cart inventory idx * @param sd : player
* return * @param index : index of item in cart
* 0 : fail * @param amount : number of item to transfer
* 1 : succes * @return 1:fail, 0:success
*------------------------------------------*/ */
int storage_guild_storageaddfromcart(struct map_session_data* sd, int index, int amount) int storage_guild_storageaddfromcart(struct map_session_data* sd, int index, int amount)
{ {
struct guild_storage *stor; struct guild_storage *stor;
@ -634,13 +697,13 @@ int storage_guild_storageaddfromcart(struct map_session_data* sd, int index, int
return 1; return 1;
} }
/*========================================== /**
* Attempt to retrieve an item from guild storage to cart, then refresh it * Attempt to retrieve an item from guild storage to cart, then refresh it
* @index : storage idx * @param sd : player
* return * @param index : index of item in storage
* 0 : fail * @param amount : number of item to transfert
* 1 : succes * @return 1:fail, 0:success
*------------------------------------------*/ */
int storage_guild_storagegettocart(struct map_session_data* sd, int index, int amount) int storage_guild_storagegettocart(struct map_session_data* sd, int index, int amount)
{ {
short flag; short flag;
@ -666,17 +729,19 @@ int storage_guild_storagegettocart(struct map_session_data* sd, int index, int a
else { else {
clif_dropitem(sd,index,0); clif_dropitem(sd,index,0);
clif_cart_additem_ack(sd,(flag==1)?ADDITEM_TO_CART_FAIL_WEIGHT:ADDITEM_TO_CART_FAIL_COUNT); clif_cart_additem_ack(sd,(flag==1)?ADDITEM_TO_CART_FAIL_WEIGHT:ADDITEM_TO_CART_FAIL_COUNT);
return 0;
} }
return 1; return 1;
} }
/*========================================== /**
* Request to save guild storage * Request to save guild storage
* return * @param account_id : account requesting the save
* 0 : fail (no storage) * @param guild_id : guild to take the guild_storage
* 1 : succes * @param flag : ?
*------------------------------------------*/ * @return 0 : fail (no storage), 1 : success (requested)
*/
int storage_guild_storagesave(int account_id, int guild_id, int flag) int storage_guild_storagesave(int account_id, int guild_id, int flag)
{ {
struct guild_storage *stor = guild2storage2(guild_id); struct guild_storage *stor = guild2storage2(guild_id);
@ -692,12 +757,11 @@ int storage_guild_storagesave(int account_id, int guild_id, int flag)
return 0; return 0;
} }
/*========================================== /**
* ACK save of guild storage * ACK save of guild storage
* return * @param guild_id : guild to use the storage
* 0 : fail (no storage) * @return 0 : fail (no storage), 1 : succes
* 1 : succes */
*------------------------------------------*/
int storage_guild_storagesaved(int guild_id) int storage_guild_storagesaved(int guild_id)
{ {
struct guild_storage *stor; struct guild_storage *stor;
@ -712,7 +776,11 @@ int storage_guild_storagesaved(int guild_id)
return 0; return 0;
} }
//Close storage for sd and save it /**
* Close storage for player then save it
* @param sd : player
* @return 0
*/
int storage_guild_storageclose(struct map_session_data* sd) int storage_guild_storageclose(struct map_session_data* sd)
{ {
struct guild_storage *stor; struct guild_storage *stor;
@ -734,6 +802,12 @@ int storage_guild_storageclose(struct map_session_data* sd)
return 0; return 0;
} }
/**
* Close storage for player then save it
* @param sd
* @param flag
* @return
*/
int storage_guild_storage_quit(struct map_session_data* sd, int flag) int storage_guild_storage_quit(struct map_session_data* sd, int flag)
{ {
struct guild_storage *stor; struct guild_storage *stor;

View File

@ -20,13 +20,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define TRADE_DISTANCE 2 ///Max distance from traders to enable a trade to take place.
//Max distance from traders to enable a trade to take place. /**
#define TRADE_DISTANCE 2 * Player initiates a trade request.
* @param sd : player requesting the trade
/*========================================== * @param target_sd : player requested
* Initiates a trade request. */
*------------------------------------------*/
void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd) void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd)
{ {
nullpo_retv(sd); nullpo_retv(sd);
@ -88,17 +88,19 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta
clif_traderequest(target_sd, sd->status.name); clif_traderequest(target_sd, sd->status.name);
} }
/*==========================================
/**
* Reply to a trade-request. * Reply to a trade-request.
* Type values: * @param sd : player receiving the trade request answer
* 0: Char is too far * @param type : answer code \n
* 1: Character does not exist * 0: Char is too far \n
* 2: Trade failed * 1: Character does not exist \n
* 3: Accept * 2: Trade failed \n
* 4: Cancel * 3: Accept \n
* Weird enough, the client should only send 3/4 * 4: Cancel \n
* Weird enough, the client should only send 3/4 \n
* and the server is the one that can reply 0~2 * and the server is the one that can reply 0~2
*------------------------------------------*/ */
void trade_tradeack(struct map_session_data *sd, int type) void trade_tradeack(struct map_session_data *sd, int type)
{ {
struct map_session_data *tsd; struct map_session_data *tsd;
@ -165,11 +167,14 @@ void trade_tradeack(struct map_session_data *sd, int type)
clif_tradestart(sd, type); clif_tradestart(sd, type);
} }
/*========================================== /**
* Check here hacker for duplicate item in trade * Check here hacker for duplicate item in trade
* normal client refuse to have 2 same types of item (except equipment) in same trade window * normal client refuse to have 2 same types of item (except equipment) in same trade window
* normal client authorise only no equiped item and only from inventory * normal client authorise only no equiped item and only from inventory
*------------------------------------------*/ * This function could end player connection if too much hack is detected
* @param sd : player to check
* @return -1:zeny hack, 0:all fine, 1:item hack
*/
int impossible_trade_check(struct map_session_data *sd) int impossible_trade_check(struct map_session_data *sd)
{ {
struct item inventory[MAX_INVENTORY]; struct item inventory[MAX_INVENTORY];
@ -229,9 +234,12 @@ int impossible_trade_check(struct map_session_data *sd)
return 0; return 0;
} }
/*========================================== /**
* Checks if trade is possible (against zeny limits, inventory limits, etc) * Checks if trade is possible (against zeny limits, inventory limits, etc)
*------------------------------------------*/ * @param sd : player 1 trading
* @param tsd : player 2 trading
* @return 0:error, 1:success
*/
int trade_check(struct map_session_data *sd, struct map_session_data *tsd) int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
{ {
struct item inventory[MAX_INVENTORY]; struct item inventory[MAX_INVENTORY];
@ -316,9 +324,12 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
return 1; return 1;
} }
/*========================================== /**
* Adds an item/qty to the trade window * Adds an item/qty to the trade window
*------------------------------------------*/ * @param sd : Player requesting to add stuff to the trade
* @param index : index of item in inventory
* @param amount : amount of item to add from index
*/
void trade_tradeadditem(struct map_session_data *sd, short index, short amount) void trade_tradeadditem(struct map_session_data *sd, short index, short amount)
{ {
struct map_session_data *target_sd; struct map_session_data *target_sd;
@ -409,9 +420,13 @@ void trade_tradeadditem(struct map_session_data *sd, short index, short amount)
clif_tradeadditem(sd, target_sd, index+2, amount); clif_tradeadditem(sd, target_sd, index+2, amount);
} }
/*========================================== /**
* Adds the specified amount of zeny to the trade window * Adds the specified amount of zeny to the trade window
*------------------------------------------*/ * This function will check if the player have enough money to do so
* And if the target player have enough space for that money
* @param sd : Player who's adding zeny
* @param amount : zeny amount
*/
void trade_tradeaddzeny(struct map_session_data* sd, int amount) void trade_tradeaddzeny(struct map_session_data* sd, int amount)
{ {
struct map_session_data* target_sd; struct map_session_data* target_sd;
@ -436,9 +451,10 @@ void trade_tradeaddzeny(struct map_session_data* sd, int amount)
clif_tradeadditem(sd, target_sd, 0, amount); clif_tradeadditem(sd, target_sd, 0, amount);
} }
/*========================================== /**
* 'Ok' button on the trade window is pressed. * 'Ok' button on the trade window is pressed.
*------------------------------------------*/ * @param sd : Player that pressed the button
*/
void trade_tradeok(struct map_session_data *sd) void trade_tradeok(struct map_session_data *sd)
{ {
struct map_session_data *target_sd; struct map_session_data *target_sd;
@ -456,9 +472,10 @@ void trade_tradeok(struct map_session_data *sd)
clif_tradedeal_lock(target_sd, 1); clif_tradedeal_lock(target_sd, 1);
} }
/*========================================== /**
* 'Cancel' is pressed. (or trade was force-cancelled by the code) * 'Cancel' is pressed. (or trade was force-cancelled by the code)
*------------------------------------------*/ * @param sd : Player that pressed the button
*/
void trade_tradecancel(struct map_session_data *sd) void trade_tradecancel(struct map_session_data *sd)
{ {
struct map_session_data *target_sd; struct map_session_data *target_sd;
@ -515,9 +532,11 @@ void trade_tradecancel(struct map_session_data *sd)
clif_tradecancelled(target_sd); clif_tradecancelled(target_sd);
} }
/*========================================== /**
* Execute the trade
* lock sd and tsd trade data, execute the trade, clear, then save players * lock sd and tsd trade data, execute the trade, clear, then save players
*------------------------------------------*/ * @param sd : Player that has click on trade button
*/
void trade_tradecommit(struct map_session_data *sd) void trade_tradecommit(struct map_session_data *sd)
{ {
struct map_session_data *tsd; struct map_session_data *tsd;

View File

@ -42,30 +42,43 @@
#include <string.h> #include <string.h>
const short dirx[8]={0,-1,-1,-1,0,1,1,1}; // Directions values
const short diry[8]={1,1,0,-1,-1,-1,0,1}; // 1 0 7
// 2 . 6
struct unit_data* unit_bl2ud(struct block_list *bl) // 3 4 5
{ const short dirx[8]={0,-1,-1,-1,0,1,1,1}; ///lookup to know where will move to x according dir
if( bl == NULL) return NULL; const short diry[8]={1,1,0,-1,-1,-1,0,1}; ///lookup to know where will move to y according dir
if( bl->type == BL_PC) return &((struct map_session_data*)bl)->ud;
if( bl->type == BL_MOB) return &((struct mob_data*)bl)->ud;
if( bl->type == BL_PET) return &((struct pet_data*)bl)->ud;
if( bl->type == BL_NPC) return &((struct npc_data*)bl)->ud;
if( bl->type == BL_HOM) return &((struct homun_data*)bl)->ud;
if( bl->type == BL_MER) return &((struct mercenary_data*)bl)->ud;
if( bl->type == BL_ELEM) return &((struct elemental_data*)bl)->ud;
return NULL;
}
//early declaration
static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data); static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data);
static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data); static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data);
/** /**
* Tells a unit to walk to a specific coordinate * Get the unit_data related to the bl
* @param bl: Unit to walk [ALL] * @param bl : Object to get the unit_data from \n
* @return 1: Success 0: Fail * valid type are : BL_PC|BL_MOB|BL_PET|BL_NPC|BL_HOM|BL_MER|BL_ELEM
**/ * @return unit_data of bl or NULL
*/
struct unit_data* unit_bl2ud(struct block_list *bl)
{
if( bl == NULL) return NULL;
switch(bl->type){
case BL_PC: return &((struct map_session_data*)bl)->ud;
case BL_MOB: return &((struct mob_data*)bl)->ud;
case BL_PET: return &((struct pet_data*)bl)->ud;
case BL_NPC: return &((struct npc_data*)bl)->ud;
case BL_HOM: return &((struct homun_data*)bl)->ud;
case BL_MER: return &((struct mercenary_data*)bl)->ud;
case BL_ELEM: return &((struct elemental_data*)bl)->ud;
default : return NULL;
}
}
/**
* Tells a unit to walk to a specific coordinate
* @param bl: Unit to walk [ALL]
* @return 1: Success 0: Fail
*/
int unit_walktoxy_sub(struct block_list *bl) int unit_walktoxy_sub(struct block_list *bl)
{ {
int i; int i;
@ -120,10 +133,10 @@ int unit_walktoxy_sub(struct block_list *bl)
/** /**
* Retrieve the direct master of a bl if one exists. * Retrieve the direct master of a bl if one exists.
* @param bl: char to get his master [HOM|ELEM|PET|MER] * @param bl: char to get his master [HOM|ELEM|PET|MER]
* @return map_session_data of master or NULL * @return map_session_data of master or NULL
**/ */
TBL_PC* unit_get_master(struct block_list *bl) TBL_PC* unit_get_master(struct block_list *bl)
{ {
if(bl) if(bl)
@ -137,10 +150,10 @@ TBL_PC* unit_get_master(struct block_list *bl)
} }
/** /**
* Retrieve a unit's master's teleport timer * Retrieve a unit's master's teleport timer
* @param bl: char to get his master's teleport timer [HOM|ELEM|PET|MER] * @param bl: char to get his master's teleport timer [HOM|ELEM|PET|MER]
* @return timer or NULL * @return timer or NULL
**/ */
int* unit_get_masterteleport_timer(struct block_list *bl) int* unit_get_masterteleport_timer(struct block_list *bl)
{ {
if(bl) if(bl)
@ -154,14 +167,14 @@ int* unit_get_masterteleport_timer(struct block_list *bl)
} }
/** /**
* Warps a unit to its master master has gone out of site (3 second default) \n * Warps a unit to its master master has gone out of site (3 second default) \n
* Can be any object with a master [MOB|PET|HOM|MER|ELEM] * Can be any object with a master [MOB|PET|HOM|MER|ELEM]
* @param tid: Timer * @param tid: Timer
* @param tick: tick (unused) * @param tick: tick (unused)
* @param id: Unit to warp * @param id: Unit to warp
* @param data: Data transferred from timer call * @param data: Data transferred from timer call
* @return 0 * @return 0
**/ */
int unit_teleport_timer(int tid, unsigned int tick, int id, intptr_t data) int unit_teleport_timer(int tid, unsigned int tick, int id, intptr_t data)
{ {
struct block_list *bl = map_id2bl(id); struct block_list *bl = map_id2bl(id);
@ -184,11 +197,11 @@ int unit_teleport_timer(int tid, unsigned int tick, int id, intptr_t data)
} }
/** /**
* Checks if a slave unit is outside their max distance from master \n * Checks if a slave unit is outside their max distance from master \n
* If so, starts a timer for (default: 3 seconds) which will teleport the unit back to master * If so, starts a timer for (default: 3 seconds) which will teleport the unit back to master
* @param sbl: Object with a master [MOB|PET|HOM|MER|ELEM] * @param sbl: Object with a master [MOB|PET|HOM|MER|ELEM]
* @return 0 * @return 0
**/ */
int unit_check_start_teleport_timer(struct block_list *sbl) int unit_check_start_teleport_timer(struct block_list *sbl)
{ {
TBL_PC *msd = unit_get_master(sbl); TBL_PC *msd = unit_get_master(sbl);
@ -217,13 +230,13 @@ int unit_check_start_teleport_timer(struct block_list *sbl)
} }
/** /**
* Defines when to refresh the walking character to object and restart the timer if applicable \n * Defines when to refresh the walking character to object and restart the timer if applicable \n
* Also checks for speed update, target location, and slave teleport timers * Also checks for speed update, target location, and slave teleport timers
* @param tid: Timer ID * @param tid: Timer ID
* @param tick: Current tick to decide next timer update * @param tick: Current tick to decide next timer update
* @param data: Data used in timer calls * @param data: Data used in timer calls
* @return 0 or unit_walktoxy_sub() * @return 0 or unit_walktoxy_sub()
**/ */
static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data) static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
{ {
int i; int i;
@ -388,13 +401,13 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
} }
/** /**
* Delays an xy timer * Delays an xy timer
* @param tid: Timer ID * @param tid: Timer ID
* @param tick: Unused * @param tick: Unused
* @param id: ID of bl to delay timer on * @param id: ID of bl to delay timer on
* @param data: Data used in timer calls * @param data: Data used in timer calls
* @return 1: Success 0: Fail (No valid bl) * @return 1: Success 0: Fail (No valid bl)
**/ */
int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data) int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
{ {
struct block_list *bl = map_id2bl(id); struct block_list *bl = map_id2bl(id);
@ -406,13 +419,13 @@ int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
} }
/** /**
* Delays an walk-to-bl timer * Delays an walk-to-bl timer
* @param tid: Timer ID * @param tid: Timer ID
* @param tick: Unused * @param tick: Unused
* @param id: ID of bl to delay timer on * @param id: ID of bl to delay timer on
* @param data: Data used in timer calls (target bl) * @param data: Data used in timer calls (target bl)
* @return 1: Success 0: Fail (No valid bl or target) * @return 1: Success 0: Fail (No valid bl or target)
**/ */
int unit_delay_walktobl_timer(int tid, unsigned int tick, int id, intptr_t data) int unit_delay_walktobl_timer(int tid, unsigned int tick, int id, intptr_t data)
{ {
struct block_list *bl = map_id2bl(id), *tbl = map_id2bl(data); struct block_list *bl = map_id2bl(id), *tbl = map_id2bl(data);
@ -428,17 +441,17 @@ int unit_delay_walktobl_timer(int tid, unsigned int tick, int id, intptr_t data)
} }
/** /**
* Begins the function of walking a unit to an x,y location \n * Begins the function of walking a unit to an x,y location \n
* This is where the path searches and unit can_move checks are done * This is where the path searches and unit can_move checks are done
* @param bl: Object to send to x,y coordinate * @param bl: Object to send to x,y coordinate
* @param x: X coordinate where the object will be walking to * @param x: X coordinate where the object will be walking to
* @param y: Y coordinate where the object will be walking to * @param y: Y coordinate where the object will be walking to
* @param flag: Parameter to decide how to walk \n * @param flag: Parameter to decide how to walk \n
* &1: Easy walk (fail if CELL_CHKNOPASS is in direct path) \n * &1: Easy walk (fail if CELL_CHKNOPASS is in direct path) \n
* &2: Force walking (override can_move) \n * &2: Force walking (override can_move) \n
* &4: Delay walking for can_move * &4: Delay walking for can_move
* @return 1: Success 0: Fail or unit_walktoxy_sub() * @return 1: Success 0: Fail or unit_walktoxy_sub()
**/ */
int unit_walktoxy( struct block_list *bl, short x, short y, int flag) int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
{ {
struct unit_data* ud = NULL; struct unit_data* ud = NULL;
@ -496,11 +509,11 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
} }
/** /**
* Sets a mob's CHASE/FOLLOW state \n * Sets a mob's CHASE/FOLLOW state \n
* This should not be done if there's no path to reach * This should not be done if there's no path to reach
* @param bl: Mob to set state on * @param bl: Mob to set state on
* @param flag: Whether to set state or not * @param flag: Whether to set state or not
**/ */
static inline void set_mobstate(struct block_list* bl, int flag) static inline void set_mobstate(struct block_list* bl, int flag)
{ {
struct mob_data* md = BL_CAST(BL_MOB,bl); struct mob_data* md = BL_CAST(BL_MOB,bl);
@ -510,13 +523,13 @@ static inline void set_mobstate(struct block_list* bl, int flag)
} }
/** /**
* Timer to walking a unit to another unit's location \n * Timer to walking a unit to another unit's location \n
* Calls unit_walktoxy_sub once determined the unit can move * Calls unit_walktoxy_sub once determined the unit can move
* @param tid: Object's timer ID * @param tid: Object's timer ID
* @param id: Object's ID * @param id: Object's ID
* @param data: Data passed through timer function (target) * @param data: Data passed through timer function (target)
* @return 0 * @return 0
**/ */
static int unit_walktobl_sub(int tid, unsigned int tick, int id, intptr_t data) static int unit_walktobl_sub(int tid, unsigned int tick, int id, intptr_t data)
{ {
struct block_list *bl = map_id2bl(id); struct block_list *bl = map_id2bl(id);
@ -534,15 +547,15 @@ static int unit_walktobl_sub(int tid, unsigned int tick, int id, intptr_t data)
} }
/** /**
* Tells a unit to walk to a target's location (chase) * Tells a unit to walk to a target's location (chase)
* @param bl: Object that is walking to target * @param bl: Object that is walking to target
* @param tbl: Target object * @param tbl: Target object
* @param range: How close to get to target (or attack range if flag&2) * @param range: How close to get to target (or attack range if flag&2)
* @param flag: Extra behaviour \n * @param flag: Extra behaviour \n
* &1: Use hard path seek (obstacles will be walked around if possible) \n * &1: Use hard path seek (obstacles will be walked around if possible) \n
* &2: Start attacking upon arrival within range, otherwise just walk to target * &2: Start attacking upon arrival within range, otherwise just walk to target
* @return 1: Started walking or set timer 0: Failed * @return 1: Started walking or set timer 0: Failed
**/ */
int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int flag) int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int flag)
{ {
struct unit_data *ud = NULL; struct unit_data *ud = NULL;
@ -601,10 +614,10 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
} }
/** /**
* Set a unit to run, checking for obstacles * Set a unit to run, checking for obstacles
* @param bl: Object that is running * @param bl: Object that is running
* @return 1: Success 0: Fail * @return 1: Success 0: Fail
**/ */
int unit_run(struct block_list *bl) int unit_run(struct block_list *bl)
{ {
struct status_change *sc = status_get_sc(bl); struct status_change *sc = status_get_sc(bl);
@ -675,12 +688,13 @@ int unit_run(struct block_list *bl)
return 1; return 1;
} }
/** [Jobbie/3CeAM] \n /**
* Exclusive function used for Wug Dash * Char movement with wugdash
* @param bl: Object that is dashing * @author [Jobbie/3CeAM]
* @param sd: Player * @param bl: Object that is dashing
* @return 1: Success 0: Fail * @param sd: Player
**/ * @return 1: Success 0: Fail
*/
int unit_wugdash(struct block_list *bl, struct map_session_data *sd) int unit_wugdash(struct block_list *bl, struct map_session_data *sd)
{ {
struct status_change *sc = status_get_sc(bl); struct status_change *sc = status_get_sc(bl);
@ -690,7 +704,7 @@ int unit_wugdash(struct block_list *bl, struct map_session_data *sd)
if (!(sc && sc->data[SC_WUGDASH])) if (!(sc && sc->data[SC_WUGDASH]))
return 0; return 0;
nullpo_ret(sd); nullpo_ret(sd); //FIXME do we really need that check since we rechecking afterward
nullpo_ret(bl); nullpo_ret(bl);
if (!unit_can_move(bl)) { if (!unit_can_move(bl)) {
@ -746,12 +760,12 @@ int unit_wugdash(struct block_list *bl, struct map_session_data *sd)
} }
/** /**
* Makes unit attempt to run away from target using hard paths * Makes unit attempt to run away from target using hard paths
* @param bl: Object that is running away from target * @param bl: Object that is running away from target
* @param target: Target * @param target: Target
* @param dist: How far bl should run * @param dist: How far bl should run
* @return 1: Success 0: Fail * @return 1: Success 0: Fail
**/ */
int unit_escape(struct block_list *bl, struct block_list *target, short dist) int unit_escape(struct block_list *bl, struct block_list *target, short dist)
{ {
uint8 dir = map_calc_dir(target, bl->x, bl->y); uint8 dir = map_calc_dir(target, bl->x, bl->y);
@ -761,14 +775,14 @@ int unit_escape(struct block_list *bl, struct block_list *target, short dist)
} }
/** /**
* Instant warps a unit to x,y coordinate * Instant warps a unit to x,y coordinate
* @param bl: Object to instant warp * @param bl: Object to instant warp
* @param dst_x: X coordinate to warp to * @param dst_x: X coordinate to warp to
* @param dst_y: Y coordinate to warp to * @param dst_y: Y coordinate to warp to
* @param easy: Easy(1) or Hard(0) path check (hard attempts to go around obstacles) * @param easy: Easy(1) or Hard(0) path check (hard attempts to go around obstacles)
* @param checkpath: Whether or not to do a cell and path check for NOPASS and NOREACH * @param checkpath: Whether or not to do a cell and path check for NOPASS and NOREACH
* @return 1: Success 0: Fail * @return 1: Success 0: Fail
**/ */
int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath) int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath)
{ {
short dx,dy; short dx,dy;
@ -833,11 +847,11 @@ int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool
} }
/** /**
* Sets direction of a unit * Sets direction of a unit
* @param bl: Object to set direction * @param bl: Object to set direction
* @param dir: Direction (0-7) * @param dir: Direction (0-7)
* @return 0 * @return 0
**/ */
int unit_setdir(struct block_list *bl,unsigned char dir) int unit_setdir(struct block_list *bl,unsigned char dir)
{ {
struct unit_data *ud; struct unit_data *ud;
@ -852,10 +866,10 @@ int unit_setdir(struct block_list *bl,unsigned char dir)
} }
/** /**
* Gets direction of a unit * Gets direction of a unit
* @param bl: Object to get direction * @param bl: Object to get direction
* @return direction (0-7) * @return direction (0-7)
**/ */
uint8 unit_getdir(struct block_list *bl) uint8 unit_getdir(struct block_list *bl)
{ {
struct unit_data *ud; struct unit_data *ud;
@ -866,15 +880,15 @@ uint8 unit_getdir(struct block_list *bl)
} }
/** /**
* Pushes a unit in a direction by a given amount of cells \n * Pushes a unit in a direction by a given amount of cells \n
* There is no path check, only map cell restrictions are respected * There is no path check, only map cell restrictions are respected
* @param bl: Object to push * @param bl: Object to push
* @param dx: Destination cell X * @param dx: Destination cell X
* @param dy: Destination cell Y * @param dy: Destination cell Y
* @param count: How many cells to push bl * @param count: How many cells to push bl
* @param flag: Whether or not to send position packet updates * @param flag: Whether or not to send position packet updates
* @return count (can be modified due to map cell restrictions) * @return count (can be modified due to map cell restrictions)
**/ */
int unit_blown(struct block_list* bl, int dx, int dy, int count, int flag) int unit_blown(struct block_list* bl, int dx, int dy, int count, int flag)
{ {
if(count) { if(count) {
@ -934,16 +948,16 @@ int unit_blown(struct block_list* bl, int dx, int dy, int count, int flag)
} }
/** /**
* Warps a unit to a map/position \n * Warps a unit to a map/position \n
* pc_setpos is used for player warping \n * pc_setpos is used for player warping \n
* This function checks for "no warp" map flags, so it's safe to call without doing nowarpto/nowarp checks * This function checks for "no warp" map flags, so it's safe to call without doing nowarpto/nowarp checks
* @param bl: Object to warp * @param bl: Object to warp
* @param m: Map ID from bl structure (NOT index) * @param m: Map ID from bl structure (NOT index)
* @param x: Destination cell X * @param x: Destination cell X
* @param y: Destination cell Y * @param y: Destination cell Y
* @param type: Clear type used in clif_clearunit_area() * @param type: Clear type used in clif_clearunit_area()
* @return Success(0); Failed(1); Error(2); unit_remove_map() Failed(3); map_addblock Failed(4) * @return Success(0); Failed(1); Error(2); unit_remove_map() Failed(3); map_addblock Failed(4)
**/ */
int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type) int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type)
{ {
struct unit_data *ud; struct unit_data *ud;
@ -1011,15 +1025,15 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type)
} }
/** /**
* Stops a unit from walking * Stops a unit from walking
* @param bl: Object to stop walking * @param bl: Object to stop walking
* @param type: Options \n * @param type: Options \n
* &0x1: Issue a fixpos packet afterwards \n * &0x1: Issue a fixpos packet afterwards \n
* &0x2: Force the unit to move one cell if it hasn't yet \n * &0x2: Force the unit to move one cell if it hasn't yet \n
* &0x4: Enable moving to the next cell when unit was already half-way there \n * &0x4: Enable moving to the next cell when unit was already half-way there \n
* (may cause on-touch/place side-effects, such as a scripted map change) * (may cause on-touch/place side-effects, such as a scripted map change)
* @return Success(1); Failed(0); * @return Success(1); Failed(0);
**/ */
int unit_stop_walking(struct block_list *bl,int type) int unit_stop_walking(struct block_list *bl,int type)
{ {
struct unit_data *ud; struct unit_data *ud;
@ -1064,13 +1078,13 @@ int unit_stop_walking(struct block_list *bl,int type)
} }
/** /**
* Initiates a skill use by a unit * Initiates a skill use by a unit
* @param src: Source object initiating skill use * @param src: Source object initiating skill use
* @param target_id: Target ID (bl->id) * @param target_id: Target ID (bl->id)
* @param skill_id: Skill ID * @param skill_id: Skill ID
* @param skill_lv: Skill Level * @param skill_lv: Skill Level
* @return unit_skilluse_id2() * @return unit_skilluse_id2()
**/ */
int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv) int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv)
{ {
return unit_skilluse_id2( return unit_skilluse_id2(
@ -1081,10 +1095,10 @@ int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, uin
} }
/** /**
* Checks if a unit is walking * Checks if a unit is walking
* @param bl: Object to check walk status * @param bl: Object to check walk status
* @return Walking(1); Not Walking(0) * @return Walking(1); Not Walking(0)
**/ */
int unit_is_walking(struct block_list *bl) int unit_is_walking(struct block_list *bl)
{ {
struct unit_data *ud = unit_bl2ud(bl); struct unit_data *ud = unit_bl2ud(bl);
@ -1093,13 +1107,14 @@ int unit_is_walking(struct block_list *bl)
return (ud->walktimer != INVALID_TIMER); return (ud->walktimer != INVALID_TIMER);
} }
/** [Skotlex] \n /**
* Checks if a unit is able to move based on status changes \n * Checks if a unit is able to move based on status changes \n
* View the StatusChangeStateTable in status.c for a list of statuses \n * View the StatusChangeStateTable in status.c for a list of statuses \n
* Some statuses are still checked here due too specific variables * Some statuses are still checked here due too specific variables
* @param bl: Object to check * @author [Skotlex]
* @return Can move(1); Can't move(0) * @param bl: Object to check
**/ * @return Can move(1); Can't move(0)
*/
int unit_can_move(struct block_list *bl) { int unit_can_move(struct block_list *bl) {
struct map_session_data *sd; struct map_session_data *sd;
struct unit_data *ud; struct unit_data *ud;
@ -1150,12 +1165,12 @@ int unit_can_move(struct block_list *bl) {
} }
/** /**
* Resumes running (RA_WUGDASH or TK_RUN) after a walk delay * Resumes running (RA_WUGDASH or TK_RUN) after a walk delay
* @param tid: Timer ID * @param tid: Timer ID
* @param id: Object ID * @param id: Object ID
* @param data: Data passed through timer function (unit_data) * @param data: Data passed through timer function (unit_data)
* @return 0 * @return 0
**/ */
int unit_resume_running(int tid, unsigned int tick, int id, intptr_t data) int unit_resume_running(int tid, unsigned int tick, int id, intptr_t data)
{ {
@ -1176,15 +1191,15 @@ int unit_resume_running(int tid, unsigned int tick, int id, intptr_t data)
} }
/** /**
* Applies a walk delay to a unit * Applies a walk delay to a unit
* @param bl: Object to apply walk delay to * @param bl: Object to apply walk delay to
* @param tick: Current tick * @param tick: Current tick
* @param delay: Amount of time to set walk delay * @param delay: Amount of time to set walk delay
* @param type: Type of delay \n * @param type: Type of delay \n
* 0: Damage induced delay; Do not change previous delay \n * 0: Damage induced delay; Do not change previous delay \n
* 1: Skill induced delay; Walk delay can only be increased, not decreased * 1: Skill induced delay; Walk delay can only be increased, not decreased
* @return Success(1); Fail(0); * @return Success(1); Fail(0);
**/ */
int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int type) int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int type)
{ {
struct unit_data *ud = unit_bl2ud(bl); struct unit_data *ud = unit_bl2ud(bl);
@ -1221,15 +1236,15 @@ int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int
} }
/** /**
* Performs checks for a unit using a skill and executes after cast time completion * Performs checks for a unit using a skill and executes after cast time completion
* @param src: Object using skill * @param src: Object using skill
* @param target_id: Target ID (bl->id) * @param target_id: Target ID (bl->id)
* @param skill_id: Skill ID * @param skill_id: Skill ID
* @param skill_lv: Skill Level * @param skill_lv: Skill Level
* @param casttime: Initial cast time before cast time reductions * @param casttime: Initial cast time before cast time reductions
* @param castcancel: Whether or not the skill can be cancelled by interuption (hit) * @param castcancel: Whether or not the skill can be cancelled by interuption (hit)
* @return Success(1); Fail(0); * @return Success(1); Fail(0);
**/ */
int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel) int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel)
{ {
struct unit_data *ud; struct unit_data *ud;
@ -1584,14 +1599,14 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
} }
/** /**
* Initiates a placement (ground/non-targeted) skill * Initiates a placement (ground/non-targeted) skill
* @param src: Object using skill * @param src: Object using skill
* @param skill_x: X coordinate where skill is being casted (center) * @param skill_x: X coordinate where skill is being casted (center)
* @param skill_y: Y coordinate where skill is being casted (center) * @param skill_y: Y coordinate where skill is being casted (center)
* @param skill_id: Skill ID * @param skill_id: Skill ID
* @param skill_lv: Skill Level * @param skill_lv: Skill Level
* @return unit_skilluse_pos2() * @return unit_skilluse_pos2()
**/ */
int unit_skilluse_pos(struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv) int unit_skilluse_pos(struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv)
{ {
return unit_skilluse_pos2( return unit_skilluse_pos2(
@ -1602,16 +1617,16 @@ int unit_skilluse_pos(struct block_list *src, short skill_x, short skill_y, uint
} }
/** /**
* Performs checks for a unit using a skill and executes after cast time completion * Performs checks for a unit using a skill and executes after cast time completion
* @param src: Object using skill * @param src: Object using skill
* @param skill_x: X coordinate where skill is being casted (center) * @param skill_x: X coordinate where skill is being casted (center)
* @param skill_y: Y coordinate where skill is being casted (center) * @param skill_y: Y coordinate where skill is being casted (center)
* @param skill_id: Skill ID * @param skill_id: Skill ID
* @param skill_lv: Skill Level * @param skill_lv: Skill Level
* @param casttime: Initial cast time before cast time reductions * @param casttime: Initial cast time before cast time reductions
* @param castcancel: Whether or not the skill can be cancelled by interuption (hit) * @param castcancel: Whether or not the skill can be cancelled by interuption (hit)
* @return Success(1); Fail(0); * @return Success(1); Fail(0);
**/ */
int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel) int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel)
{ {
struct map_session_data *sd = NULL; struct map_session_data *sd = NULL;
@ -1747,11 +1762,11 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
} }
/** /**
* Update a unit's attack target * Update a unit's attack target
* @param ud: Unit data * @param ud: Unit data
* @param target_id: Target ID (bl->id) * @param target_id: Target ID (bl->id)
* @return 0 * @return 0
**/ */
int unit_set_target(struct unit_data* ud, int target_id) int unit_set_target(struct unit_data* ud, int target_id)
{ {
struct unit_data * ux; struct unit_data * ux;
@ -1771,10 +1786,10 @@ int unit_set_target(struct unit_data* ud, int target_id)
} }
/** /**
* Stop a unit's attacks * Stop a unit's attacks
* @param bl: Object to stop * @param bl: Object to stop
* @return 0 * @return 0
**/ */
int unit_stop_attack(struct block_list *bl) int unit_stop_attack(struct block_list *bl)
{ {
struct unit_data *ud = unit_bl2ud(bl); struct unit_data *ud = unit_bl2ud(bl);
@ -1790,10 +1805,10 @@ int unit_stop_attack(struct block_list *bl)
} }
/** /**
* Removes a unit's target due to being unattackable * Removes a unit's target due to being unattackable
* @param bl: Object to unlock target * @param bl: Object to unlock target
* @return 0 * @return 0
**/ */
int unit_unattackable(struct block_list *bl) int unit_unattackable(struct block_list *bl)
{ {
struct unit_data *ud = unit_bl2ud(bl); struct unit_data *ud = unit_bl2ud(bl);
@ -1810,12 +1825,12 @@ int unit_unattackable(struct block_list *bl)
} }
/** /**
* Requests a unit to attack a target * Requests a unit to attack a target
* @param src: Object initiating attack * @param src: Object initiating attack
* @param target_id: Target ID (bl->id) * @param target_id: Target ID (bl->id)
* @param continuous: Whether or not the attack is ongoing * @param continuous: Whether or not the attack is ongoing
* @return Success(0); Fail(1); * @return Success(0); Fail(1);
**/ */
int unit_attack(struct block_list *src,int target_id,int continuous) int unit_attack(struct block_list *src,int target_id,int continuous)
{ {
struct block_list *target; struct block_list *target;
@ -1867,12 +1882,13 @@ int unit_attack(struct block_list *src,int target_id,int continuous)
return 0; return 0;
} }
/** [Skotlex] \n /**
* Cancels an ongoing combo, resets attackable time, and restarts the \n * Cancels an ongoing combo, resets attackable time, and restarts the \n
* attack timer to resume attack after amotion time * attack timer to resume attack after amotion time
* @param bl: Object to cancel combo * @author [Skotlex]
* @return Success(1); Fail(0); * @param bl: Object to cancel combo
**/ * @return Success(1); Fail(0);
*/
int unit_cancel_combo(struct block_list *bl) int unit_cancel_combo(struct block_list *bl)
{ {
struct unit_data *ud; struct unit_data *ud;
@ -1894,13 +1910,13 @@ int unit_cancel_combo(struct block_list *bl)
} }
/** /**
* Does a path_search to check if a position can be reached * Does a path_search to check if a position can be reached
* @param bl: Object to check path * @param bl: Object to check path
* @param x: X coordinate that will be path searched * @param x: X coordinate that will be path searched
* @param y: Y coordinate that will be path searched * @param y: Y coordinate that will be path searched
* @param easy: Easy(1) or Hard(0) path check (hard attempts to go around obstacles) * @param easy: Easy(1) or Hard(0) path check (hard attempts to go around obstacles)
* @return true or false * @return true or false
**/ */
bool unit_can_reach_pos(struct block_list *bl,int x,int y, int easy) bool unit_can_reach_pos(struct block_list *bl,int x,int y, int easy)
{ {
nullpo_retr(false, bl); nullpo_retr(false, bl);
@ -1912,15 +1928,15 @@ bool unit_can_reach_pos(struct block_list *bl,int x,int y, int easy)
} }
/** /**
* Does a path_search to check if a unit can be reached * Does a path_search to check if a unit can be reached
* @param bl: Object to check path * @param bl: Object to check path
* @param tbl: Target to be checked for available path * @param tbl: Target to be checked for available path
* @param range: The number of cells away from bl that the path should be checked * @param range: The number of cells away from bl that the path should be checked
* @param easy: Easy(1) or Hard(0) path check (hard attempts to go around obstacles) * @param easy: Easy(1) or Hard(0) path check (hard attempts to go around obstacles)
* @param x: Pointer storing a valid X coordinate around tbl that can be reached * @param x: Pointer storing a valid X coordinate around tbl that can be reached
* @param y: Pointer storing a valid Y coordinate around tbl that can be reached * @param y: Pointer storing a valid Y coordinate around tbl that can be reached
* @return true or false * @return true or false
**/ */
bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, int easy, short *x, short *y) bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, int easy, short *x, short *y)
{ {
int i; int i;
@ -1956,13 +1972,13 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
} }
/** /**
* Calculates position of Pet/Mercenary/Homunculus/Elemental * Calculates position of Pet/Mercenary/Homunculus/Elemental
* @param bl: Object to calculate position * @param bl: Object to calculate position
* @param tx: X coordinate to go to * @param tx: X coordinate to go to
* @param ty: Y coordinate to go to * @param ty: Y coordinate to go to
* @param dir: Direction which to be 2 cells from master's position * @param dir: Direction which to be 2 cells from master's position
* @return Success(0); Fail(1); * @return Success(0); Fail(1);
**/ */
int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir) int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
{ {
int dx, dy, x, y, i, k; int dx, dy, x, y, i, k;
@ -2014,12 +2030,12 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
} }
/** /**
* Function timer to continuously attack * Function timer to continuously attack
* @param src: Object to continuously attack * @param src: Object to continuously attack
* @param tid: Timer ID * @param tid: Timer ID
* @param tick: Current tick * @param tick: Current tick
* @return Attackable(1); Unattackable(0); * @return Attackable(1); Unattackable(0);
**/ */
static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int tick) static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int tick)
{ {
struct block_list *target; struct block_list *target;
@ -2153,13 +2169,13 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
} }
/** /**
* Timer function to cancel attacking if unit has become unattackable * Timer function to cancel attacking if unit has become unattackable
* @param tid: Timer ID * @param tid: Timer ID
* @param tick: Current tick * @param tick: Current tick
* @param id: Object to cancel attack if applicable * @param id: Object to cancel attack if applicable
* @param data: Data passed from timer call * @param data: Data passed from timer call
* @return 0 * @return 0
**/ */
static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data) static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data)
{ {
struct block_list *bl; struct block_list *bl;
@ -2170,13 +2186,13 @@ static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data)
} }
/** /**
* Cancels a skill's cast * Cancels a skill's cast
* @param bl: Object to cancel cast * @param bl: Object to cancel cast
* @param type: Cancel check flag \n * @param type: Cancel check flag \n
* &1: Cast-Cancel invoked \n * &1: Cast-Cancel invoked \n
* &2: Cancel only if skill is cancellable * &2: Cancel only if skill is cancellable
* @return Success(1); Fail(0); * @return Success(1); Fail(0);
**/ */
int unit_skillcastcancel(struct block_list *bl,int type) int unit_skillcastcancel(struct block_list *bl,int type)
{ {
struct map_session_data *sd = NULL; struct map_session_data *sd = NULL;
@ -2233,9 +2249,9 @@ int unit_skillcastcancel(struct block_list *bl,int type)
} }
/** /**
* Initialized data on a unit * Initialized data on a unit
* @param bl: Object to initialize data on * @param bl: Object to initialize data on
**/ */
void unit_dataset(struct block_list *bl) void unit_dataset(struct block_list *bl)
{ {
struct unit_data *ud; struct unit_data *ud;
@ -2252,10 +2268,10 @@ void unit_dataset(struct block_list *bl)
} }
/** /**
* Gets the number of units attacking another unit * Gets the number of units attacking another unit
* @param bl: Object to check amount of targets * @param bl: Object to check amount of targets
* @return number of targets or 0 * @return number of targets or 0
**/ */
int unit_counttargeted(struct block_list* bl) int unit_counttargeted(struct block_list* bl)
{ {
struct unit_data* ud; struct unit_data* ud;
@ -2265,24 +2281,11 @@ int unit_counttargeted(struct block_list* bl)
} }
/** /**
* Is this even used? Why is it a function? * Changes the size of a unit
**/ * @param bl: Object to change size [PC|MOB]
int unit_fixdamage(struct block_list *src,struct block_list *target,unsigned int tick,int sdelay,int ddelay,int64 damage,int div,int type,int64 damage2) * @param size: New size of bl
{ * @return 0
nullpo_ret(target); */
if(damage+damage2 <= 0)
return 0;
return status_fix_damage(src,target,damage+damage2,clif_damage(target,target,tick,sdelay,ddelay,damage,div,type,damage2));
}
/**
* Changes the size of a unit
* @param bl: Object to change size [PC|MOB]
* @param size: New size of bl
* @return 0
**/
int unit_changeviewsize(struct block_list *bl,short size) int unit_changeviewsize(struct block_list *bl,short size)
{ {
nullpo_ret(bl); nullpo_ret(bl);
@ -2301,15 +2304,15 @@ int unit_changeviewsize(struct block_list *bl,short size)
} }
/** /**
* Removes a bl/ud from the map \n * Removes a bl/ud from the map \n
* On kill specifics are not performed here, check status_damage() * On kill specifics are not performed here, check status_damage()
* @param bl: Object to remove from map * @param bl: Object to remove from map
* @param clrtype: How bl is being removed \n * @param clrtype: How bl is being removed \n
* 0: Assume bl is being warped \n * 0: Assume bl is being warped \n
* 1: Death, appropriate cleanup performed * 1: Death, appropriate cleanup performed
* @param file, line, func: Call information for debug purposes * @param file, line, func: Call information for debug purposes
* @return Success(1); Couldn't be removed or bl was free'd(0) * @return Success(1); Couldn't be removed or bl was free'd(0)
**/ */
int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func) int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func)
{ {
struct unit_data *ud = unit_bl2ud(bl); struct unit_data *ud = unit_bl2ud(bl);
@ -2537,12 +2540,12 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
} }
/** /**
* Removes units of a master when the master is removed from map * Removes units of a master when the master is removed from map
* @param sd: Player * @param sd: Player
* @param clrtype: How bl is being removed \n * @param clrtype: How bl is being removed \n
* 0: Assume bl is being warped \n * 0: Assume bl is being warped \n
* 1: Death, appropriate cleanup performed * 1: Death, appropriate cleanup performed
**/ */
void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype) void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype)
{ {
unit_remove_map(&sd->bl,clrtype); unit_remove_map(&sd->bl,clrtype);
@ -2560,9 +2563,10 @@ void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype)
} }
/** /**
* Frees units of a master when the master is removed from map * Frees units of a player when is removed from map
* @param sd: Player * Also free his pets/homon/mercenary/elemental/etc if he have any
**/ * @param sd: Player
*/
void unit_free_pc(struct map_session_data *sd) void unit_free_pc(struct map_session_data *sd)
{ {
if (sd->pd) unit_free(&sd->pd->bl,CLR_OUTSIGHT); if (sd->pd) unit_free(&sd->pd->bl,CLR_OUTSIGHT);
@ -2573,13 +2577,13 @@ void unit_free_pc(struct map_session_data *sd)
} }
/** /**
* Frees all related resources to the unit * Frees all related resources to the unit
* @param bl: Object being removed from map * @param bl: Object being removed from map
* @param clrtype: How bl is being removed \n * @param clrtype: How bl is being removed \n
* 0: Assume bl is being warped \n * 0: Assume bl is being warped \n
* 1: Death, appropriate cleanup performed * 1: Death, appropriate cleanup performed
* @return 0 * @return 0
**/ */
int unit_free(struct block_list *bl, clr_type clrtype) int unit_free(struct block_list *bl, clr_type clrtype)
{ {
struct unit_data *ud = unit_bl2ud( bl ); struct unit_data *ud = unit_bl2ud( bl );
@ -2803,8 +2807,9 @@ int unit_free(struct block_list *bl, clr_type clrtype)
} }
/** /**
* Initialization function for unit on map start * Initialization function for unit on map start
**/ * called in map::do_init
*/
int do_init_unit(void) int do_init_unit(void)
{ {
add_timer_func_list(unit_attack_timer, "unit_attack_timer"); add_timer_func_list(unit_attack_timer, "unit_attack_timer");
@ -2816,6 +2821,11 @@ int do_init_unit(void)
return 0; return 0;
} }
/**
* Unit module destructor, (thing to do before closing the module)
* called in map::do_final
* @return 0
*/
int do_final_unit(void) int do_final_unit(void)
{ {
// Nothing to do // Nothing to do

View File

@ -14,8 +14,11 @@ struct map_session_data;
#include "path.h" // struct walkpath_data #include "path.h" // struct walkpath_data
#include "skill.h" // struct skill_timerskill, struct skill_unit_group, struct skill_unit_group_tickset #include "skill.h" // struct skill_timerskill, struct skill_unit_group, struct skill_unit_group_tickset
extern const short dirx[8]; ///lookup to know where will move to x according dir
extern const short diry[8]; ///lookup to know where will move to y according dir
struct unit_data { struct unit_data {
struct block_list *bl; struct block_list *bl; ///link to owner object BL_CHAR (BL_PC|BL_HOM|BL_PET|BL_ELE|BL_MER)
struct walkpath_data walkpath; struct walkpath_data walkpath;
struct skill_timerskill *skilltimerskill[MAX_SKILLTIMERSKILL]; struct skill_timerskill *skilltimerskill[MAX_SKILLTIMERSKILL];
struct skill_unit_group *skillunit[MAX_SKILLUNITGROUP]; struct skill_unit_group *skillunit[MAX_SKILLUNITGROUP];
@ -78,6 +81,9 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir);
int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data); int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data);
int unit_delay_walktobl_timer(int tid, unsigned int tick, int id, intptr_t data); int unit_delay_walktobl_timer(int tid, unsigned int tick, int id, intptr_t data);
// Ranger
int unit_wugdash(struct block_list *bl, struct map_session_data *sd);
// Causes the target object to stop moving. // Causes the target object to stop moving.
int unit_stop_walking(struct block_list *bl,int type); int unit_stop_walking(struct block_list *bl,int type);
int unit_can_move(struct block_list *bl); int unit_can_move(struct block_list *bl);
@ -130,10 +136,5 @@ int unit_changeviewsize(struct block_list *bl,short size);
int do_init_unit(void); int do_init_unit(void);
int do_final_unit(void); int do_final_unit(void);
// Ranger
int unit_wugdash(struct block_list *bl, struct map_session_data *sd);
extern const short dirx[8];
extern const short diry[8];
#endif /* _UNIT_H_ */ #endif /* _UNIT_H_ */

View File

@ -20,21 +20,29 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
static int vending_nextid = 0; static int vending_nextid = 0; ///Vending_id counter
static DBMap *vending_db; static DBMap *vending_db; ///Db holder the vender : charid -> map_session_data
/**
* Lookup to get the vending_db outside module
* @return the vending_db
*/
DBMap * vending_getdb(){ DBMap * vending_getdb(){
return vending_db; return vending_db;
} }
/// Returns an unique vending shop id.
static int vending_getuid(void) /**
{ * Create an unique vending shop id.
* @return the next vending_id
*/
static int vending_getuid(void){
return ++vending_nextid; return ++vending_nextid;
} }
/*========================================== /**
* Close shop * Make a player close his shop
*------------------------------------------*/ * @param sd : player session
*/
void vending_closevending(struct map_session_data* sd) void vending_closevending(struct map_session_data* sd)
{ {
nullpo_retv(sd); nullpo_retv(sd);
@ -46,9 +54,11 @@ void vending_closevending(struct map_session_data* sd)
} }
} }
/*========================================== /**
* Request a shop's item list * Player request a shop's item list (a player shop)
*------------------------------------------*/ * @param sd : player requestion the list
* @param id : vender account id (gid)
*/
void vending_vendinglistreq(struct map_session_data* sd, int id) void vending_vendinglistreq(struct map_session_data* sd, int id)
{ {
struct map_session_data* vsd; struct map_session_data* vsd;
@ -70,9 +80,15 @@ void vending_vendinglistreq(struct map_session_data* sd, int id)
clif_vendinglist(sd, id, vsd->vending); clif_vendinglist(sd, id, vsd->vending);
} }
/*========================================== /**
* Purchase item(s) from a shop * Purchase item(s) from a shop
*------------------------------------------*/ * @param sd : buyer player session
* @param aid : account id of vender
* @param uid : shop unique id
* @param data : items data who would like to purchase \n
* data := {<index>.w <amount>.w }[count]
* @param count : number of different items he's trying to buy
*/
void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const uint8* data, int count) void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const uint8* data, int count)
{ {
int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING]; int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING];
@ -226,10 +242,14 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
} }
} }
/*========================================== /**
* Open shop * Player setup a new shop
* data := {<index>.w <amount>.w <value>.l}[count] * @param sd : player opening the shop
*------------------------------------------*/ * @param message : shop title
* @param data : itemlist data \n
* data := {<index>.w <amount>.w <value>.l}[count]
* @param count : number of different items
*/
void vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count) { void vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count) {
int i, j; int i, j;
int vending_skill_lvl; int vending_skill_lvl;
@ -297,8 +317,12 @@ void vending_openvending(struct map_session_data* sd, const char* message, const
idb_put(vending_db, sd->status.char_id, sd); idb_put(vending_db, sd->status.char_id, sd);
} }
/**
/// Checks if an item is being sold in given player's vending. * Checks if an item is being sold in given player's vending.
* @param sd : vender session (player)
* @param nameid : item id
* @return 0:not selling it, 1: yes
*/
bool vending_search(struct map_session_data* sd, unsigned short nameid) { bool vending_search(struct map_session_data* sd, unsigned short nameid) {
int i; int i;
@ -315,8 +339,13 @@ bool vending_search(struct map_session_data* sd, unsigned short nameid) {
} }
/// Searches for all items in a vending, that match given ids, price and possible cards.
/// @return Whether or not the search should be continued. /**
* Searches for all items in a vending, that match given ids, price and possible cards.
* @param sd : The vender session to search into
* @param s : parameter of the search (see s_search_store_search)
* @return Whether or not the search should be continued.
*/
bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s) { bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s) {
int i, c, slot; int i, c, slot;
unsigned int idx, cidx; unsigned int idx, cidx;
@ -367,10 +396,19 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_
return true; return true;
} }
/**
* Initialise the vending module
* called in map::do_init
*/
void do_final_vending(void) { void do_final_vending(void) {
db_destroy(vending_db); db_destroy(vending_db);
} }
/**
* Destory the vending module
* called in map::do_final
*/
void do_init_vending(void) { void do_init_vending(void) {
vending_db = idb_alloc(DB_OPT_BASE); vending_db = idb_alloc(DB_OPT_BASE);
vending_nextid = 0; vending_nextid = 0;

View File

@ -10,9 +10,9 @@ struct map_session_data;
struct s_search_store_search; struct s_search_store_search;
struct s_vending { struct s_vending {
short index; //cart index (return item data) short index; /// cart index (return item data)
short amount; //amout of the item for vending short amount; ///amout of the item for vending
unsigned int value; //at wich price unsigned int value; ///at wich price
}; };
DBMap * vending_getdb(); DBMap * vending_getdb();