Freeciv-3.1: /fast/freeciv/nightly/S3_1/ai/default/aiferry.c File Reference

Freeciv-3.1

Loading...
Searching...
No Matches
Macros | Functions
aiferry.c File Reference
`#include "log.h"`
`#include "game.h"`
`#include "movement.h"`
`#include "unit.h"`
`#include "unitlist.h"`
`#include "path_finding.h"`
`#include "pf_tools.h"`
`#include "advgoto.h"`
`#include "autoexplorer.h"`
`#include "autosettlers.h"`
`#include "hand_gen.h"`
`#include "srv_log.h"`
`#include "unithand.h"`
`#include "unittools.h"`
`#include "advdata.h"`
`#include "handicaps.h"`
`#include "aidata.h"`
`#include "aiguard.h"`
`#include "ailog.h"`
`#include "aiplayer.h"`
`#include "aitools.h"`
`#include "aiunit.h"`
`#include "daicity.h"`
`#include "aiferry.h"`

Go to the source code of this file.

## Macros

#define | FERRY_AVAILABLE (-1) /* Boat is looking for a passenger */
#define | FERRY_ABANDON_BOSS
#define | FERRY_WANTED (-1) /* Needs a boat */
#define | FERRY_NONE 0 /* Has no boat and doesn't need one */
#define | LOGLEVEL_FERRY LOG_DEBUG
#define | LOGLEVEL_GOBYBOAT LOG_DEBUG
#define | LOGLEVEL_FINDFERRY LOG_DEBUG

## Functions

void | aiferry_init_stats (struct ai_type *ait, struct player *pplayer)
bool | dai_is_ferry_type (const struct unit_type *pferry, struct ai_type *ait)
bool | dai_is_ferry (struct unit *pferry, struct ai_type *ait)
void | dai_ferry_init_ferry (struct ai_type *ait, struct unit *ferry)
void | dai_ferry_transformed (struct ai_type *ait, struct unit *ferry, const struct unit_type *old)
void | dai_ferry_lost (struct ai_type *ait, struct unit *punit)
void | aiferry_clear_boat (struct ai_type *ait, struct unit *punit)
static void | aiferry_request_boat (struct ai_type *ait, struct unit *punit)
static void | aiferry_psngr_meet_boat (struct ai_type *ait, struct unit *punit, struct unit *pferry)
static void | aiferry_make_available (struct ai_type *ait, struct unit *pferry)
int | aiferry_avail_boats (struct ai_type *ait, struct player *pplayer)
static unsigned | combined_land_sea_move (const struct tile *src_tile, enum pf_move_scope src_scope, const struct tile *tgt_tile, enum pf_move_scope dst_scope, const struct pf_parameter *param)
static unsigned | sea_move (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
bool | is_boat_free (struct ai_type *ait, struct unit *boat, struct unit *punit, int cap)
bool | is_boss_of_boat (struct ai_type *ait, struct unit *punit)
int | aiferry_find_boat (struct ai_type *ait, struct unit *punit, int cap, struct pf_path **path)
static int | aiferry_find_boat_nearby (struct ai_type *ait, struct unit *punit, int cap)
static void | dai_activate_passengers (struct ai_type *ait, struct unit *ferry)
bool | dai_amphibious_goto_constrained (struct ai_type *ait, struct unit *ferry, struct unit *passenger, struct tile *ptile, struct pft_amphibious *parameter)
bool | aiferry_goto_amphibious (struct ai_type *ait, struct unit *ferry, struct unit *passenger, struct tile *ptile)
bool | aiferry_gobyboat (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile, bool with_bodyguard)
static bool | aiferry_findcargo (struct ai_type *ait, struct unit *pferry)
static bool | aiferry_find_interested_city (struct ai_type *ait, struct unit *pferry)
void | dai_manage_ferryboat (struct ai_type *ait, struct player *pplayer, struct unit *punit)

## Macro Definition Documentation

## ◆ FERRY_ABANDON_BOSS

#define FERRY_ABANDON_BOSS

Value:
(-2) /* Passenger is assigned for boat, but boat
* might take another passenger. Probably
* passenger already left the boat*/

Definition at line 66 of file aiferry.c.

## ◆ FERRY_AVAILABLE

#define FERRY_AVAILABLE (-1) /* Boat is looking for a passenger */

Definition at line 65 of file aiferry.c.

## ◆ FERRY_NONE

#define FERRY_NONE 0 /* Has no boat and doesn't need one */

Definition at line 72 of file aiferry.c.

## ◆ FERRY_WANTED

#define FERRY_WANTED (-1) /* Needs a boat */

Definition at line 71 of file aiferry.c.

## ◆ LOGLEVEL_FERRY

#define LOGLEVEL_FERRY LOG_DEBUG

Definition at line 78 of file aiferry.c.

## ◆ LOGLEVEL_FINDFERRY

#define LOGLEVEL_FINDFERRY LOG_DEBUG

Definition at line 82 of file aiferry.c.

## ◆ LOGLEVEL_GOBYBOAT

#define LOGLEVEL_GOBYBOAT LOG_DEBUG

Definition at line 80 of file aiferry.c.

## Function Documentation

## ◆ aiferry_avail_boats()

int aiferry_avail_boats | ( | struct ai_type * | ait,
|  | struct player * | pplayer
| ) |  |

Returns the number of available boats. A simple accessor made to perform debug checks.

Definition at line 355 of file aiferry.c.

Referenced by dai_is_unit_tired_waiting_boat().

## ◆ aiferry_clear_boat()

void aiferry_clear_boat | ( | struct ai_type * | ait,
|  | struct unit * | punit
| ) |  |

Use on a unit which no longer needs a boat.

Definition at line 253 of file aiferry.c.

Referenced by dai_caravan_goto(), dai_gothere(), dai_manage_barbarian_leader(), dai_manage_caravan(), dai_manage_military(), and dai_unit_new_task().

## ◆ aiferry_find_boat()

int aiferry_find_boat | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | int | cap,
|  | struct pf_path ** | path
| ) |  |

