Registry: use BITS everywhere
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / all.qh
1 #ifndef TURRETS_ALL_H
2 #define TURRETS_ALL_H
3
4 #include "../command/all.qh"
5 #include "config.qh"
6
7 #include "turret.qh"
8
9 REGISTRY(Turrets, BITS(5))
10 REGISTER_REGISTRY(RegisterTurrets)
11
12
13 GENERIC_COMMAND(dumpturrets, "Dump all turrets into turrets_dump.txt")
14 {
15     switch(request)
16     {
17         case CMD_REQUEST_COMMAND:
18         {
19             #ifdef SVQC
20             tur_config_file = -1;
21             tur_config_alsoprint = -1;
22             string filename = argv(1);
23
24             if(filename == "")
25             {
26                 filename = "turrets_dump.cfg";
27                 tur_config_alsoprint = FALSE;
28             }
29             else if(filename == "-")
30             {
31                 filename = "turrets_dump.cfg";
32                 tur_config_alsoprint = TRUE;
33             }
34             tur_config_file = fopen(filename, FILE_WRITE);
35
36             if(tur_config_file >= 0)
37             {
38                 Dump_Turret_Settings();
39                 LOG_INFO(sprintf("Dumping turrets... File located in ^2data/data/%s^7.\n", filename));
40                 fclose(tur_config_file);
41                 tur_config_file = -1;
42                 tur_config_alsoprint = -1;
43             }
44             else
45             {
46                 LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename));
47             }
48             #else
49             LOG_INFO(_("Turrets dump command only works with sv_cmd.\n"));
50             #endif
51             return;
52         }
53
54         default:
55         case CMD_REQUEST_USAGE:
56         {
57             LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpturrets [filename]"));
58             LOG_INFO("  Where 'filename' is the file to write (default is turrets_dump.cfg),\n");
59             LOG_INFO("  if supplied with '-' output to console as well as default,\n");
60             LOG_INFO("  if left blank, it will only write to default.\n");
61             return;
62         }
63     }
64 }
65
66
67 const int TUR_FIRST = 1;
68 #define TUR_LAST (Turrets_COUNT - 1)
69
70 #define REGISTER_TURRET(id, inst) REGISTER(RegisterTurrets, TUR, Turrets, id, m_id, inst)
71
72 REGISTER_TURRET(Null, NEW(Turret));
73
74 Turret get_turretinfo(int id)
75 {
76     if (id >= TUR_FIRST && id <= TUR_LAST) {
77         Turret t = Turrets[id];
78         if (t) return t;
79     }
80     return TUR_Null;
81 }
82
83 #include "all.inc"
84
85 #endif