2016-11-01 17:25:52 +01:00
|
|
|
/*
|
2015-01-30 22:10:29 +01:00
|
|
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
2014-12-12 21:06:47 +01:00
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include "spy.h"
|
2016-11-01 22:11:10 +01:00
|
|
|
#include "guard.h"
|
2012-06-14 08:25:20 +02:00
|
|
|
#include "laws.h"
|
2014-08-27 06:40:18 +02:00
|
|
|
#include "move.h"
|
|
|
|
#include "reports.h"
|
2016-03-08 14:09:22 +01:00
|
|
|
#include "study.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* kernel includes */
|
2016-11-22 12:32:28 +01:00
|
|
|
#include <kernel/config.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/faction.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
#include <kernel/messages.h>
|
2012-06-24 07:36:17 +02:00
|
|
|
#include <kernel/order.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
/* attributes includes */
|
2010-09-03 08:29:33 +02:00
|
|
|
#include <attributes/otherfaction.h>
|
2014-11-01 12:09:56 +01:00
|
|
|
#include <attributes/racename.h>
|
|
|
|
#include <attributes/stealth.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
#include <util/attrib.h>
|
|
|
|
#include <util/base36.h>
|
2016-11-23 19:04:17 +01:00
|
|
|
#include <util/bsdstring.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/parser.h>
|
|
|
|
#include <util/rand.h>
|
|
|
|
#include <util/rng.h>
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-07-07 09:44:24 +02:00
|
|
|
#include <limits.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* in spy steht der Unterschied zwischen Wahrnehmung des Opfers und
|
|
|
|
* Spionage des Spions */
|
2011-03-07 08:02:35 +01:00
|
|
|
void spy_message(int spy, const unit * u, const unit * target)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-10-27 12:36:11 +01:00
|
|
|
char status[32];
|
|
|
|
|
|
|
|
report_status(target, u->faction->locale, status, sizeof(status));
|
2014-12-12 21:06:47 +01:00
|
|
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("spyreport", "spy target status", u,
|
2015-10-27 12:36:11 +01:00
|
|
|
target, status));
|
2014-12-12 21:06:47 +01:00
|
|
|
if (spy > 20) {
|
2017-10-06 21:53:07 +02:00
|
|
|
sc_mage *mage = get_mage_depr(target);
|
2014-12-12 21:06:47 +01:00
|
|
|
/* for mages, spells and magic school */
|
|
|
|
if (mage) {
|
2015-01-13 13:34:26 +01:00
|
|
|
ADDMSG(&u->faction->msgs, msg_message("spyreport_mage", "spy target type", u,
|
2014-12-12 21:06:47 +01:00
|
|
|
target, magic_school[mage->magietyp]));
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
if (spy > 6) {
|
|
|
|
faction *fv = visible_faction(u->faction, target);
|
|
|
|
if (fv && fv != target->faction) {
|
|
|
|
/* true faction */
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("spyreport_faction",
|
2015-01-13 13:34:26 +01:00
|
|
|
"spy target faction", u, target, target->faction));
|
2014-12-12 21:06:47 +01:00
|
|
|
add_seen_faction(u->faction, target->faction);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
if (spy > 0) {
|
|
|
|
int first = 1;
|
|
|
|
int found = 0;
|
|
|
|
skill *sv;
|
|
|
|
char buf[4096];
|
|
|
|
|
|
|
|
buf[0] = 0;
|
|
|
|
for (sv = target->skills; sv != target->skills + target->skill_size; ++sv) {
|
|
|
|
if (sv->level > 0) {
|
|
|
|
found++;
|
|
|
|
if (first == 1) {
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
else {
|
2016-11-23 19:04:17 +01:00
|
|
|
strlcat(buf, ", ", sizeof(buf));
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2016-11-23 19:04:17 +01:00
|
|
|
strlcat(buf, (const char *)skillname((skill_t)sv->id, u->faction->locale),
|
|
|
|
sizeof(buf));
|
|
|
|
strlcat(buf, " ", sizeof(buf));
|
|
|
|
strlcat(buf, itoa10(eff_skill(target, sv, target->region)),
|
|
|
|
sizeof(buf));
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
2015-01-13 13:34:26 +01:00
|
|
|
ADDMSG(&u->faction->msgs, msg_message("spyreport_skills", "spy target skills", u,
|
2014-12-12 21:06:47 +01:00
|
|
|
target, buf));
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
if (target->items) {
|
2015-01-18 17:40:54 +01:00
|
|
|
ADDMSG(&u->faction->msgs, msg_message("spyreport_items", "spy target items", u,
|
2014-12-12 21:06:47 +01:00
|
|
|
target, target->items));
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
int spy_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-12 21:06:47 +01:00
|
|
|
unit *target;
|
|
|
|
int spy, observe;
|
|
|
|
double spychance, observechance;
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
init_order(ord);
|
|
|
|
getunit(r, u->faction, &target);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
if (!target) {
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
msg_feedback(u, u->thisorder, "feedback_unit_not_found", ""));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!can_contact(r, u, target)) {
|
|
|
|
cmistake(u, u->thisorder, 24, MSG_EVENT);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-08-27 16:16:55 +02:00
|
|
|
if (effskill(u, SK_SPY, 0) < 1) {
|
2014-12-12 21:06:47 +01:00
|
|
|
cmistake(u, u->thisorder, 39, MSG_EVENT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Die Grundchance fuer einen erfolgreichen Spionage-Versuch ist 10%.
|
|
|
|
* Fuer jeden Talentpunkt, den das Spionagetalent das Tarnungstalent
|
|
|
|
* des Opfers uebersteigt, erhoeht sich dieses um 5%*/
|
2015-08-27 16:16:55 +02:00
|
|
|
spy = effskill(u, SK_SPY, 0) - effskill(target, SK_STEALTH, r);
|
2017-01-10 16:31:05 +01:00
|
|
|
spychance = 0.1 + MAX(spy * 0.05, 0.0);
|
2014-12-12 21:06:47 +01:00
|
|
|
|
|
|
|
if (chance(spychance)) {
|
|
|
|
produceexp(u, SK_SPY, u->number);
|
|
|
|
spy_message(spy, u, target);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("spyfail", "spy target", u, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* der Spion kann identifiziert werden, wenn das Opfer bessere
|
|
|
|
* Wahrnehmung als das Ziel Tarnung + Spionage/2 hat */
|
2015-08-27 16:16:55 +02:00
|
|
|
observe = effskill(target, SK_PERCEPTION, r)
|
|
|
|
- (effskill(u, SK_STEALTH, 0) + effskill(u, SK_SPY, 0) / 2);
|
2014-12-12 21:06:47 +01:00
|
|
|
|
|
|
|
if (invisible(u, target) >= u->number) {
|
2017-01-10 16:31:05 +01:00
|
|
|
observe = MIN(observe, 0);
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Anschliessend wird - unabhaengig vom Erfolg - gewuerfelt, ob der
|
|
|
|
* Spionageversuch bemerkt wurde. Die Wahrscheinlich dafuer ist (100 -
|
|
|
|
* SpionageSpion*5 + WahrnehmungOpfer*2)%. */
|
2015-08-27 16:16:55 +02:00
|
|
|
observechance = 1.0 - (effskill(u, SK_SPY, 0) * 0.05)
|
|
|
|
+ (effskill(target, SK_PERCEPTION, 0) * 0.02);
|
2014-12-12 21:06:47 +01:00
|
|
|
|
|
|
|
if (chance(observechance)) {
|
|
|
|
ADDMSG(&target->faction->msgs, msg_message("spydetect",
|
|
|
|
"spy target", observe > 0 ? u : NULL, target));
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-01 14:59:20 +01:00
|
|
|
static bool can_set_factionstealth(const unit * u, const faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-12 21:06:47 +01:00
|
|
|
region *lastr = NULL;
|
|
|
|
/* for all units mu of our faction, check all the units in the region
|
|
|
|
* they are in, if their visible faction is f, it's ok. use lastr to
|
|
|
|
* avoid testing the same region twice in a row. */
|
|
|
|
unit *mu = u->faction->units;
|
|
|
|
while (mu != NULL) {
|
|
|
|
if (mu->number && mu->region != lastr) {
|
|
|
|
unit *ru = mu->region->units;
|
|
|
|
lastr = mu->region;
|
|
|
|
while (ru != NULL) {
|
|
|
|
if (ru->number) {
|
|
|
|
faction *fv = visible_faction(f, ru);
|
|
|
|
if (fv == f) {
|
|
|
|
if (cansee(f, lastr, ru, 0))
|
2017-03-01 14:59:20 +01:00
|
|
|
return true;
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ru = ru->next;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
mu = mu->nextF;
|
|
|
|
}
|
2017-03-01 14:59:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_factionstealth(unit *u, faction *f) {
|
|
|
|
attrib *a = a_find(u->attribs, &at_otherfaction);
|
|
|
|
if (!a)
|
|
|
|
a = a_add(&u->attribs, make_otherfaction(f));
|
|
|
|
else
|
|
|
|
a->data.v = f;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
int setstealth_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-31 21:07:42 +01:00
|
|
|
char token[64];
|
2014-12-12 21:06:47 +01:00
|
|
|
const char *s;
|
2015-11-09 13:36:52 +01:00
|
|
|
int level;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
init_order(ord);
|
2014-12-31 21:07:42 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
/* Tarne ohne Parameter: Setzt maximale Tarnung */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
if (s == NULL || *s == 0) {
|
|
|
|
u_seteffstealth(u, -1);
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-02-03 21:19:39 +01:00
|
|
|
if (isdigit(*(const unsigned char *)s)) {
|
2014-12-12 21:06:47 +01:00
|
|
|
/* Tarnungslevel setzen */
|
|
|
|
level = atoi((const char *)s);
|
2015-08-27 16:16:55 +02:00
|
|
|
if (level > effskill(u, SK_STEALTH, 0)) {
|
2014-12-12 21:06:47 +01:00
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_lowstealth", ""));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
u_seteffstealth(u, level);
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-04-17 16:31:52 +02:00
|
|
|
if (skill_enabled(SK_STEALTH)) { /* hack! E3 erlaubt keine Tarnung */
|
|
|
|
const race *trace;
|
|
|
|
|
|
|
|
trace = findrace(s, u->faction->locale);
|
|
|
|
if (trace) {
|
|
|
|
/* demons can cloak as other player-races */
|
|
|
|
if (u_race(u) == get_race(RC_DAEMON)) {
|
2017-04-17 20:18:37 +02:00
|
|
|
if (playerrace(trace)) {
|
2015-04-17 16:31:52 +02:00
|
|
|
u->irace = trace;
|
2017-04-22 18:38:34 +02:00
|
|
|
if (u_race(u)->flags & RCF_SHAPESHIFTANY && get_racename(u->attribs)) {
|
2015-04-17 16:31:52 +02:00
|
|
|
set_racename(&u->attribs, NULL);
|
2017-04-22 18:33:47 +02:00
|
|
|
}
|
2015-04-17 16:31:52 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2015-04-17 16:31:52 +02:00
|
|
|
/* Singdrachen koennen sich nur als Drachen tarnen */
|
2017-04-22 18:33:47 +02:00
|
|
|
else if (u_race(u) == get_race(RC_SONGDRAGON)
|
2015-04-17 16:31:52 +02:00
|
|
|
|| u_race(u) == get_race(RC_BIRTHDAYDRAGON)) {
|
|
|
|
if (trace == get_race(RC_SONGDRAGON) || trace == get_race(RC_FIREDRAGON)
|
|
|
|
|| trace == get_race(RC_DRAGON) || trace == get_race(RC_WYRM)) {
|
|
|
|
u->irace = trace;
|
|
|
|
if (u_race(u)->flags & RCF_SHAPESHIFTANY && get_racename(u->attribs))
|
|
|
|
set_racename(&u->attribs, NULL);
|
|
|
|
}
|
|
|
|
return 0;
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
|
|
|
|
2015-04-17 16:31:52 +02:00
|
|
|
/* Daemomen und Illusionsparteien koennen sich als andere race tarnen */
|
|
|
|
if (u_race(u)->flags & RCF_SHAPESHIFT) {
|
|
|
|
if (playerrace(trace)) {
|
|
|
|
u->irace = trace;
|
|
|
|
if ((u_race(u)->flags & RCF_SHAPESHIFTANY) && get_racename(u->attribs))
|
|
|
|
set_racename(&u->attribs, NULL);
|
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2015-04-17 16:31:52 +02:00
|
|
|
return 0;
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
switch (findparam(s, u->faction->locale)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
case P_FACTION:
|
2014-12-12 21:06:47 +01:00
|
|
|
/* TARNE PARTEI [NICHT|NUMMER abcd] */
|
2014-12-31 21:07:42 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2015-11-09 13:36:52 +01:00
|
|
|
if (rule_stealth_anon()) {
|
2014-12-12 21:06:47 +01:00
|
|
|
if (!s || *s == 0) {
|
2016-12-03 23:38:53 +01:00
|
|
|
u->flags |= UFL_ANON_FACTION;
|
2014-12-12 21:06:47 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (findparam(s, u->faction->locale) == P_NOT) {
|
2016-12-03 23:38:53 +01:00
|
|
|
u->flags &= ~UFL_ANON_FACTION;
|
2014-12-12 21:06:47 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-09 13:36:52 +01:00
|
|
|
if (rule_stealth_other()) {
|
2014-12-12 21:06:47 +01:00
|
|
|
if (get_keyword(s, u->faction->locale) == K_NUMBER) {
|
|
|
|
int nr = -1;
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-12-31 21:07:42 +01:00
|
|
|
if (s) {
|
|
|
|
nr = atoi36(s);
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2014-12-31 21:07:42 +01:00
|
|
|
if (!s || *s == 0 || nr == u->faction->no) {
|
2014-12-12 21:06:47 +01:00
|
|
|
a_removeall(&u->attribs, &at_otherfaction);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct faction *f = findfaction(nr);
|
2017-03-01 14:59:20 +01:00
|
|
|
if (f == NULL || !can_set_factionstealth(u, f)) {
|
2014-12-12 21:06:47 +01:00
|
|
|
cmistake(u, ord, 66, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_factionstealth(u, f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-05 04:21:00 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
cmistake(u, ord, 289, MSG_EVENT);
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
case P_ANY:
|
|
|
|
case P_NOT:
|
2014-12-12 21:06:47 +01:00
|
|
|
/* TARNE ALLES (was nicht so alles geht?) */
|
|
|
|
u_seteffstealth(u, -1);
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
default:
|
2014-12-12 21:06:47 +01:00
|
|
|
if (u_race(u)->flags & RCF_SHAPESHIFTANY) {
|
|
|
|
set_racename(&u->attribs, s);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmistake(u, ord, 289, MSG_EVENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-08-07 09:03:19 +02:00
|
|
|
static int top_skill(region * r, faction * f, ship * sh, skill_t sk)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-12 21:06:47 +01:00
|
|
|
int value = 0;
|
|
|
|
unit *u;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
if (u->ship == sh && u->faction == f) {
|
2015-08-27 16:16:55 +02:00
|
|
|
int s = effskill(u, sk, 0);
|
2017-01-10 16:31:05 +01:00
|
|
|
value = MAX(s, value);
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
return value;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int try_destruction(unit * u, unit * u2, const ship * sh, int skilldiff)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-12 21:06:47 +01:00
|
|
|
const char *destruction_success_msg = "destroy_ship_0";
|
|
|
|
const char *destruction_failed_msg = "destroy_ship_1";
|
|
|
|
const char *destruction_detected_msg = "destroy_ship_2";
|
|
|
|
const char *detect_failure_msg = "destroy_ship_3";
|
|
|
|
const char *object_destroyed_msg = "destroy_ship_4";
|
|
|
|
|
|
|
|
if (skilldiff == 0) {
|
|
|
|
/* tell the unit that the attempt failed: */
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message(destruction_failed_msg, "ship unit",
|
|
|
|
sh, u));
|
|
|
|
/* tell the enemy about the attempt: */
|
|
|
|
if (u2) {
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message(detect_failure_msg, "ship", sh));
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
else if (skilldiff < 0) {
|
|
|
|
/* tell the unit that the attempt was detected: */
|
2015-07-07 00:49:12 +02:00
|
|
|
ADDMSG(&u->faction->msgs, msg_message(destruction_detected_msg,
|
2014-12-12 21:06:47 +01:00
|
|
|
"ship unit", sh, u));
|
|
|
|
/* tell the enemy whodunit: */
|
|
|
|
if (u2) {
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message(detect_failure_msg, "ship", sh));
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
else {
|
|
|
|
/* tell the unit that the attempt succeeded */
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message(destruction_success_msg, "ship unit",
|
|
|
|
sh, u));
|
|
|
|
if (u2) {
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message(object_destroyed_msg, "ship", sh));
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
return 1; /* success */
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 09:29:43 +02:00
|
|
|
static void sink_ship(region * r, ship * sh, unit * saboteur)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-12 21:06:47 +01:00
|
|
|
unit **ui, *u;
|
|
|
|
region *safety = r;
|
|
|
|
int i;
|
|
|
|
direction_t d;
|
|
|
|
double probability = 0.0;
|
|
|
|
message *sink_msg = NULL;
|
|
|
|
faction *f;
|
|
|
|
|
2015-07-07 09:29:43 +02:00
|
|
|
assert(r);
|
|
|
|
assert(sh);
|
|
|
|
assert(saboteur);
|
2014-12-12 21:06:47 +01:00
|
|
|
for (f = NULL, u = r->units; u; u = u->next) {
|
|
|
|
/* slight optimization to avoid dereferencing u->faction each time */
|
|
|
|
if (f != u->faction) {
|
|
|
|
f = u->faction;
|
2016-12-03 23:38:53 +01:00
|
|
|
f->flags &= ~FFL_SELECT;
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
/* figure out what a unit's chances of survival are: */
|
2016-11-22 12:32:28 +01:00
|
|
|
if (!(r->terrain->flags & SEA_REGION)) {
|
2014-12-12 21:06:47 +01:00
|
|
|
probability = CANAL_SWIMMER_CHANCE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
|
|
|
region *rn = rconnect(r, d);
|
2016-11-22 12:32:28 +01:00
|
|
|
if (rn && !(rn->terrain->flags & SEA_REGION) && !move_blocked(NULL, r, rn)) {
|
2014-12-12 21:06:47 +01:00
|
|
|
safety = rn;
|
|
|
|
probability = OCEAN_SWIMMER_CHANCE;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
2015-07-07 09:29:43 +02:00
|
|
|
for (ui = &r->units; *ui;) {
|
2014-12-12 21:06:47 +01:00
|
|
|
unit *u = *ui;
|
|
|
|
|
|
|
|
/* inform this faction about the sinking ship: */
|
2016-11-22 12:32:28 +01:00
|
|
|
if (!(u->faction->flags & FFL_SELECT)) {
|
2014-12-12 21:06:47 +01:00
|
|
|
fset(u->faction, FFL_SELECT);
|
|
|
|
if (sink_msg == NULL) {
|
|
|
|
sink_msg = msg_message("sink_msg", "ship region", sh, r);
|
|
|
|
}
|
|
|
|
add_message(&f->msgs, sink_msg);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
|
|
|
|
if (u->ship == sh) {
|
|
|
|
int dead = 0;
|
|
|
|
message *msg;
|
|
|
|
|
|
|
|
/* if this fails, I misunderstood something: */
|
|
|
|
for (i = 0; i != u->number; ++i)
|
|
|
|
if (chance(probability))
|
|
|
|
++dead;
|
|
|
|
|
|
|
|
if (dead != u->number) {
|
|
|
|
/* she will live. but her items get stripped */
|
|
|
|
if (dead > 0) {
|
|
|
|
msg =
|
|
|
|
msg_message("sink_lost_msg", "dead region unit", dead, safety, u);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
msg = msg_message("sink_saved_msg", "region unit", safety, u);
|
|
|
|
}
|
|
|
|
leave_ship(u);
|
|
|
|
if (r != safety) {
|
2016-10-31 07:45:06 +01:00
|
|
|
setguard(u, false);
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
|
|
|
while (u->items) {
|
|
|
|
i_remove(&u->items, u->items);
|
|
|
|
}
|
|
|
|
move_unit(u, safety, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
msg = msg_message("sink_lost_msg", "dead region unit", dead, NULL, u);
|
|
|
|
}
|
|
|
|
add_message(&u->faction->msgs, msg);
|
|
|
|
msg_release(msg);
|
|
|
|
if (dead == u->number) {
|
2015-07-07 09:29:43 +02:00
|
|
|
if (remove_unit(ui, u) == 0) {
|
|
|
|
/* ui is already pointing at u->next */
|
|
|
|
continue;
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2015-07-07 09:29:43 +02:00
|
|
|
ui = &u->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
if (sink_msg)
|
|
|
|
msg_release(sink_msg);
|
|
|
|
/* finally, get rid of the ship */
|
|
|
|
remove_ship(&sh->region->ships, sh);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
int sabotage_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-12 21:06:47 +01:00
|
|
|
const char *s;
|
2015-07-07 09:29:43 +02:00
|
|
|
param_t p;
|
2014-12-12 21:06:47 +01:00
|
|
|
ship *sh;
|
|
|
|
unit *u2;
|
2015-07-07 09:29:43 +02:00
|
|
|
int skdiff = INT_MAX;
|
|
|
|
|
|
|
|
assert(u);
|
|
|
|
assert(ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
init_order(ord);
|
|
|
|
s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-07-07 09:29:43 +02:00
|
|
|
p = findparam(s, u->faction->locale);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-07-07 09:29:43 +02:00
|
|
|
switch (p) {
|
2011-03-07 08:02:35 +01:00
|
|
|
case P_SHIP:
|
2014-12-12 21:06:47 +01:00
|
|
|
sh = u->ship;
|
|
|
|
if (!sh) {
|
|
|
|
cmistake(u, u->thisorder, 144, MSG_EVENT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
u2 = ship_owner(sh);
|
2015-07-07 09:29:43 +02:00
|
|
|
if (u2->faction != u->faction) {
|
|
|
|
skdiff =
|
2015-08-27 16:16:55 +02:00
|
|
|
effskill(u, SK_SPY, 0) - top_skill(u->region, u2->faction, sh, SK_PERCEPTION);
|
2015-07-07 09:29:43 +02:00
|
|
|
}
|
2014-12-12 21:06:47 +01:00
|
|
|
if (try_destruction(u, u2, sh, skdiff)) {
|
2015-08-27 16:16:55 +02:00
|
|
|
sink_ship(u->region, sh, u);
|
2014-12-12 21:06:47 +01:00
|
|
|
}
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
default:
|
2014-12-12 21:06:47 +01:00
|
|
|
cmistake(u, u->thisorder, 9, MSG_EVENT);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|