Freeciv-3.2
Loading...
Searching...
No Matches
infrapts.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - 2004 The Freeciv Project Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifdef HAVE_CONFIG_H
14#include <fc_config.h>
15#endif
16
17/* common */
18#include "map.h"
19
20/* server */
21#include <hand_gen.h> /* <> so looked from the build directory first. */
22#include "maphand.h"
23#include "notify.h"
24#include "plrhand.h"
25
26/************************************************************************/
29void handle_player_place_infra(struct player *pplayer, int tile, int extra)
30{
31 struct tile *ptile;
32 struct extra_type *pextra;
33
34 if (!terrain_control.infrapoints) {
35 return;
36 }
37
38 ptile = index_to_tile(&(wld.map), tile);
39 pextra = extra_by_number(extra);
40
41 if (ptile == NULL || pextra == NULL) {
42 return;
43 }
44
45 if (!map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
47 _("Cannot place %s to unseen tile."),
49 return;
50 }
51
52 if (pplayer->economic.infra_points < pextra->infracost) {
54 _("Cannot place %s for lack of infrapoints."),
56 return;
57 }
58
59 if (!player_can_place_extra(pextra, pplayer, ptile)) {
61 _("Cannot place unbuildable %s."),
63 return;
64 }
65
66 pplayer->economic.infra_points -= pextra->infracost;
67 send_player_info_c(pplayer, pplayer->connections);
68
69 ptile->placing = pextra;
70
71 if (pextra->build_time > 0) {
72 ptile->infra_turns = pextra->build_time;
73 } else {
74 ptile->infra_turns = tile_terrain(ptile)->placing_time * pextra->build_time_factor;
75 }
76
77 /* update_tile_knowledge() would not know to send the tile
78 * when only placing has changed, so send it explicitly. */
79 send_tile_info(pplayer->connections, ptile, FALSE);
80}
char * incite_cost
Definition comments.c:75
bool player_can_place_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:488
struct extra_type * extra_by_number(int id)
Definition extras.c:183
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define _(String)
Definition fcintl.h:67
const struct ft_color ftc_server
struct world wld
Definition game.c:63
void handle_player_place_infra(struct player *pplayer, int tile, int extra)
Definition infrapts.c:29
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:456
struct terrain_misc terrain_control
Definition map.c:69
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:491
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
int build_time_factor
Definition extras.h:119
int build_time
Definition extras.h:118
int infracost
Definition extras.h:122
int infra_points
Definition player.h:65
struct conn_list * connections
Definition player.h:296
struct player_economic economic
Definition player.h:282
Definition tile.h:50
int infra_turns
Definition tile.h:62
struct extra_type * placing
Definition tile.h:61
struct civ_map map
#define FALSE
Definition support.h:47
#define tile_terrain(_tile)
Definition tile.h:110