OSDN Git Service

日本語版
[nazghul-jp/nazghul-jp.git] / src / effect.c
1 //
2 // nazghul - an old-school RPG engine
3 // Copyright (C) 2004 Gordon McNutt
4 //
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 2 of the License, or (at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 // more details.
14 //
15 // You should have received a copy of the GNU General Public License along with
16 // this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 // Suite 330, Boston, MA 02111-1307 USA
18 //
19 // Gordon McNutt
20 // gmcnutt@users.sourceforge.net
21 //
22
23 #include "effect.h"
24
25 #include <assert.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 const int EFFECT_ID = 0xeffec1;
30
31 struct effect *effect_new(char *tag, scheme *sc, pointer exec_proc,
32                           pointer apply_proc, pointer rm_proc,
33                           pointer restart,
34                           char *name)
35 {
36         struct effect *et;
37
38         et = (struct effect*)calloc(1, sizeof(*et));
39         assert(et);
40
41         et->ID = EFFECT_ID;
42
43         if (exec_proc) {
44                 et->exec = closure_new_ref(sc, exec_proc);
45         }
46
47         if (apply_proc) {
48                 et->apply = closure_new_ref(sc, apply_proc);
49         }
50
51         if (rm_proc) {
52                 et->rm = closure_new_ref(sc, rm_proc);
53         }
54
55         if (restart) {
56                 et->restart = closure_new_ref(sc, restart);
57         }
58
59         et->tag = strdup(tag);
60         assert(et->tag);
61
62         /* Effects with no name should be considered invisible to the UI */
63         if (name) {
64                 et->name = strdup(name);
65                 assert(et->name);
66         }
67
68         return et;
69 }
70
71 extern void effect_del(struct effect *et)
72 {
73         free(et->tag);
74         free(et->name);
75         closure_unref_safe(et->exec);
76         closure_unref_safe(et->apply);
77         closure_unref_safe(et->rm);
78         closure_unref_safe(et->restart);
79         /* Need to free sprite? Nope -- sprites are global resources
80          * managed by the session. When the session is torn down it frees all
81          * of the sprites created when it loaded. */
82         free(et);
83 }