ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_range.C
Revision: 1.49
Committed: Sat Apr 23 04:56:55 2011 UTC (13 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.48: +1 -1 lines
Log Message:
update copyright to 2011

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.29 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.27 *
4 root 1.49 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.42 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 root 1.27 *
8 root 1.39 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 root 1.27 *
13 root 1.28 * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17 root 1.27 *
18 root 1.39 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.27 *
22 root 1.29 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.15 */
24 elmex 1.1
25     /* This file deals with range related commands (casting, shooting,
26     * throwing, etc.
27     */
28    
29     #include <global.h>
30 root 1.13 #include <sproto.h>
31 elmex 1.1 #include <spells.h>
32     #include <skills.h>
33    
34     /* Shows all spells that op knows. If params is supplied, the must match
35     * that. Given there is more than one skill, we can't supply break
36     * them down to cleric/wizardry.
37     */
38 root 1.5 static void
39     show_matching_spells (object *op, char *params)
40 elmex 1.1 {
41 root 1.5 object *spell;
42     char spell_sort[NROFREALSPELLS][MAX_BUF], tmp[MAX_BUF], *cp;
43     int num_found = 0, i;
44    
45     /* We go and see what spells the player has. We put them
46     * into the spell_sort array so that we can sort them -
47     * we prefix the skill in the name so that the sorting
48     * works better.
49     */
50 root 1.19 for (spell = op->inv; spell; spell = spell->below)
51 root 1.5 {
52     /* If it is a spell, and no params are passed, or they
53     * match the name, process this spell.
54     */
55     if (spell->type == SPELL && (!params || !strncmp (params, spell->name, strlen (params))))
56     {
57     if (spell->path_attuned & op->path_denied)
58     {
59     sprintf (spell_sort[num_found++], "%s:%-22s %3s %3s", spell->skill ? &spell->skill : "generic", &spell->name, "den", "den");
60     }
61     else
62     {
63     sprintf (spell_sort[num_found++],
64     "%s:%-22s %3d %3d", spell->skill ? &spell->skill : "generic",
65     &spell->name, spell->level, SP_level_spellpoint_cost (op, spell, SPELL_HIGHEST));
66 root 1.2 }
67     }
68 elmex 1.1 }
69 root 1.19
70 root 1.5 if (!num_found)
71     {
72     /* If a matching string was passed along, now try it without that
73     * string. It is odd to do something like 'cast trans',
74     * and it say you have no spells, when really, you do, but just
75     * nothing that matches.
76     */
77     if (params)
78     show_matching_spells (op, NULL);
79     else
80     new_draw_info (NDI_UNIQUE, 0, op, "You know no spells");
81     }
82     else
83     {
84     /* Note in the code below that we make some
85     * presumptions that there will be a colon in the
86     * string. given the code above, this is always
87     * the case.
88     */
89 root 1.16 qsort (spell_sort, num_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp);
90 root 1.5 strcpy (tmp, "asdfg"); /* Dummy string so initial compare fails */
91     for (i = 0; i < num_found; i++)
92     {
93     /* Different skill name, so print banner */
94     if (strncmp (tmp, spell_sort[i], strlen (tmp)))
95     {
96     strcpy (tmp, spell_sort[i]);
97     cp = strchr (tmp, ':');
98     *cp = '\0';
99     new_draw_info (NDI_UNIQUE, 0, op, "");
100     new_draw_info_format (NDI_UNIQUE, 0, op, "%s spells %.*s [lvl] [sp]", tmp, 12 - strlen (tmp), " ");
101 root 1.2 }
102 root 1.5 new_draw_info (NDI_UNIQUE, 0, op, strchr (spell_sort[i], ':') + 1);
103 root 1.2 }
104 elmex 1.1 }
105     }
106    
107     /* sets up to cast a spell. op is the caster, params is the spell name,
108     * and command is the first letter of the spell type (c=cast, i=invoke,
109     * p=prepare). Invoke casts a spell immediately, where as cast (and I believe
110     * prepare) just set up the range type.
111     */
112 root 1.41 static int
113 root 1.5 command_cast_spell (object *op, char *params, char command)
114 elmex 1.1 {
115 root 1.5 int castnow = 0;
116     char *cp;
117     object *spob;
118    
119     if (command == 'i')
120     castnow = 1;
121    
122     /* Remove control of the golem */
123 root 1.20 if (object *golem = op->contr->golem)
124 root 1.38 golem->drop_and_destroy ();
125 elmex 1.1
126 root 1.18 if (params)
127 root 1.5 {
128     int spellnumber = 0;
129    
130     if ((spellnumber = atoi (params)))
131 root 1.9 for (spob = op->inv; spob && spob->count != spellnumber; spob = spob->below)
132 root 1.6 /* nop */;
133 root 1.5 else
134     spob = lookup_spell_by_name (op, params);
135    
136     if (spob && spob->type == SPELL)
137     {
138     /* Now grab any extra data, if there is any. Forward pass
139     * any 'of' delimiter
140     */
141     if (spellnumber)
142     {
143     /* if we passed a number, the options start at the second word */
144     cp = strchr (params, ' ');
145     if (cp)
146     {
147     cp++;
148     if (!strncmp (cp, "of ", 3))
149     cp += 3;
150 root 1.2 }
151     }
152 root 1.20 else if (strlen (params) > strlen (spob->name))
153 root 1.5 {
154     cp = params + strlen (spob->name);
155     *cp = 0;
156     cp++;
157     if (!strncmp (cp, "of ", 3))
158     cp += 3;
159 root 1.2 }
160 root 1.5 else
161     cp = NULL;
162    
163     if (castnow)
164 root 1.6 cast_spell (op, op, op->facing, spob, cp);
165 root 1.44 else if (op->apply (spob))
166 root 1.5 {
167 root 1.44 splay (spob);
168     assign (op->contr->spellparam, cp ? cp : "");
169 root 1.2 }
170 root 1.6
171 root 1.5 return 0;
172     } /* else fall through to below and print spells */
173     } /* params supplied */
174    
175     /* We get here if cast was given without options or we could not find
176     * the requested spell. List all the spells the player knows.
177     */
178 root 1.22 new_draw_info (NDI_UNIQUE, 0, op, "Cast what spell? Choose one of:");
179 root 1.5 show_matching_spells (op, params);
180 root 1.22
181 root 1.5 return 1;
182 elmex 1.1 }
183    
184 root 1.40 int
185     command_invoke (object *op, char *params)
186     {
187     return command_cast_spell (op, params, 'i');
188     }
189    
190     int
191     command_cast (object *op, char *params)
192     {
193     return command_cast_spell (op, params, 'c');
194     }
195    
196     int
197     command_prepare (object *op, char *params)
198     {
199     return command_cast_spell (op, params, 'p');
200     }
201    
202 elmex 1.1 /**************************************************************************/
203    
204 root 1.45 int
205     command_rotateshoottype (object *op, char *params)
206 root 1.5 {
207 root 1.44 if (op->contr->combat_ob && op->contr->ranged_ob)
208 root 1.45 op->apply (
209 root 1.44 op->current_weapon == op->contr->combat_ob
210     ? op->contr->ranged_ob
211     : op->contr->combat_ob
212     );
213 root 1.23
214 root 1.20 //TODO: maybe switch to golem, if any?
215 root 1.19
216 elmex 1.1 return 0;
217     }
218 root 1.48