Cube  Check-in [be136b699f]

Overview
Comment:Fix projectiles
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: be136b699f19297f19ff807c028ad6977fcf27d245ed99d8288f59e35d0be1bd
User & Date: js on 2025-03-20 10:52:08
Other Links: manifest | tags
Context
2025-03-20
11:03
Use enumerateObjectsUsingBlock: where appropriate check-in: fd4460c7b6 user: js tags: trunk
10:52
Fix projectiles check-in: be136b699f user: js tags: trunk
2025-03-16
10:11
Use one autorelease pool per frame check-in: 489124a92f user: js tags: trunk
Changes

Modified src/weapon.mm from [a4e8e0ad47] to [c14fa40d91].

143
144
145
146
147
148
149





150
151
152
153
154
155
156
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161







+
+
+
+
+








void
newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
    DynamicEntity *owner, int gun)
{
	for (size_t i = 0; i < MAXPROJ; i++) {
		Projectile *p = projs[i];

		if (p == nil) {
			p = [[Projectile alloc] init];
			projs[i] = p;
		}

		if (p.inuse)
			continue;

		p.inuse = true;
		p.o = from;
		p.to = to;
201
202
203
204
205
206
207

208
209
210
211
212
213
214

215
216

217
218

219

220
221

222
223
224




225
226
227
228


229
230
231


232
233

234
235

236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

228


229



230
231
232
233
234



235
236



237
238


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259







+







+


+


+
-
+
-
-
+
-
-
-
+
+
+
+

-
-
-
+
+
-
-
-
+
+
-
-
+


+









+








void
splash(Projectile *p, const OFVector3D &v, const OFVector3D &vold,
    int notthisplayer, int notthismonster, int qdam)
{
	particle_splash(0, 50, 300, v);
	p.inuse = false;

	if (p.gun != GUN_RL) {
		playsound(S_FEXPLODE, &v);
		// no push?
	} else {
		playsound(S_RLHIT, &v);
		newsphere(v, RL_RADIUS, 0);
		dodynlight(vold, v, 0, 0, p.owner);

		if (!p.local)
			return;

		radialeffect(player1, v, -1, qdam, p.owner);

		[players enumerateObjectsUsingBlock:^(
		size_t i = 0;
		    id player, size_t i, bool *stop) {
		for (id player in players) {
			if (i == notthisplayer) {
			if (i == notthisplayer)
				i++;
				continue;
			}
				return;

			if (player == [OFNull null])
				return;

			if (player != [OFNull null])
				radialeffect(player, v, i, qdam, p.owner);

			radialeffect(player, v, i, qdam, p.owner);
		}];
			i++;
		}


		[getmonsters() enumerateObjectsUsingBlock:^(
		i = 0;
		for (DynamicEntity *monster in getmonsters())
		    DynamicEntity *monster, size_t i, bool *stop) {
			if (i != notthismonster)
				radialeffect(monster, v, i, qdam, p.owner);
		}];
	}
}

inline void
projdamage(
    DynamicEntity *o, Projectile *p, OFVector3D &v, int i, int im, int qdam)
{
	if (o.state != CS_ALIVE)
		return;

	if (intersect(o, p.o, v)) {
		splash(p, v, p.o, i, im, qdam);
		hit(i, qdam, o, p.owner);
	}
}

void
261
262
263
264
265
266
267
268

269

270
271
272
273
274
275
276
269
270
271
272
273
274
275

276

277
278
279
280
281
282
283
284







-
+
-
+







		if (p.owner.monsterstate)
			qdam /= MONSTERDAMAGEFACTOR;
		vdist(dist, v, p.o, p.to);
		float dtime = dist * 1000 / p.speed;
		if (time > dtime)
			dtime = time;
		vmul(v, time / dtime);
		vadd(v, p.o) if (p.local)
		vadd(v, p.o);
		{
		if (p.local) {
			for (id player in players)
				if (player != [OFNull null])
					projdamage(player, p, v, i, -1, qdam);

			if (p.owner != player1)
				projdamage(player1, p, v, -1, -1, qdam);