1 /*
2 	C-Dogs SDL
3 	A port of the legendary (and fun) action/arcade cdogs.
4 	Copyright (c) 2015-2016, 2018, 2020-2021 Cong Xu
5 	All rights reserved.
6 
7 	Redistribution and use in source and binary forms, with or without
8 	modification, are permitted provided that the following conditions are met:
9 
10 	Redistributions of source code must retain the above copyright notice, this
11 	list of conditions and the following disclaimer.
12 	Redistributions in binary form must reproduce the above copyright notice,
13 	this list of conditions and the following disclaimer in the documentation
14 	and/or other materials provided with the distribution.
15 
16 	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 	POSSIBILITY OF SUCH DAMAGE.
27 */
28 #pragma once
29 
30 #include <json/json.h>
31 
32 #include "ammo.h"
33 #include "utils.h"
34 #include "weapon.h"
35 
36 // Effects for "pick up" objects
37 typedef enum
38 {
39 	PICKUP_NONE,
40 	PICKUP_JEWEL,
41 	PICKUP_HEALTH,
42 	PICKUP_AMMO,
43 	PICKUP_KEYCARD,
44 	PICKUP_GUN,
45 	PICKUP_SHOW_MAP
46 } PickupType;
47 PickupType StrPickupType(const char *s);
48 const char *PickupTypeStr(const PickupType pt);
49 
50 typedef struct
51 {
52 	char *Name;
53 	PickupType Type;
54 	union {
55 		int Score;
56 		int Health;
57 		NAmmo Ammo;
58 		int Keys; // Refer to flags in mission.h
59 		int GunId;
60 	} u;
61 	CPic Pic;
62 	char *Sound;
63 } PickupClass;
64 typedef struct
65 {
66 	CArray Classes;		  // of PickupClass
67 	CArray CustomClasses; // of PickupClass
68 	CArray KeyClasses;	  // of PickupClass
69 } PickupClasses;
70 extern PickupClasses gPickupClasses;
71 
72 PickupClass *StrPickupClass(const char *s);
73 // Legacy pickup classes, integer based
74 PickupClass *IntPickupClass(const int i);
75 // Legacy exit styles, integer based
76 const char *IntExitStyle(const int i);
77 // Legacy key classes, style+integer based
78 const char *IntKeyStyle(const int style);
79 PickupClass *IntKeyPickupClass(const int style, const int i);
80 // Semi-legacy key classes, style+integer colour
81 PickupClass *KeyPickupClass(const char *style, const int i);
82 PickupClass *PickupClassGetById(PickupClasses *classes, const int id);
83 int StrPickupClassId(const char *s);
84 
85 void PickupClassesInit(
86 	PickupClasses *classes, const char *filename, const AmmoClasses *ammo,
87 	const WeaponClasses *guns);
88 void PickupClassesLoadJSON(CArray *classes, json_t *root);
89 void PickupClassesLoadAmmo(CArray *classes, const CArray *ammoClasses);
90 void PickupClassesLoadGuns(CArray *classes, const CArray *gunClasses);
91 void PickupClassesLoadKeys(CArray *classes);
92 void PickupClassesClear(CArray *classes);
93 void PickupClassesTerminate(PickupClasses *classes);
94 int PickupClassesCount(const PickupClasses *classes);
95 
96 int PickupClassesGetScoreIdx(const PickupClass *p);
97 // Count the number of "Score" type pickups
98 int PickupClassesGetScoreCount(const PickupClasses *classes);
99 // Get the ith "Score" type pickup
100 PickupClass *IntScorePickupClass(const int i);
101 
102 // Score for picking up an objective
103 #define PICKUP_SCORE 10
104