summaryrefslogtreecommitdiff
path: root/src/map/magic.c
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-12-25 05:00:31 -0500
committerJared Adams <jaxad0127@gmail.com>2009-12-26 00:40:11 -0700
commit634aeeb9d58b01f9de6632a014a063ef0c4cf31e (patch)
tree70023dd2bcc12a3f96ec6f118d80e27411920531 /src/map/magic.c
parent113fcc4f0a7a0921e94bc415515dd4b393a29d60 (diff)
downloadtmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.tar.gz
tmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.tar.bz2
tmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.tar.xz
tmwa-634aeeb9d58b01f9de6632a014a063ef0c4cf31e.zip
Used the "indent" C formatting program from GNU to do some clean ups
The command options used was: -nbad -bap -sc -bl -blf -bli0 -cli4 -cbi0 -di5 -nbc -bls -ip2 -nut -ts4 -bap -i4 -sob -npsl
Diffstat (limited to 'src/map/magic.c')
-rw-r--r--src/map/magic.c204
1 files changed, 105 insertions, 99 deletions
diff --git a/src/map/magic.c b/src/map/magic.c
index f70d9a6..8e9c80e 100644
--- a/src/map/magic.c
+++ b/src/map/magic.c
@@ -7,131 +7,137 @@
#undef DEBUG
-static char *
-magic_preprocess_message(character_t *character, char *start, char *end)
+static char *magic_preprocess_message (character_t * character, char *start,
+ char *end)
{
- if (character->state.shroud_active
- && character->state.shroud_disappears_on_talk)
- magic_unshroud(character);
-
- if (character->state.shroud_active
- && character->state.shroud_hides_name_talking) {
- int len = strlen(end);
- strcpy(start, "? ");
- memmove(start + 2, end, len + 1);
- return start + 4;
- } else
- return end + 2; /* step past blank */
+ if (character->state.shroud_active
+ && character->state.shroud_disappears_on_talk)
+ magic_unshroud (character);
+
+ if (character->state.shroud_active
+ && character->state.shroud_hides_name_talking)
+ {
+ int len = strlen (end);
+ strcpy (start, "? ");
+ memmove (start + 2, end, len + 1);
+ return start + 4;
+ }
+ else
+ return end + 2; /* step past blank */
}
#define ISBLANK(c) ((c) == ' ')
/* Returns a dynamically allocated copy of `src'.
* `*parameter' may point within that copy or be NULL. */
-static char *
-magic_tokenise(char *src, char **parameter)
+static char *magic_tokenise (char *src, char **parameter)
{
- char *retval = strdup(src);
- char *seeker = retval;
+ char *retval = strdup (src);
+ char *seeker = retval;
- while (*seeker && !ISBLANK(*seeker))
- ++seeker;
+ while (*seeker && !ISBLANK (*seeker))
+ ++seeker;
- if (!*seeker)
- *parameter = NULL;
- else {
- *seeker = 0; /* Terminate invocation */
- ++seeker;
+ if (!*seeker)
+ *parameter = NULL;
+ else
+ {
+ *seeker = 0; /* Terminate invocation */
+ ++seeker;
- while (ISBLANK (*seeker))
- ++seeker;
+ while (ISBLANK (*seeker))
+ ++seeker;
- *parameter = seeker;
- }
+ *parameter = seeker;
+ }
- return retval;
+ return retval;
}
-int
-magic_message(character_t *caster,
- char *spell_, size_t spell_len)
+int magic_message (character_t * caster, char *spell_, size_t spell_len)
{
- if (pc_isdead(caster))
- return 0;
-
- int power = caster->matk1;
- char *invocation_base = spell_ + 8;
- char *source_invocation = 1 + invocation_base + strlen(caster->status.name);
- spell_t *spell;
- char *parameter;
- char *spell_invocation;
-
- if (!source_invocation)
- return 0;
+ if (pc_isdead (caster))
+ return 0;
+
+ int power = caster->matk1;
+ char *invocation_base = spell_ + 8;
+ char *source_invocation =
+ 1 + invocation_base + strlen (caster->status.name);
+ spell_t *spell;
+ char *parameter;
+ char *spell_invocation;
+
+ if (!source_invocation)
+ return 0;
+
+ /* Pre-message filter in case some spell alters output */
+ source_invocation =
+ magic_preprocess_message (caster, invocation_base, source_invocation);
+
+ spell_invocation = magic_tokenise (source_invocation, &parameter);
+ parameter = parameter ? strdup (parameter) : strdup ("");
+
+ spell = magic_find_spell (spell_invocation);
+ free (spell_invocation);
+
+ if (spell)
+ {
+ int near_miss;
+ env_t *env =
+ spell_create_env (&magic_conf, spell, caster, power, parameter);
+ effect_set_t *effects;
+
+ if ((spell->flags & SPELL_FLAG_NONMAGIC) || (power >= 1))
+ effects = spell_trigger (spell, caster, env, &near_miss);
+ else
+ effects = NULL;
- /* Pre-message filter in case some spell alters output */
- source_invocation = magic_preprocess_message(caster, invocation_base, source_invocation);
+#ifdef DEBUG
+ fprintf (stderr, "Found spell `%s', triggered = %d\n", spell_,
+ effects != NULL);
+#endif
+ if (caster->status.option & OPTION_HIDE)
+ return 0; // No spellcasting while hidden
- spell_invocation = magic_tokenise(source_invocation, &parameter);
- parameter = parameter ? strdup(parameter) : strdup("");
+ MAP_LOG_PC (caster, "CAST %s %s",
+ spell->name, effects ? "SUCCESS" : "FAILURE");
- spell = magic_find_spell(spell_invocation);
- free(spell_invocation);
+ if (effects)
+ {
+ invocation_t *invocation = spell_instantiate (effects, env);
- if (spell) {
- int near_miss;
- env_t *env = spell_create_env(&magic_conf, spell, caster, power, parameter);
- effect_set_t *effects;
+ /* We have a proper spell effect-- obscure the invocation! */
+ while (*source_invocation)
+ {
+ if (((rand () * 100.0) / (RAND_MAX * 1.0)) <
+ magic_conf.obscure_chance)
+ *source_invocation = '*';
+ ++source_invocation;
+ }
- if ((spell->flags & SPELL_FLAG_NONMAGIC)
- || (power >= 1))
- effects = spell_trigger(spell, caster, env, &near_miss);
- else
- effects = NULL;
+ spell_bind (caster, invocation);
+ spell_execute (invocation);
-#ifdef DEBUG
- fprintf(stderr, "Found spell `%s', triggered = %d\n", spell_, effects != NULL);
-#endif
- if (caster->status.option & OPTION_HIDE)
- return 0; // No spellcasting while hidden
-
- MAP_LOG_PC(caster, "CAST %s %s",
- spell->name,
- effects? "SUCCESS" : "FAILURE");
-
- if (effects) {
- invocation_t *invocation = spell_instantiate(effects, env);
-
- /* We have a proper spell effect-- obscure the invocation! */
- while (*source_invocation) {
- if (((rand() * 100.0) / (RAND_MAX * 1.0)) < magic_conf.obscure_chance)
- *source_invocation = '*';
- ++source_invocation;
- }
-
- spell_bind(caster, invocation);
- spell_execute(invocation);
-
- return (spell->flags & SPELL_FLAG_SILENT)? -1 : 1;
- } else {
- magic_free_env(env);
-
- /* Obscure proper almost-triggered spell */
- if (near_miss)
- while (*source_invocation)
- *source_invocation++ = '.';
- }
- return 1;
+ return (spell->flags & SPELL_FLAG_SILENT) ? -1 : 1;
+ }
+ else
+ {
+ magic_free_env (env);
+
+ /* Obscure proper almost-triggered spell */
+ if (near_miss)
+ while (*source_invocation)
+ *source_invocation++ = '.';
}
+ return 1;
+ }
- return 0; /* Not a spell */
+ return 0; /* Not a spell */
}
-int
-magic_init(char *conffile); // must be called after itemdb initialisation
+int magic_init (char *conffile); // must be called after itemdb initialisation
-void
-do_init_magic()
+void do_init_magic ()
{
- magic_init(MAGIC_CONFIG_FILE);
+ magic_init (MAGIC_CONFIG_FILE);
}