shock: apply also to units with 0 people, because they need to e.g. kill familiar-attributes.

This commit is contained in:
Enno Rehling 2006-02-17 17:47:11 +00:00
parent 61a6a52665
commit da213e5f16
3 changed files with 53 additions and 45 deletions

View File

@ -28,7 +28,6 @@ extern "C" {
/* Prototypen */
void do_shock(struct unit *u, const char *reason);
int use_item_power(struct region * r, struct unit * u);
int use_item_regeneration(struct region * r, struct unit * u);
void showspells(struct region *r, struct unit *u);

View File

@ -107,45 +107,6 @@ report_failure(unit * mage, struct order * ord) {
cmistake(mage, ord, 180, MSG_MAGIC);
}
/* ------------------------------------------------------------- */
/* do_shock - Schockt die Einheit, z.B. bei Verlust eines */
/* Vertrauten. */
/* ------------------------------------------------------------- */
void
do_shock(unit *u, const char *reason)
{
int i;
if(u->number == 0) return;
/* HP - Verlust */
u->hp = (unit_max_hp(u) * u->number)/10;
u->hp = max(1, u->hp);
/* Aura - Verlust */
if(is_mage(u)) {
set_spellpoints(u, max_spellpoints(u->region,u)/10);
}
/* Evt. Talenttageverlust */
for (i=0;i!=u->skill_size;++i) if (rand()%5==0) {
skill * sv = u->skills+i;
int weeks = (sv->level * sv->level - sv->level) / 2;
int change = (weeks+9) / 10;
reduce_skill(u, sv, change);
}
/* Dies ist ein Hack, um das skillmod und familiar-Attribut beim Mage
* zu löschen wenn der Familiar getötet wird. Da sollten wir über eine
* saubere Implementation nachdenken. */
if(!strcmp(reason, "trigger")) {
remove_familiar(u);
}
ADDMSG(&u->faction->msgs, msg_message("shock",
"mage reason", u, strdup(reason)));
}
/* ------------------------------------------------------------- */
/* Spruchanalyse - Ausgabe von curse->info und curse->name */
/* ------------------------------------------------------------- */

View File

@ -17,9 +17,13 @@
#include "shock.h"
/* kernel includes */
#include <curse.h>
#include <spell.h>
#include <unit.h>
#include <kernel/curse.h>
#include <kernel/faction.h>
#include <kernel/magic.h>
#include <kernel/message.h>
#include <kernel/skill.h>
#include <kernel/spell.h>
#include <kernel/unit.h>
/* util includes */
#include <event.h>
@ -27,12 +31,55 @@
#include <base36.h>
/* libc includes */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/***
** shock
**/
/* ------------------------------------------------------------- */
/* do_shock - Schockt die Einheit, z.B. bei Verlust eines */
/* Vertrauten. */
/* ------------------------------------------------------------- */
static void
do_shock(unit *u, const char *reason)
{
int i;
if (u->number > 0) {
/* HP - Verlust */
u->hp = (unit_max_hp(u) * u->number)/10;
u->hp = max(1, u->hp);
}
/* Aura - Verlust */
if (is_mage(u)) {
set_spellpoints(u, max_spellpoints(u->region,u)/10);
}
/* Evt. Talenttageverlust */
for (i=0;i!=u->skill_size;++i) if (rand()%5==0) {
skill * sv = u->skills+i;
int weeks = (sv->level * sv->level - sv->level) / 2;
int change = (weeks+9) / 10;
reduce_skill(u, sv, change);
}
/* Dies ist ein Hack, um das skillmod und familiar-Attribut beim Mage
* zu löschen wenn der Familiar getötet wird. Da sollten wir über eine
* saubere Implementation nachdenken. */
if (strcmp(reason, "trigger")==0) {
remove_familiar(u);
}
ADDMSG(&u->faction->msgs, msg_message("shock",
"mage reason", u, strdup(reason)));
}
static int
shock_handle(trigger * t, void * data)
{
@ -40,8 +87,9 @@ shock_handle(trigger * t, void * data)
unit * u = (unit*)t->data.v;
if (u!=NULL) {
do_shock(u, "trigger");
} else
} else {
log_error(("could not perform shock::handle()\n"));
}
unused(data);
return 0;
}