2 Copyright (C) 2004 Parallel Realities
3 Copyright (C) 2007 Kővágó Zoltán
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "gettext.hpp"
24 #include "console/console.hpp"
27 * Loads all the predefined weapons for the game
31 if (!engine
.loadData("data/weapons"))
33 graphics
.showErrorAndExit(_("Couldn't load weapon definitions file (%s)"), "data/weapons");
36 char *token
= strtok((char*)engine
.dataBuffer
, "\n");
46 if (strcmp(token
, "@EOF@") == 0)
49 sscanf(token
, "%d %*c %[^\"] %*c %d %d %d %d %d %d %s %s %d %s", &id
, name
, ¶m
[0], ¶m
[1], ¶m
[2], ¶m
[3], ¶m
[4], ¶m
[5], sprite
[0], sprite
[1], ¶m
[6], flags
);
51 weapon
[id
].setName(name
);
52 weapon
[id
].id
= param
[0];
53 weapon
[id
].damage
= param
[1];
54 weapon
[id
].health
= param
[2];
55 weapon
[id
].dx
= param
[3];
56 weapon
[id
].dy
= param
[4];
57 weapon
[id
].reload
= param
[5];
58 weapon
[id
].sprite
[0] = graphics
.getSprite(sprite
[0], true);
59 weapon
[id
].sprite
[1] = graphics
.getSprite(sprite
[1], true);
60 weapon
[id
].fireSound
= param
[6];
61 weapon
[id
].flags
= engine
.getValueOfFlagTokens(flags
);
63 token
= strtok(NULL
, "\n");
68 * Chooses a random non aimed weapon. Selected either WP_MACHINEGUN, WP_ALIENLASER
69 * WP_PLASMARIFLE or WP_ALIENGRENADE
70 * @return The randomly selected Weapon
72 Weapon
*getRandomStraightWeapon()
77 return &weapon
[WP_MACHINEGUN
];
80 return &weapon
[WP_ALIENLASER
];
83 return &weapon
[WP_PLASMARIFLE
];
86 return &weapon
[WP_ALIENGRENADE
];
90 return &weapon
[WP_PISTOL
];
94 * Chooses a random aimed weapon. Selected either WP_AIMEDPISTOL, WP_ALIENSPREAD
96 * @return The randomly selected Weapon
98 Weapon
*getRandomAimedWeapon()
103 return &weapon
[WP_AIMEDPISTOL
];
106 return &weapon
[WP_ALIENSPREAD
];
109 return &weapon
[WP_ALIENGRENADE
];
113 return &weapon
[WP_AIMEDPISTOL
];
117 * Chooses a random weapon for use by Galdov. Selects either WP_AIMEDPISTOL, WP_ALIENSPREAD
118 * WP_ALIENGRENADE or WP_PLASMARIFLE
119 * @return The randomly selected Weapon
121 Weapon
*getRandomGaldovWeapon()
126 return &weapon
[WP_AIMEDPISTOL
];
129 return &weapon
[WP_ALIENSPREAD
];
132 return &weapon
[WP_ALIENGRENADE
];
135 return &weapon
[WP_PLASMARIFLE
];
139 return &weapon
[WP_AIMEDPISTOL
];
143 * Searches the Weapon array for the named Weapon. Once it is found
144 * it is returned. If it is not found WP_PISTOL is returned
146 * @return The randomly selected Weapon
148 Weapon
*getWeaponByName(char *name
)
150 if (strcmp("randomStraight", name
) == 0)
152 return getRandomStraightWeapon();
155 if (strcmp("randomAimed", name
) == 0)
157 return getRandomAimedWeapon();
160 for (int i
= 0 ; i
< MAX_WEAPONS
; i
++)
162 if (strcmp(weapon
[i
].name
, name
) == 0)
168 debug
<< "WARNING - COULD NOT FIND WEAPON '" << name
<< "'" << std::endl
;
170 return &weapon
[WP_PISTOL
];