/*
*
* 3G-02 Laser Gun Design Aid v0.01a (Quick Hack #1)
* (c) 1991 TinCan SiftWare/Marc A. Volovic
*
* Warranty: This programme is guaranteed to take up disk space.
* If it does things to your life/computer/pet/spouse -
* Life Is A Bitch And Then She Bites You And Then You Die.
*
* Version 0.01a is hereby announced as FreeWare.
*
* This is being written in a tearing hurry - NO ERROR CHECKING IS
* PERFORMED BY THE PROGRAMME. It will gladly produce 0j guns or
* superconductor loops with negative weight. Take notice!
*
* There are no modifications for weapon kind (i.e. pistol or rifle)
* or cost options (weight decrease/increase for cost changes).
*
* Projected changes and additions:
*
* 1. IMPORTANT: Code modularization in preparation for (2).
* 2. Particle Beam Design Section
* 3. Implement proper rounding functions.
*
* Note: Prerequisite to Sections 3 through 6: Find out volume of a given
* round on a diameter/ratio via formula.
*
* 4. Gauss Design Section
* 5. Conventional Round Design Section
* 6. Conventional Weapon Design Section
* 7. Rocket/Missile Section
*
*
* In order to maintain consistency I have used the following terms:
*
* Beam Energy - actual energy for damage calculation purposes
* Input Energy - energy required by the lasing tube to produce a beam
* Storage Energy - energy required to replenish one unit of input energy
* (at the moment - unused)
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "dtypes.h"
#define INTERNAL 1
#define EXTERNAL 2
#define PI 3.1415927
int RANGE_CLASS[8] = { 0, 10, 20, 40, 80, 150, 300, 600 };
int WEIGHT_CLASS[3] = {500, 4000, 32000 };
dword INIT_CLASS[8] = {500, 1000, 3000, 10000, 20000, 40000, 80000,
160000};
char *WEIGHT_TYPE[] = { "VS", "S", "M", "L" };
char *cvtfs(double val, int len)
{
int size, decp, sign;
static char ret[BUFSIZ];
char *cp;
char *ap;
int c1;
size = len;
/* Initial Translate */
cp = ecvt(val, size, &decp, &sign);
ap = ret;
if (sign)
*ap++ = '-';
for (c1 = decp; c1--;)
*ap++ = *cp++;
if (len > decp) {
*ap++ = '.';
for (c1 = len - decp; c1--;)
*ap++ = *cp++;
}
*ap = '\0';
return(ret);
}
main()
{
dword b_energy; /* Beam Energy */
dword i_energy; /* Input Energy */
dword s_energy; /* Storage Energy */
int init; /* Initiative */
byte action; /* Action */
byte ins[2]; /* Input */
byte tl; /* Tech Level */
byte clip; /* Internal/External Clip */
byte clip_type; /* Clip Type */
byte fold_factor; /* Tube Factor Folding */
byte aim_rc; /* Aim Range Class */
byte damage_rc; /* Damage Range Class */
byte location; /* Number Of Locations */
byte divisor = 7; /* BP divisor */
word c_shots; /* Shots/Clip */
double dv; /* Damage Value */
double c_weight; /* Weight Of Clip */
double total; /* Total Weight */
double s_weight; /* Storage Weight */
double accessory; /* Accessory Weight */
double diameter; /* Beam Diameter */
double eff; /* Conversion Efficiency */
double weight; /* Weapon Weight */
double length; /* Weapon Length */
double tube_length; /* Lasing Tube Length */
double av; /* Armour Value */
double bp; /* Body Points */
double bulk; /* Bulk */
double loc_weight; /* Location Weight */
double ia; /* Inherent Accuracy */
double base_cost; /* Basic Cost */
double t1, t2, t3, t4; /* Temporary storage */
char clip_str[7]; /* Clip String Display */
char act_str[12]; /* Action String Display */
char buf[BUFSIZ]; /* Display Buffer */
char bulk_str[5]; /* Bulk String Display */
printf("\n3G Laser Weapon Design Aid v0.01\n");
printf("TL: ");
scanf("%u", &tl);
printf("Required Beam Energy: ");
scanf("%U", &b_energy);
t1 = sqrt(pow(b_energy, 0.9)/(PI * 10000)) * 20;
diameter = (t1 > 5) ? t1 : 5;
modf(modf(diameter, &t1) * 10, &t2);
switch (t2) {
case 0 :
case 1 :
case 2 :
t2 = 0;
break;
case 3 :
case 4 :
case 5 :
case 6 :
case 7 :
t2 = 5;
break;
case 8 :
case 9 :
t2 = 0;
++t1;
break;
}
diameter = t1 + t2 / 10;
dv = sqrt((b_energy * 0.735) / (diameter / 10));
eff = 1 / ((tl-7) * 0.05);
i_energy = b_energy * eff;
s_energy = i_energy * eff;
t1 = (double)i_energy / ((tl - 7) * 0.4);
if (tl > 12) {
t2 = (double)i_energy / ((tl - 12) * 125);
t3 = (double)i_energy / (((tl - 7) / 2) * (tl - 8) * 100)
+ 100;
}
printf("Energy Storage:\n 1) Capacitors (%.2fg/shot)\n",
t1);
if (tl > 12) {
printf(" 2) Superconductor loops (%.2fg/shot)\n", t2);
printf(" 3) Direct Battery Link (%.2fg/shot)\n", t3);
}
printf("Select: ");
scanf("%u", &clip_type);
switch (clip_type)
{
case 1 :
s_weight = t1;
break;
case 2 :
s_weight = t2;
break;
case 3 :
s_weight = t3;
break;
default :
fputs("Error!", stdout);
exit(1);
} /* esac */
printf("Shots: ");
scanf("%u", &c_shots);
c_weight = c_shots * s_weight;
printf("Internal? ");
scanf("%1s", &ins);
if (!strcmp(ins, "y")) {
clip = INTERNAL;
c_weight *= 1.1;
} else {
clip = EXTERNAL;
c_weight *= 1.2;
}
/* Temporary Weight */
t1 = sqrt(b_energy) * (200 / (tl - 7));
/* Temporary Length */
t2 = pow((t1 / 3), 0.8) / (sqrt(diameter * .2) * PI);
printf("Temporary Weight: %.3f Temporary Length: %3f\n",
t1, t2);
printf("Folding Factor: ");
scanf("%u", &fold_factor);
length = t2 / (fold_factor + 1);
tube_length = t2;
weight = t1 * (1 + fold_factor / 10);
if (clip == INTERNAL)
accessory = (weight + c_weight) * 0.2;
else
accessory = weight * 0.2;
total = weight + accessory + c_weight;
for (aim_rc = 0; aim_rc < 8; aim_rc++) {
if (length < RANGE_CLASS[aim_rc])
break;
}
for (damage_rc = 0; damage_rc++ < 8; )
if (tube_length < RANGE_CLASS[damage_rc])
break;
if (modf((length / 15), &bulk))
++bulk;
loc_weight = total / bulk;
for (t1 = 0; t1 < 4; divisor--, t1++)
if (loc_weight < WEIGHT_CLASS[t1])
break;
strcpy(bulk_str, WEIGHT_TYPE[t1]);
strcat(bulk_str, "/");
strcpy(buf, cvtfs(bulk, 1));
strcat(bulk_str, buf);
for(t1 = 0; t1 < 9; t1++)
if ((loc_weight * pow(bulk, 2)) < INIT_CLASS[t1])
break;
init = 4 - t1;
total /= 1000; /* Translate to kg */
c_weight /= 1000; /* Translate to kg */
/* Assign minimum clip weight - 10g seems light enough */
if (c_weight < 0.01)
c_weight = 0.01;
bp = (float)(20 - tl) / divisor;
av = pow(b_energy, 0.15)*((20 - tl) / 5);
ia = aim_rc / 2;
base_cost = pow(dv, 2) / 3 + 300;
printf("\n\nBase Cost: Cr%.1f\n", base_cost);
printf("\nActions:\n 1) SA 2) AT 3) AB\n 4) SA/AT");
printf(" 5) SA/AB 6) SA/AT/AB\n");
printf("Select: ");
scanf("%1u", &action);
switch (action) {
case 1 : strcpy(act_str, "SA"); /* SA */
break;
case 2 : strcpy(act_str, "AT"); /* AT */
break;
case 3 : base_cost *= 1.5; /* AB */
strcpy(act_str, "AB");
break;
case 4 : base_cost *= 1.3; /* SA/AT */
strcpy(act_str, "SA/AT");
break;
case 5 : base_cost *= 1.5; /* SA/AB */
strcpy(act_str, "SA/AB");
break;
case 6 : base_cost *= 1.95; /* SA/AT/AB */
strcpy(act_str, "SA/AT/AB");
break;
default : printf("Error!");
break;
}
sprintf(clip_str, "%3u", c_shots);
if (clip == INTERNAL)
strcat(clip_str, "/I");
else
strcat(clip_str, "/E");
printf("*** UNIMPLEMENTED ***");
printf("\nOptions:\n 1) Continuous Fire\n 2) Stunner\n");
printf(" 3) Adjustable\n");
printf("*** UNIMPLEMENTED ***");
/* Disgusting, rewrite somehow */
printf("\n------------------------ START ------------------------\n");
ultoa(b_energy, buf, 10);
printf("TL%u %sj Laser Weapon\n", tl, buf);
printf(" Cal RC DV IA In Mass Bulk Cost Clip");
printf(" Action ROF C-Mass AV BP\n");
printf("%4.1f %1u/%1u %3.0f %+2.0f %+2d %6.2f %4s %8.1f", diameter,
aim_rc, damage_rc, dv, ia, init, total, bulk_str, base_cost);
printf(" %-5s %-9s xx %5.2f %2.0f %2.0f", clip_str, act_str,
c_weight, av, bp);
printf("\n------------------------- END -------------------------\n");
}