Proper and real PF function for finding a boat. If you don't require the path to the ferry, pass path=NULL. Return the unit ID of the boat; punit is the passenger.

WARNING: Due to the nature of this function and PF (see the comment of combined_land_sea_move), the path won't lead onto the boat itself.

Definition at line 497 of file aiferry.c.

Referenced by dai_find_boat_for_unit(), find_best_city_placement(), and find_something_to_kill().

## ◆ aiferry_find_boat_nearby()

static int aiferry_find_boat_nearby | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | int | cap
| ) |  |

static

Find a boat within one move from us (i.e. a one we can board).

Definition at line 588 of file aiferry.c.

## ◆ aiferry_find_interested_city()

static bool aiferry_find_interested_city | ( | struct ai_type * | ait,
|  | struct unit * | pferry
| ) |  |

static

A helper for ai_manage_ferryboat. Finds a city that wants a ferry. It might signal for the ferry using pcity->server.ai.choice.need_boat field or it might simply be building a ferry of it's own.

The city found will be set as the goto destination.

TODO: lift the path off the map TODO (possible): put this and ai_ferry_findcargo into one PF-loop. This will save some code lines but will be faster in the rare cases when there passengers that can not be reached ("false positive").

Definition at line 1017 of file aiferry.c.

## ◆ aiferry_findcargo()

static bool aiferry_findcargo | ( | struct ai_type * | ait,
|  | struct unit * | pferry
| ) |  |

static

A helper for ai_manage_ferryboat. Finds a passenger for the ferry. Potential passengers signal the boats by setting their ai.ferry field to FERRY_WANTED.

TODO: Lift the path off the map

Definition at line 951 of file aiferry.c.

## ◆ aiferry_gobyboat()

bool aiferry_gobyboat | ( | struct ai_type * | ait,
|  | struct player * | pplayer,
|  | struct unit * | punit,
|  | struct tile * | dest_tile,
|  | bool | with_bodyguard
| ) |  |

This function is to be called if punit needs to use a boat to get to the destination.

Return values: TRUE if got to or next to our destination, FALSE otherwise.

TODO: A big one is rendezvous points between units and boats. When this is implemented, we won't have to be at the coast to ask for a boat to come to us.

Definition at line 766 of file aiferry.c.

Referenced by dai_gothere(), and dai_military_attack().

## ◆ aiferry_goto_amphibious()

bool aiferry_goto_amphibious | ( | struct ai_type * | ait,
|  | struct unit * | ferry,
|  | struct unit * | passenger,
|  | struct tile * | ptile
| ) |  |

Move a passenger on a ferry to a specified destination. Return FALSE iff we died.

Definition at line 732 of file aiferry.c.

Referenced by dai_military_attack_barbarian().

## ◆ aiferry_init_stats()

void aiferry_init_stats | ( | struct ai_type * | ait,
|  | struct player * | pplayer
| ) |  |

Call to initialize the ferryboat statistics

Definition at line 94 of file aiferry.c.

Referenced by dai_data_phase_begin().

## ◆ aiferry_make_available()

static void aiferry_make_available | ( | struct ai_type * | ait,
|  | struct unit * | pferry
| ) |  |

static

Mark the ferry as available and update the statistics.

Definition at line 341 of file aiferry.c.

## ◆ aiferry_psngr_meet_boat()

static void aiferry_psngr_meet_boat | ( | struct ai_type * | ait,
|  | struct unit * | punit,
|  | struct unit * | pferry
| ) |  |

static

Assign the passenger to the boat and vice versa.

Definition at line 316 of file aiferry.c.

## ◆ aiferry_request_boat()

static void aiferry_request_boat | ( | struct ai_type * | ait,
|  | struct unit * | punit
| ) |  |

static

Request a boat for the unit. Should only be used if the unit is on the coast, otherwise ferries will not see it.

Definition at line 290 of file aiferry.c.

## ◆ combined_land_sea_move()

