forked from github/server
new feature: sea serpents will not go after small targets.
This commit is contained in:
parent
b9b3f0322e
commit
c5181195d7
|
@ -38,37 +38,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static critbit_tree cb_equipments = { 0 };
|
||||
|
||||
equipment *get_equipment(const char *eqname)
|
||||
{
|
||||
const char *match;
|
||||
equipment *eq = NULL;
|
||||
|
||||
match = cb_find_str(&cb_equipments, eqname);
|
||||
if (match) {
|
||||
cb_get_kv(match, &eq, sizeof(eq));
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
equipment *get_or_create_equipment(const char *eqname)
|
||||
{
|
||||
equipment *eq = get_equipment(eqname);
|
||||
if (!eq) {
|
||||
size_t len;
|
||||
char data[64];
|
||||
|
||||
eq = (equipment *)calloc(1, sizeof(equipment));
|
||||
eq->name = strdup(eqname);
|
||||
|
||||
len = cb_new_kv(eqname, strlen(eqname), &eq, sizeof(eq), data);
|
||||
assert(len <= sizeof(data));
|
||||
cb_insert(&cb_equipments, data, len);
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
void equipment_setskill(equipment * eq, skill_t sk, const char *value)
|
||||
{
|
||||
if (eq != NULL) {
|
||||
|
@ -231,6 +200,37 @@ void free_ls(void *arg) {
|
|||
free(ls);
|
||||
}
|
||||
|
||||
static critbit_tree cb_equipments = { 0 };
|
||||
|
||||
equipment *get_equipment(const char *eqname)
|
||||
{
|
||||
const char *match;
|
||||
equipment *eq = NULL;
|
||||
|
||||
match = cb_find_str(&cb_equipments, eqname);
|
||||
if (match) {
|
||||
cb_get_kv(match, &eq, sizeof(eq));
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
equipment *get_or_create_equipment(const char *eqname)
|
||||
{
|
||||
equipment *eq = get_equipment(eqname);
|
||||
if (!eq) {
|
||||
size_t len;
|
||||
char data[64];
|
||||
|
||||
eq = (equipment *)calloc(1, sizeof(equipment));
|
||||
eq->name = strdup(eqname);
|
||||
|
||||
len = cb_new_kv(eqname, strlen(eqname), &eq, sizeof(eq), data);
|
||||
assert(len <= sizeof(data));
|
||||
cb_insert(&cb_equipments, data, len);
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
static void free_equipment(equipment *eq) {
|
||||
int i;
|
||||
free(eq->name);
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
@ -191,6 +192,7 @@ void monsters_desert(struct faction *monsters)
|
|||
|
||||
int monster_attacks(unit * monster, bool rich_only)
|
||||
{
|
||||
const race *rc_serpent = get_race(RC_SEASERPENT);
|
||||
if (monster->status < ST_AVOID) {
|
||||
region *r = monster->region;
|
||||
unit *u2;
|
||||
|
@ -199,6 +201,12 @@ int monster_attacks(unit * monster, bool rich_only)
|
|||
for (u2 = r->units; u2; u2 = u2->next) {
|
||||
if (u2->faction != monster->faction && cansee(monster->faction, r, u2, 0) && !in_safe_building(u2, monster)) {
|
||||
int m = get_money(u2);
|
||||
if (u_race(monster) == rc_serpent) {
|
||||
/* attack bigger ships only */
|
||||
if (!u2->ship || u2->ship->type->cargo <= 50000) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!rich_only || m > 0) {
|
||||
order *ord = monster_attack(monster, u2);
|
||||
if (ord) {
|
||||
|
|
Loading…
Reference in New Issue