|
|
1 | |
1 | /* |
2 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
3 | |
4 | |
|
|
5 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
7 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
8 | |
7 | This program is free software; you can redistribute it and/or modify |
9 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
10 | it under the terms of the GNU General Public License as published by |
… | |
… | |
36 | int |
38 | int |
37 | main (int argc, char *argv[]) |
39 | main (int argc, char *argv[]) |
38 | { |
40 | { |
39 | char InFileName[1024], OutFileName[1024]; |
41 | char InFileName[1024], OutFileName[1024]; |
40 | maptile *newMap; |
42 | maptile *newMap; |
41 | RMParms rp; |
43 | random_map_params rp; |
42 | FILE *fp; |
44 | FILE *fp; |
43 | |
45 | |
44 | if (argc < 3) |
46 | if (argc < 3) |
45 | { |
47 | { |
46 | printf ("\nUsage: %s inputfile outputfile\n", argv[0]); |
48 | printf ("\nUsage: %s inputfile outputfile\n", argv[0]); |
… | |
… | |
55 | init_artifacts (); |
57 | init_artifacts (); |
56 | init_formulae (); |
58 | init_formulae (); |
57 | init_readable (); |
59 | init_readable (); |
58 | |
60 | |
59 | init_gods (); |
61 | init_gods (); |
60 | memset (&rp, 0, sizeof (RMParms)); |
62 | memset (&rp, 0, sizeof (random_map_params)); |
61 | rp.Xsize = -1; |
63 | rp.Xsize = -1; |
62 | rp.Ysize = -1; |
64 | rp.Ysize = -1; |
63 | if ((fp = fopen (InFileName, "r")) == NULL) |
65 | if ((fp = fopen (InFileName, "r")) == NULL) |
64 | { |
66 | { |
65 | fprintf (stderr, "\nError: can not open %s\n", InFileName); |
67 | fprintf (stderr, "\nError: can not open %s\n", InFileName); |
… | |
… | |
88 | object *tmp = NULL; |
90 | object *tmp = NULL; |
89 | int i; |
91 | int i; |
90 | |
92 | |
91 | switch (op->type) |
93 | switch (op->type) |
92 | { |
94 | { |
93 | case SHOP_FLOOR: |
95 | case SHOP_FLOOR: |
94 | if (!op->has_random_items ()) |
96 | if (!op->has_random_items ()) |
95 | return 0; |
97 | return 0; |
96 | do |
98 | do |
97 | { |
99 | { |
98 | i = 10; /* let's give it 10 tries */ |
100 | i = 10; /* let's give it 10 tries */ |
99 | while ((tmp = generate_treasure (op->randomitems, op->stats.exp ? op->stats.exp : 5)) == NULL && --i); |
101 | while ((tmp = generate_treasure (op->randomitems, op->stats.exp ? op->stats.exp : 5)) == NULL && --i); |
100 | if (tmp == NULL) |
102 | if (tmp == NULL) |
101 | return 0; |
103 | return 0; |
102 | if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) |
104 | if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) |
103 | { |
105 | { |
104 | tmp->destroy (); |
106 | tmp->destroy (); |
105 | tmp = NULL; |
107 | tmp = NULL; |
106 | } |
108 | } |
107 | } |
109 | } |
108 | while (!tmp); |
110 | while (!tmp); |
109 | |
111 | |
110 | tmp->x = op->x, tmp->y = op->y; |
112 | tmp->x = op->x, tmp->y = op->y; |
111 | SET_FLAG (tmp, FLAG_UNPAID); |
113 | SET_FLAG (tmp, FLAG_UNPAID); |
112 | insert_ob_in_map (tmp, op->map, NULL, 0); |
114 | insert_ob_in_map (tmp, op->map, NULL, 0); |
113 | CLEAR_FLAG (op, FLAG_AUTO_APPLY); |
115 | CLEAR_FLAG (op, FLAG_AUTO_APPLY); |
114 | identify (tmp); |
116 | identify (tmp); |
115 | break; |
117 | break; |
116 | |
118 | |
117 | case TREASURE: |
119 | case TREASURE: |
118 | if (op->has_random_items ()) |
120 | if (op->has_random_items ()) |
119 | while ((op->stats.hp--) > 0) |
121 | while ((op->stats.hp--) > 0) |
120 | create_treasure (op->randomitems, op, GT_ENVIRONMENT, |
122 | create_treasure (op->randomitems, op, GT_ENVIRONMENT, |
121 | op->stats.exp ? op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); |
123 | op->stats.exp ? op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); |
122 | op->remove (); |
124 | op->remove (); |
123 | op->destroy (); |
125 | op->destroy (); |
124 | break; |
126 | break; |
125 | } |
127 | } |
126 | |
128 | |
127 | return tmp ? 1 : 0; |
129 | return tmp ? 1 : 0; |
128 | } |
130 | } |
129 | |
131 | |
… | |
… | |
137 | fix_auto_apply (maptile *m) |
139 | fix_auto_apply (maptile *m) |
138 | { |
140 | { |
139 | object *tmp, *above = NULL; |
141 | object *tmp, *above = NULL; |
140 | int x, y; |
142 | int x, y; |
141 | |
143 | |
142 | for (x = 0; x < MAP_WIDTH (m); x++) |
144 | for (x = 0; x < m->width; x++) |
143 | for (y = 0; y < MAP_HEIGHT (m); y++) |
145 | for (y = 0; y < m->height; y++) |
144 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) |
146 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) |
145 | { |
147 | { |
146 | above = tmp->above; |
148 | above = tmp->above; |
147 | |
149 | |
148 | if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) |
150 | if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY)) |
149 | auto_apply (tmp); |
151 | auto_apply (tmp); |
… | |
… | |
163 | } |
165 | } |
164 | else if (tmp->has_random_items ()) |
166 | else if (tmp->has_random_items ()) |
165 | create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0); |
167 | create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0); |
166 | } |
168 | } |
167 | } |
169 | } |
168 | for (x = 0; x < MAP_WIDTH (m); x++) |
170 | for (x = 0; x < m->width; x++) |
169 | for (y = 0; y < MAP_HEIGHT (m); y++) |
171 | for (y = 0; y < m->height; y++) |
170 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
172 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
171 | if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) |
173 | if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) |
172 | check_trigger (tmp, tmp->above); |
174 | check_trigger (tmp, tmp->above); |
173 | } |
175 | } |
174 | |
176 | |
175 | /** |
177 | /** |