forked from github/server
move is_guarded from move.h to guard.h
Conflicts: src/move.c
This commit is contained in:
parent
59c8fbc5a5
commit
5bb2dbfd87
|
@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "alchemy.h"
|
||||
#include "guard.h"
|
||||
#include "move.h"
|
||||
#include "skill.h"
|
||||
#include "study.h"
|
||||
|
|
79
src/guard.c
79
src/guard.c
|
@ -20,7 +20,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "guard.h"
|
||||
#include "laws.h"
|
||||
#include "monster.h"
|
||||
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/save.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -145,3 +148,79 @@ void guard(unit * u, unsigned int mask)
|
|||
unsigned int flags = guard_flags(u);
|
||||
setguard(u, flags & mask);
|
||||
}
|
||||
|
||||
static bool is_guardian_u(const unit * guard, unit * u, unsigned int mask)
|
||||
{
|
||||
if (guard->faction == u->faction)
|
||||
return false;
|
||||
if (is_guard(guard, mask) == 0)
|
||||
return false;
|
||||
if (alliedunit(guard, u->faction, HELP_GUARD))
|
||||
return false;
|
||||
if (ucontact(guard, u))
|
||||
return false;
|
||||
if (!cansee(guard->faction, u->region, u, 0))
|
||||
return false;
|
||||
if (!(u_race(guard)->flags & RCF_FLY) && u_race(u)->flags & RCF_FLY)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_guardian_r(const unit * guard)
|
||||
{
|
||||
if (guard->number == 0)
|
||||
return false;
|
||||
if (besieged(guard))
|
||||
return false;
|
||||
|
||||
/* if region_owners exist then they may be guardians: */
|
||||
if (guard->building && rule_region_owners() && guard == building_owner(guard->building)) {
|
||||
faction *owner = region_get_owner(guard->region);
|
||||
if (owner == guard->faction) {
|
||||
building *bowner = largestbuilding(guard->region, &cmp_taxes, false);
|
||||
if (bowner == guard->building) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((guard->flags & UFL_GUARD) == 0)
|
||||
return false;
|
||||
return fval(u_race(guard), RCF_UNARMEDGUARD) || is_monsters(guard->faction) || (armedmen(guard, true) > 0);
|
||||
}
|
||||
|
||||
bool is_guard(const struct unit * u, unsigned int mask)
|
||||
{
|
||||
return is_guardian_r(u) && (getguard(u) & mask) != 0;
|
||||
}
|
||||
|
||||
unit *is_guarded(region * r, unit * u, unsigned int mask)
|
||||
{
|
||||
unit *u2;
|
||||
int noguards = 1;
|
||||
|
||||
if (!fval(r, RF_GUARDED)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* at this point, u2 is the last unit we tested to
|
||||
* be a guard (and failed), or NULL
|
||||
* i is the position of the first free slot in the cache */
|
||||
|
||||
for (u2 = r->units; u2; u2 = u2->next) {
|
||||
if (is_guardian_r(u2)) {
|
||||
noguards = 0;
|
||||
if (is_guardian_u(u2, u, mask)) {
|
||||
/* u2 is our guard. stop processing (we might have to go further next time) */
|
||||
return u2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (noguards) {
|
||||
/* you are mistaken, sir. there are no guards in these lands */
|
||||
freset(r, RF_GUARDED);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ extern "C" {
|
|||
|
||||
void guard(struct unit * u, unsigned int mask);
|
||||
|
||||
struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask);
|
||||
bool is_guard(const struct unit *u, unsigned int mask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
76
src/move.c
76
src/move.c
|
@ -977,82 +977,6 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static bool is_guardian_u(const unit * guard, unit * u, unsigned int mask)
|
||||
{
|
||||
if (guard->faction == u->faction)
|
||||
return false;
|
||||
if (is_guard(guard, mask) == 0)
|
||||
return false;
|
||||
if (alliedunit(guard, u->faction, HELP_GUARD))
|
||||
return false;
|
||||
if (ucontact(guard, u))
|
||||
return false;
|
||||
if (!cansee(guard->faction, u->region, u, 0))
|
||||
return false;
|
||||
if (!(u_race(guard)->flags & RCF_FLY) && u_race(u)->flags & RCF_FLY)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_guardian_r(const unit * guard)
|
||||
{
|
||||
if (guard->number == 0)
|
||||
return false;
|
||||
if (besieged(guard))
|
||||
return false;
|
||||
|
||||
/* if region_owners exist then they may be guardians: */
|
||||
if (guard->building && rule_region_owners() && guard == building_owner(guard->building)) {
|
||||
faction *owner = region_get_owner(guard->region);
|
||||
if (owner == guard->faction) {
|
||||
building *bowner = largestbuilding(guard->region, &cmp_taxes, false);
|
||||
if (bowner == guard->building) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((guard->flags & UFL_GUARD) == 0)
|
||||
return false;
|
||||
return fval(u_race(guard), RCF_UNARMEDGUARD) || is_monsters(guard->faction) || (armedmen(guard, true) > 0);
|
||||
}
|
||||
|
||||
bool is_guard(const struct unit * u, unsigned int mask)
|
||||
{
|
||||
return is_guardian_r(u) && (getguard(u) & mask) != 0;
|
||||
}
|
||||
|
||||
unit *is_guarded(region * r, unit * u, unsigned int mask)
|
||||
{
|
||||
unit *u2;
|
||||
int noguards = 1;
|
||||
|
||||
if (!fval(r, RF_GUARDED)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* at this point, u2 is the last unit we tested to
|
||||
* be a guard (and failed), or NULL
|
||||
* i is the position of the first free slot in the cache */
|
||||
|
||||
for (u2 = r->units; u2; u2 = u2->next) {
|
||||
if (is_guardian_r(u2)) {
|
||||
noguards = 0;
|
||||
if (is_guardian_u(u2, u, mask)) {
|
||||
/* u2 is our guard. stop processing (we might have to go further next time) */
|
||||
return u2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (noguards) {
|
||||
/* you are mistaken, sir. there are no guards in these lands */
|
||||
freset(r, RF_GUARDED);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool move_blocked(const unit * u, const region * r, const region * r2)
|
||||
{
|
||||
connection *b;
|
||||
|
|
|
@ -60,8 +60,6 @@ extern "C" {
|
|||
int personcapacity(const struct unit *u);
|
||||
void movement(void);
|
||||
void run_to(struct unit *u, struct region *to);
|
||||
struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask);
|
||||
bool is_guard(const struct unit *u, unsigned int mask);
|
||||
int enoughsailors(const struct ship *sh, int sumskill);
|
||||
bool canswim(struct unit *u);
|
||||
bool canfly(struct unit *u);
|
||||
|
|
Loading…
Reference in New Issue