Feature #2038 ยป 0043-Send-access-areas-to-the-client.patch
| client/packhand.c | ||
|---|---|---|
|
#include "support.h"
|
||
|
/* common */
|
||
|
#include "accessarea.h"
|
||
|
#include "achievements.h"
|
||
|
#include "actions.h"
|
||
|
#include "capstr.h"
|
||
| ... | ... | |
|
{
|
||
|
options_sync_reply(serial);
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Handle access area packet.
|
||
|
**************************************************************************/
|
||
|
void handle_access_area(const struct packet_access_area *packet)
|
||
|
{
|
||
|
struct player *plr = player_by_number(packet->player);
|
||
|
struct aarea_list *alist;
|
||
|
struct access_area *aarea;
|
||
|
if (plr == nullptr) {
|
||
|
log_warn("handle_access_area() received illegal player");
|
||
|
return;
|
||
|
}
|
||
|
if (packet->index == 0) {
|
||
|
/* First access area packet. Clear old set. */
|
||
|
area_list_clear_plr(plr);
|
||
|
alist = aarea_list_new();
|
||
|
area_list_for_player_set(plr, alist);
|
||
|
} else {
|
||
|
alist = area_list_for_player(plr);
|
||
|
}
|
||
|
aarea = fc_malloc(sizeof(struct access_area));
|
||
|
aarea->cities = nullptr;
|
||
|
aarea->index = packet->index;
|
||
|
aarea->capital = packet->capital;
|
||
|
aarea->tiledefs = packet->tiledefs;
|
||
|
aarea_list_append(alist, aarea);
|
||
|
}
|
||
| common/accessarea.c | ||
|---|---|---|
|
area_list_clear(aalist[player_index(pplayer)]);
|
||
|
}
|
||
|
/*********************************************************************//**
|
||
|
Return current area list for player.
|
||
|
@param pplayer Whose list to return
|
||
|
*************************************************************************/
|
||
|
struct aarea_list *area_list_for_player(struct player *pplayer)
|
||
|
{
|
||
|
return aalist[player_index(pplayer)];
|
||
|
}
|
||
|
/*********************************************************************//**
|
||
|
Set access area list for player
|
||
|
@param pplayer Whose list to set
|
||
| common/accessarea.h | ||
|---|---|---|
|
void area_list_clear(struct aarea_list *alist);
|
||
|
void area_list_clear_plr(struct player *pplayer);
|
||
|
struct aarea_list *area_list_for_player(struct player *pplayer);
|
||
|
void area_list_for_player_set(struct player *pplayer, struct aarea_list *alist);
|
||
|
#ifdef __cplusplus
|
||
| common/networking/packets.def | ||
|---|---|---|
|
Max used id:
|
||
|
============
|
||
|
Max id: 520
|
||
|
Max id: 521
|
||
|
Packets are not ordered by their id, but by their category. New packet
|
||
|
with higher id may get added to existing category, and not to the end of file.
|
||
| ... | ... | |
|
type BV_UTYPE_ROLES = bitvector(bv_unit_type_roles)
|
||
|
type BV_DISASTER_EFFECTS = bitvector(bv_disaster_effects)
|
||
|
type BV_SPACESHIP_STRUCT = bitvector(bv_spaceship_structure)
|
||
|
type BV_TILEDEFS = bitvector(bv_tiledefs)
|
||
|
# typedefs for IDs
|
||
|
type EXTRA = SINT8
|
||
| ... | ... | |
|
UINT32 serial;
|
||
|
end
|
||
|
/************** Access areas **********************/
|
||
|
PACKET_ACCESS_AREA = 521; sc, lsend
|
||
|
PLAYER player;
|
||
|
UINT16 index;
|
||
|
BOOL capital;
|
||
|
BV_TILEDEFS tiledefs;
|
||
|
end
|
||
|
/*************** Webclient specific packets ****************/
|
||
|
/* Use range 256:511 for these */
|
||
| server/aahand.c | ||
|---|---|---|
|
struct unit *access_unit;
|
||
|
struct aarea_list *alist;
|
||
|
int index = 0;
|
||
|
struct packet_access_area packet;
|
||
|
area_list_clear_plr(plr);
|
||
|
alist = aarea_list_new();
|
||
| ... | ... | |
|
access_unit = unit_virtual_create(plr, nullptr,
|
||
|
access_utype, 0);
|
||
|
packet.player = player_number(plr);
|
||
|
city_list_iterate(plr->cities, pcity) {
|
||
|
if (pcity->server.aarea == nullptr) {
|
||
|
struct access_area *aarea = fc_malloc(sizeof(struct access_area));
|
||
| ... | ... | |
|
} city_list_iterate_end;
|
||
|
BV_CLR_ALL(aarea->tiledefs);
|
||
|
BV_CLR_ALL(packet.tiledefs);
|
||
|
pf_map_tiles_iterate(pfm, ptile, TRUE) {
|
||
|
if (ptile != nullptr) {
|
||
|
tiledef_iterate(td) {
|
||
|
if (tile_matches_tiledef(td, ptile)) {
|
||
|
BV_SET(aarea->tiledefs, tiledef_number(td));
|
||
|
int tn = tiledef_number(td);
|
||
|
BV_SET(aarea->tiledefs, tn);
|
||
|
BV_SET(packet.tiledefs, tn);
|
||
|
}
|
||
|
} tiledef_iterate_end;
|
||
|
}
|
||
|
} pf_map_tiles_iterate_end;
|
||
|
pf_map_destroy(pfm);
|
||
|
packet.index = aarea->index;
|
||
|
packet.capital = aarea->capital;
|
||
|
lsend_packet_access_area(plr->connections, &packet);
|
||
|
}
|
||
|
} city_list_iterate_end;
|
||