Ejemplo n.º 1
0
Archivo: zone.c Proyecto: velour/mid
void zoneput(Zone *zn, int znum)
{
	ignframetime();
	if (!ensuredir(zonedir))
		die("Failed to make zone directory: %s", miderrstr());
	
	char *zfile = zonefile(znum);
	FILE *f = fopen(zfile, "w");
	if (!f)
		die("Failed to open zone file for writing [%s]: %s", zfile, miderrstr());

	zonewrite(f, zn);
	fclose(f);
}
Ejemplo n.º 2
0
Archivo: zone.c Proyecto: velour/mid
Zone *zoneget(int znum)
{
	ignframetime();

	char *zfile = zonefile(znum);
	FILE *f = fopen(zfile, "r");
	if (!f)
		die("Unable to open the zone file [%s]: %s", zfile, miderrstr());

	Zone *zn = zoneread(f);
	if (!zn)
		die("Failed to read the zone file [%s]: %s", zfile, miderrstr());

	fclose(f);
	return zn;
}
Ejemplo n.º 3
0
Archivo: zone.c Proyecto: velour/mid
void zonecleanup(int zmax)
{
	for (int i = 0; i <= zmax; i++) {
		char *zfile = zonefile(i);
		if (!fsexists(zfile))
			continue;
		if (unlink(zfile) < 0)
			pr("Failed to remove zone file [%s]: %s", zfile, miderrstr());
	}
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	int *ids;

	loginit(NULL);

	Rng r;
	int usdargs = rng(&r, argc, argv);
	argc -= usdargs;
	argv += usdargs;

	int n = idargs(argc, argv, &ids);

	if (argc < 3)
		fatal("usage: enmgen [-s <seed>] <ID>+ <num>");

	long num = strtol(argv[argc-1], NULL, 10);
	if (num == LLONG_MIN || num == LLONG_MAX)
			fatal("Invalid number: %s", argv[argc-1]);

	Zone *zn = zoneread(stdin);
	if (!zn)
		die("Failed to read the zone: %s", miderrstr());

	Loc ls[zn->lvl->d * zn->lvl->w * zn->lvl->h];
	int nls = locs(zn, ls);

	int i;
	for (i = 0; i < num && nls > 0; i++) {
		int idind = rngintincl(&r, 0, n);
		int lind = rngintincl(&r, 0, nls);
		Loc l = ls[lind];
		if (nls > 1)
			ls[lind] = ls[nls-1];
		nls--;
		Enemy enm;
		if (!enemyinit(&enm, ids[idind], l.p.x, l.p.y))
			fatal("Failed to initialize enemy with ID: %d", ids[idind]);
		if (!zoneaddenemy(zn, l.z, enm)) {
			nls = rmz(ls, nls, l.z);
			num--;
		}
	}

	if (i < num)
		fatal("Failed to place all items");

	zonewrite(stdout, zn);
	zonefree(zn);
	xfree(ids);

	return 0;
}
Ejemplo n.º 5
0
Archivo: zone.c Proyecto: velour/mid
Zone *zonegen(Rng *r, int depth)
{
	ignframetime();
	FILE *fin = inzone;

	if (!fin)
		fin = zpipe(r, depth);
	Zone *z = zoneread(fin);
	if (!z)
		die("Failed to read the zone: %s", miderrstr());

	if (inzone) {
		fclose(fin);
		inzone = NULL;
	} else {
		int ret = pipeclose(fin);
		if (ret == -1)
			die("Zone gen pipeline exited with failure: %s", miderrstr());
	}

	return z;
}
Ejemplo n.º 6
0
Archivo: zone.c Proyecto: velour/mid
static FILE *zpipe(Rng *r, int depth)
{
	Pipe p = {};

	switch(depth){
	case 0:
		pipeadd(&p, "lvlgen", "25 25 3 -s %lu ", (unsigned long) rngint(r));
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemStatup);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d %d %d %d 50", (unsigned long) rngint(r),
			ItemCopper, ItemCopper, ItemCopper, ItemCopper, ItemCopper, 
			ItemSilver, ItemSilver,
			ItemGold
		);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d 5", (unsigned long) rngint(r),
			ItemHealth, ItemHealth, ItemHealth, ItemHealth,
			ItemCarrot
		);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d 1", (unsigned long) rngint(r),
			ItemBubble, ItemZap, ItemLead
		);
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemHamCan);
		pipeadd(&p, "envgen", "-s %lu %d 1", (unsigned long) rngint(r), EnvShrempty);
		pipeadd(&p, "envgen", "-s %lu %d %d %d 2", (unsigned long) rngint(r),
			EnvSwdStoneHp,
			EnvSwdStoneDex,
			EnvSwdStoneStr);
		pipeadd(&p, "envgen", "-s %lu %d %d %d %d 2", (unsigned long)rngint(r),
			EnvHelm0,
			EnvBody0,
			EnvGlove0,
			EnvBoot0);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d %d %d %d %d %d %d %d %d %d 50",
			(unsigned long) rngint(r),
			EnemyUnti, EnemyUnti, EnemyUnti,
			EnemyNous, EnemyNous, EnemyNous, EnemyNous,
			EnemyDa, EnemyDa, EnemyDa,
			EnemyThu,
			EnemyGrendu
		);
		break;
	case 1:
		pipeadd(&p, "lvlgen", "25 25 3 -s %lu ", (unsigned long) rngint(r));
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemStatup);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d %d %d %d 50", (unsigned long) rngint(r),
			ItemCopper, ItemCopper, ItemCopper, ItemCopper, 
			ItemSilver, ItemSilver, ItemSilver,
			ItemGold
		);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d 5", (unsigned long) rngint(r),
			ItemHealth, ItemHealth, ItemHealth,
			ItemCarrot, ItemCarrot
		);
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemHamCan);
		pipeadd(&p, "envgen", "-s %lu %d 1", (unsigned long) rngint(r), EnvShrempty);
		pipeadd(&p, "envgen", "-s %lu %d %d %d 2", (unsigned long) rngint(r),
			EnvSwdStoneHp,
			EnvSwdStoneDex,
			EnvSwdStoneStr);
		pipeadd(&p, "envgen", "-s %lu %d %d %d %d 2", (unsigned long)rngint(r),
			EnvHelm0,
			EnvBody0,
			EnvGlove0,
			EnvBoot0);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d %d %d %d %d %d %d %d %d %d 50",
			(unsigned long) rngint(r),
			EnemyUnti, EnemyUnti, EnemyUnti,
			EnemyNous, EnemyNous, EnemyNous,
			EnemyDa, EnemyDa, EnemyDa,
			EnemyThu, EnemyThu,
			EnemyGrendu
		);
		break;
	case 2:
		pipeadd(&p, "lvlgen", "25 25 3 -s %lu ", (unsigned long) rngint(r));
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemStatup);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d %d %d %d 50", (unsigned long) rngint(r),
			ItemCopper, ItemCopper, ItemCopper, 
			ItemSilver, ItemSilver, ItemSilver, ItemSilver,
			ItemGold
		);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d 5", (unsigned long) rngint(r),
			ItemHealth, ItemHealth,
			ItemCarrot, ItemCarrot, ItemCarrot
		);
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemHamCan);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d 1", (unsigned long) rngint(r),
			ItemBubble, ItemZap, ItemLead
		);
		pipeadd(&p, "envgen", "-s %lu %d 1", (unsigned long) rngint(r), EnvShrempty);
		pipeadd(&p, "envgen", "-s %lu %d %d %d 2", (unsigned long) rngint(r),
			EnvSwdStoneHp2,
			EnvSwdStoneDex2,
			EnvSwdStoneStr2);
		pipeadd(&p, "envgen", "-s %lu %d %d %d %d 2", (unsigned long)rngint(r),
			EnvHelm2,
			EnvBody2,
			EnvGlove2,
			EnvBoot2);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d %d %d %d %d %d %d %d %d %d 50",
			(unsigned long) rngint(r),
			EnemyUnti, EnemyUnti, EnemyUnti,
			EnemyNous, EnemyNous,
			EnemyDa, EnemyDa, EnemyDa,
			EnemyThu, EnemyThu,
			EnemyGrendu, EnemyGrendu
		);
		break;
	case 3:
		pipeadd(&p, "lvlgen", "30 30 3 -s %lu ", (unsigned long) rngint(r));
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemStatup);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d %d %d %d 50", (unsigned long) rngint(r),
			ItemCopper, 
			ItemSilver, ItemSilver, ItemSilver,
			ItemGold, ItemGold, ItemGold, ItemGold
		);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d 4", (unsigned long) rngint(r),
			ItemHealth, ItemHealth,
			ItemCarrot, ItemCarrot
		);
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemHamCan);
		pipeadd(&p, "envgen", "-s %lu %d 1", (unsigned long) rngint(r), EnvShrempty);
		pipeadd(&p, "envgen", "-s %lu %d %d %d 2", (unsigned long) rngint(r),
			EnvSwdStoneHp2,
			EnvSwdStoneDex2,
			EnvSwdStoneStr2);
		pipeadd(&p, "envgen", "-s %lu %d %d %d %d 2", (unsigned long)rngint(r),
			EnvHelm2,
			EnvBody2,
			EnvGlove2,
			EnvBoot2);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d %d %d %d %d %d %d %d %d %d 25",
			(unsigned long) rngint(r),
			EnemyUnti, EnemyUnti, EnemyUnti,
			EnemyNous, EnemyNous,
			EnemyDa, EnemyDa, EnemyDa,
			EnemyThu, EnemyThu,
			EnemyGrendu, EnemyGrendu
		);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d 25",
			(unsigned long) rngint(r),
			EnemyThu, EnemyThu,
			EnemyGrendu
		);
		break;
	case 4:
		pipeadd(&p, "lvlgen", "30 30 4 -s %lu ", (unsigned long) rngint(r));
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemStatup);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d %d %d %d 50", (unsigned long) rngint(r),
			ItemCopper, 
			ItemSilver, ItemSilver, ItemSilver,
			ItemGold, ItemGold, ItemGold, ItemGold
		);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d 2", (unsigned long) rngint(r),
			ItemHealth,
			ItemCarrot
		);
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemHamCan);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d 1", (unsigned long) rngint(r),
			ItemBubble, ItemZap, ItemLead
		);
		pipeadd(&p, "envgen", "-s %lu %d 1", (unsigned long) rngint(r), EnvShrempty);
		pipeadd(&p, "envgen", "-s %lu %d %d %d 2", (unsigned long) rngint(r),
			EnvSwdStoneHp3,
			EnvSwdStoneDex3,
			EnvSwdStoneStr3);
		pipeadd(&p, "envgen", "-s %lu %d %d %d %d 2", (unsigned long)rngint(r),
			EnvHelm4,
			EnvBody4,
			EnvGlove4,
			EnvBoot4);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d %d %d %d %d %d %d %d %d %d 20",
			(unsigned long) rngint(r),
			EnemyUnti, EnemyUnti, EnemyUnti,
			EnemyNous, EnemyNous,
			EnemyDa, EnemyDa, EnemyDa,
			EnemyThu, EnemyThu,
			EnemyGrendu, EnemyGrendu
		);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d %d %d 30",
			(unsigned long) rngint(r),
			EnemyThu, EnemyThu,
			EnemyGrendu, EnemyGrendu,
			EnemyTihgt
		);
		break;
	default:
		pipeadd(&p, "lvlgen", "30 30 4 -x -s %lu ", (unsigned long) rngint(r));
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemStatup);
		pipeadd(&p, "itmgen", "-s %lu %d %d %d %d %d %d %d %d 50", (unsigned long) rngint(r),
			ItemSilver,
			ItemGold
		);
		pipeadd(&p, "itmgen", "-s %lu %d 1", (unsigned long) rngint(r), ItemHamCan);
		pipeadd(&p, "envgen", "-s %lu %d 1", (unsigned long) rngint(r), EnvShrempty);
		pipeadd(&p, "envgen", "-s %lu %d %d %d 2", (unsigned long) rngint(r),
			EnvSwdStoneHp3,
			EnvSwdStoneDex3,
			EnvSwdStoneStr3);
		pipeadd(&p, "envgen", "-s %lu %d %d %d %d 2", (unsigned long)rngint(r),
			EnvHelm4,
			EnvBody4,
			EnvGlove4,
			EnvBoot4);
		pipeadd(&p, "enmgen", "-s %lu %d %d %d %d %d %d %d %d %d %d %d %d 20",
			(unsigned long) rngint(r),
			EnemyUnti, EnemyUnti, EnemyUnti,
			EnemyNous, EnemyNous,
			EnemyDa, EnemyDa, EnemyDa,
			EnemyThu, EnemyThu,
			EnemyGrendu, EnemyGrendu
		);
		pipeadd(&p, "enmgen", "-s %lu %d 15",
			(unsigned long) rngint(r),
			EnemyTihgt
		);
		pipeadd(&p, "enmgen", "-s %lu %d 1",
			(unsigned long) rngint(r),
			EnemyHeart
		);
		break;
	}

	char adc[256];
	if(snprintf(adc, sizeof(adc), "\"%s/cur.lvl\"", zonedir) == -1)
		die("Failed to create cur.lvl path: %s", miderrstr());
	pipeadd(&p, "tee", adc);

	p.cmd[p.n - 3] = 0;

	pr("lvlgen pipeline: [%s]", p.cmd);

	FILE *fin = piperead(p.cmd);
	if (!fin)
		die("Unable to execute zone gen pipeline: %s", miderrstr());

	return fin;
}