static unsigned combined_land_sea_move | ( | const struct tile * | src_tile,
|  | enum pf_move_scope | src_scope,
|  | const struct tile * | tgt_tile,
|  | enum pf_move_scope | dst_scope,
|  | const struct pf_parameter * | param
| ) |  |

static

Combined cost function for a land unit looking for a ferry. The path finding first goes over the continent and then into the ocean where we actually look for ferry. Thus moves land-to-sea are allowed and moves sea-to-land are not. A consequence is that we don't get into the cities on other continent, which might station boats. This defficiency seems to be impossible to fix with the current PF structure, so it has to be accounted for in the actual ferry search function.

For movements sea-to-sea the cost is collected via the extra cost call-back. Doesn't care for enemy/neutral tiles, these should be excluded using a TB call-back.

Definition at line 396 of file aiferry.c.

## ◆ dai_activate_passengers()

static void dai_activate_passengers | ( | struct ai_type * | ait,
|  | struct unit * | ferry
| ) |  |

static

Manage the passengers on a ferry, even if they are asleep. This is suitable for when the commander of a ferry has left; it gives a chance for another passenger to take control.

Definition at line 612 of file aiferry.c.

## ◆ dai_amphibious_goto_constrained()

bool dai_amphibious_goto_constrained | ( | struct ai_type * | ait,
|  | struct unit * | ferry,
|  | struct unit * | passenger,
|  | struct tile * | ptile,
|  | struct pft_amphibious * | parameter
| ) |  |

Move a passenger on a ferry to a specified destination. The passenger is assumed to be on the given ferry. The destination may be inland, in which case the passenger will ride the ferry to a beach head, disembark, then continue on land. Return FALSE iff we died.

Definition at line 636 of file aiferry.c.

## ◆ dai_ferry_init_ferry()

void dai_ferry_init_ferry | ( | struct ai_type * | ait,
|  | struct unit * | ferry
| ) |  |

Initialize new ferry when player gets it

Definition at line 169 of file aiferry.c.

Referenced by cai_ferry_init_ferry(), texwai_ferry_init_ferry(), and twai_ferry_init_ferry().

## ◆ dai_ferry_lost()

void dai_ferry_lost | ( | struct ai_type * | ait,
|  | struct unit * | punit
| ) |  |

Close ferry when player loses it

Definition at line 223 of file aiferry.c.

Referenced by cai_ferry_lost(), texwai_ferry_lost(), and twai_ferry_lost().

## ◆ dai_ferry_transformed()

void dai_ferry_transformed | ( | struct ai_type * | ait,
|  | struct unit * | ferry,
|  | const struct unit_type * | old
| ) |  |

Update ferry system when unit is transformed.

Definition at line 191 of file aiferry.c.

Referenced by cai_ferry_transformed(), texwai_ferry_transformed(), and twai_ferry_transformed().

## ◆ dai_is_ferry()

bool dai_is_ferry | ( | struct unit * | pferry,
|  | struct ai_type * | ait
| ) |  |

Should unit be considered a ferry?

Definition at line 161 of file aiferry.c.

Referenced by dai_fill_unit_param(), dai_manage_unit(), dai_military_attack(), and find_best_city_placement().

## ◆ dai_is_ferry_type()

bool dai_is_ferry_type | ( | const struct unit_type * | pferry,
|  | struct ai_type * | ait
| ) |  |

Print the list of boats of pplayer. Should unit type be considered a ferry?

Definition at line 151 of file aiferry.c.

Referenced by kill_something_with().

## ◆ dai_manage_ferryboat()

void dai_manage_ferryboat | ( | struct ai_type * | ait,
|  | struct player * | pplayer,
|  | struct unit * | punit
| ) |  |

It's about 12 feet square and has a capacity of almost 1000 pounds. It is well constructed of teak, and looks seaworthy.

Manage ferryboat. If there is a passenger-in-charge, we let it drive the boat. If there isn't, appoint one from those we have on board.

If there is no one aboard, look for potential cargo. If none found, explore and then go to the nearest port.

Definition at line 1111 of file aiferry.c.

Referenced by dai_manage_unit().

## ◆ is_boat_free()

bool is_boat_free | ( | struct ai_type * | ait,
|  | struct unit * | boat,
|  | struct unit * | punit,
|  | int | cap
| ) |  |

Runs a few checks to determine if "boat" is a free boat that can carry "cap" units of the same type as "punit" over sea.

Definition at line 440 of file aiferry.c.

Referenced by dai_military_attack_barbarian(), and find_something_to_kill().

## ◆ is_boss_of_boat()

bool is_boss_of_boat | ( | struct ai_type * | ait,
|  | struct unit * | punit
| ) |  |

Check if unit is boss in ferry

Definition at line 473 of file aiferry.c.

Referenced by dai_manage_barbarian_leader().

## ◆ sea_move()

static unsigned sea_move | ( | const struct tile * | ptile,
|  | enum known_type | known,
|  | const struct pf_parameter * | param
| ) |  |

static

EC callback to account for the cost of sea moves by a ferry hurrying to pick our unit up.

Definition at line 423 of file aiferry.c.