Esempio n. 1
0
int FailEval(char plr, int type, char *text, int val, int xtra)
{
    int FNote = 0, temp, k, ctr = 0;
    char PROBLEM = 0;
    struct Astros *crw;

    temp = 0; /* XXX check uninitialized */

    if (!(strncmp(Mev[STEP].E->Name, "DO", 2) == 0 && Mev[STEP].loc == 0x02)) {
        Mev[STEP].E->MisFail++;  // set failure for all but docking power on
    }

    Mev[STEP].StepInfo = 1003;
    FNote = 5; // Mission Failure

    if (Unm == 0) {
        Mev[STEP].trace = 0x7f;

        if (type == 12) {
            DestroyPad(plr, MPad + Mev[STEP].pad, 20, 0);
        }

        if (!AI[plr]) {
            FailureMode(plr, FNote, text);
        }

        //Special Case for PhotoRecon with Lunar Probe
        if (Mev[STEP].loc == 20 && mcc == 8) {
            Mev[STEP - 1].E->MisFail++;
        }

        return 0;
    }

    Mev[STEP].StepInfo = 0;

    switch (type) {

    case 0: // Failure has no effect on Mission
    case 20:   // don't want to test for crew experience
        FNote = 0;
        Mev[STEP].StepInfo = 50;

        if (Mev[STEP].fgoto == -1) {
            Mev[STEP].trace = 0x7F;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break;


    case 2:  // End of Mission Failure
        FNote = 5;
        Mev[STEP].StepInfo = 1000 + Mev[STEP].loc;
        Mev[STEP].trace = 0x7f;
        break;


    case 5:  // Stranded Step  (temp)
    case 3:  // Kill ALL Crew and END Mission
        FNote = 8;

        if (InSpace > 0 && MANNED[Mev[STEP].pad] == 0 && strncmp(Mev[STEP].E->ID, "M2", 2) == 0) {
            Mev[STEP].pad = other(Mev[STEP].pad); // for Kicker-C problems
            F_KillCrew(F_ALL, 0);
            Mev[STEP].pad = other(Mev[STEP].pad);
        } else {
            F_KillCrew(F_ALL, 0);
        }

        Mev[STEP].StepInfo = 4600 + Mev[STEP].loc;
        Mev[STEP].trace = 0x7F;
        break;

    case 4:  // Branch to Alternate Step
        FNote = 1;
        Mev[STEP].StepInfo = 1900 + Mev[STEP].loc;

        if (Mev[STEP].fgoto == -1) { // End of Mission Flag
            if (Mev[STEP].PComp > 0) {
                Mev[STEP].PComp = 4;
            }

            Mev[STEP].trace = 0x7F; // End of Mission Signal
            FNote = 5;
        } else if (Mev[STEP].fgoto != -2) { // Alternate Step is other num
            if (Mev[STEP].PComp > 0) {
                Mev[STEP].PComp = 4;
            }

            Mev[STEP].trace = Mev[STEP].fgoto;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break;

    case 6:   // Reduce Safety by VAL% temp
        FNote = 0;
        Mev[STEP].E->MisSaf -= abs(val);

        if (Mev[STEP].E->MisSaf <= 0) {
            Mev[STEP].E->MisSaf = 1;
        }

        Mev[STEP].StepInfo = 900 + Mev[STEP].loc;

        if (Mev[STEP].fgoto == -1 && Unm == 0) {
            Mev[STEP].trace = 0x7F;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break;

    case 7:   // Reduce Safety by VAL% perm
        FNote = 0;
        Mev[STEP].StepInfo = 1700 + Mev[STEP].loc;

        if (Mev[STEP].fgoto == -1) {
            Mev[STEP].trace = 0x7F;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break;

    case 9:  // Recheck Step
        FNote = 2;
        Mev[STEP].StepInfo = 9;
//         Mev[STEP].rnum=random(10000)+1;  // new failure roll
//         Mev[STEP].dice=random(100)+1;    // new die roll
        Mev[STEP].trace = STEP;          // redo step
        break;

    case 12:  // Subtract VAL% from Safety, repair Pad for XTRA (launch only)
        FNote = 5;
        Mev[STEP].E->MisSaf -= abs(val);

        if (Mev[STEP].E->MisSaf <= 0) {
            Mev[STEP].E->MisSaf = 1;
        }

        Mev[STEP].StepInfo = 1600 + Mev[STEP].loc;

        DestroyPad(plr, MPad + Mev[STEP].pad, abs(xtra), 0); // Destroy Pad

        Mev[STEP].trace = 0x7F; // signal end of mission
        break;

    case 13: // Kill Crew, repair Pad for VAL
        FNote = 8;
        F_KillCrew(F_ALL, 0);
        DestroyPad(plr, Mev[STEP].pad + MPad, (val == 0) ? abs(xtra) : abs(val), 0); // Destroy Pad
        Mev[STEP].StepInfo = 4500 + Mev[STEP].loc;
        Mev[STEP].trace = 0x7F;
        break;

    case 15:  // Give option to Scrub  1%->20% negative of part
        FNote = 3;
        Mev[STEP].E->MisSaf -= brandom(20) + 1;

        if (Mev[STEP].E->MisSaf <= 0) {
            Mev[STEP].E->MisSaf = 1;
        }

        Mev[STEP].StepInfo = 15;
        break;

    case 16: // VAL% injury,   XTRA% death
        FNote = 0;
        Mev[STEP].StepInfo = 1100 + Mev[STEP].loc;

        for (k = 0; k < MANNED[Mev[STEP].pad]; k++) {
            if (brandom(100) >= val) {
                F_IRCrew(F_INJ, MA[Mev[STEP].pad][k].A);
                Mev[STEP].StepInfo = 2100 + Mev[STEP].loc;
                FNote = 9;
            }
        }; // for

        ctr = 0;

        for (k = 0; k < MANNED[Mev[STEP].pad]; k++) {
            if (Data->P[plr].Pool[temp].Status == AST_ST_RETIRED) {
                if (brandom(100) > xtra) {
                    F_KillCrew(F_ONE, MA[Mev[STEP].pad][k].A);
                    Mev[STEP].StepInfo = 3100 + Mev[STEP].loc;
                    FNote = 8;
                    ctr++;
                }
            }
        }

        if (ctr == MANNED[Mev[STEP].pad]) {
            Mev[STEP].StepInfo = 4100 + Mev[STEP].loc;
            Mev[STEP].trace = 0x7F;
        } else if (Mev[STEP].fgoto == -1) {
            Mev[STEP].trace = 0x7F;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        if (Mev[STEP].FName[3] == 0x30) {
            Mev[STEP].trace = 0x7f;
        }

        break;



    case 17: // VAL% survial and XTRA% if injury and retirement
        Mev[STEP].StepInfo = 1300 + Mev[STEP].loc;

        for (k = 0; k < MANNED[Mev[STEP].pad]; k++) {
            if (brandom(100) >= xtra) {
                F_IRCrew(F_RET, MA[Mev[STEP].pad][k].A);
                Mev[STEP].StepInfo = 2300 + Mev[STEP].loc;
                FNote = 9;
            }
        };

        ctr = 0;

        for (k = 0; k < MANNED[Mev[STEP].pad]; k++) {
            if (brandom(100) >= val) {
                F_KillCrew(F_ONE, MA[Mev[STEP].pad][k].A);
                Mev[STEP].StepInfo = 3300 + Mev[STEP].loc;
                FNote = 8;
                ctr++;
            }
        }; // for

        if (ctr == MANNED[Mev[STEP].pad]) {
            Mev[STEP].StepInfo = 4100 + Mev[STEP].loc;
            Mev[STEP].trace = 0x7F;
        } else if (Mev[STEP].fgoto == -1) {
            Mev[STEP].trace = 0x7F;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break;

    case 18:    // set MFlag from VAL, branch if already set
        if ((MFlag & val) > 0) {
            FNote = 1;
            Mev[STEP].StepInfo = 1800 + Mev[STEP].loc;

            if (Mev[STEP].fgoto == -1) {
                Mev[STEP].trace = 0x7F;
                FNote = 0;
            } else if (Mev[STEP].fgoto != -2) {
                Mev[STEP].trace = Mev[STEP].fgoto;
            } else {
                Mev[STEP].trace = STEP + 1;
            }
        } else {
            FNote = 0;
            Mev[STEP].StepInfo = 18;
            MFlag = MFlag | val;

            if (Mev[STEP].fgoto == -1) {
                Mev[STEP].trace = 0x7F;
            } else {
                Mev[STEP].trace = STEP + 1;
            }
        };

        break;

    case 19:   // Set mission flag and recheck step
        if ((MFlag & val) > 0) {
            Mev[STEP].StepInfo = 1200 + Mev[STEP].loc;
            FNote = 2;
        } else {
            FNote = 2;
            Mev[STEP].StepInfo = 19;
            MFlag = MFlag | val;
        };

        Mev[STEP].trace = STEP;          // recheck step

//         Mev[STEP].rnum=random(10000)+1;  // new failure roll
//         Mev[STEP].dice=random(100)+1;    // new die roll
        break;


    case 22: // one man % survival :: EVA
        Mev[STEP].StepInfo = 19;

        if (brandom(100) > val) {
            FNote = 8;
            crw = (EVA[Mev[STEP].pad] != -1) ? MA[Mev[STEP].pad][EVA[Mev[STEP].pad]].A : MA[other(Mev[STEP].pad)][EVA[other(Mev[STEP].pad)]].A;
            F_KillCrew(F_ONE, crw);

            if (Mev[STEP].Name[6] == 0x36) {
                death = 1;    // one man lem
            }

            Mev[STEP].StepInfo = 3200 + Mev[STEP].loc;
            Mev[STEP].trace = STEP + 1;
        };

        break;

    case 23: // VAL% retirement, hardware cut %XTRA perm
        FNote = 0;
        Mev[STEP].StepInfo = 23 + Mev[STEP].loc;

        for (k = 0; k < MANNED[Mev[STEP].pad]; k++) {
            if (brandom(100) >= val) {
                FNote = 9;
                F_IRCrew(F_RET, MA[Mev[STEP].pad][k].A);
                Mev[STEP].StepInfo = 2400 + Mev[STEP].loc;
                ctr++;
            }
        };

        //Used to reduce safety

        if (Mev[STEP].fgoto == -1) {
            Mev[STEP].trace = 0x7F;
        } else if (Mev[STEP].fgoto != -2) {
            Mev[STEP].trace = Mev[STEP].fgoto;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break;

    case 24:   // Reduce Safety by VAL% perm :: hardware recovered
        FNote = 5;
        Mev[STEP].E->Safety -= brandom(10);

        if (Mev[STEP].E->Safety <= 0) {
            Mev[STEP].E->Safety = 1;
        }

        Mev[STEP].StepInfo = 800 + Mev[STEP].loc;
        Mev[STEP].trace = 0x7F;

        break;

    case 25:    // Mission Failure recover Minishuttle
        FNote = 5;
        Mev[STEP].StepInfo = 700;
        Mev[STEP].trace = 0x7F; // End of Mission
        break;

    case 26: // Subtract VAL% from Equip perm and branch to alternate
        FNote = 1;
        Mev[STEP].StepInfo = 1926;
        Mev[STEP].E->Safety -= brandom(10);

        if (Mev[STEP].E->Safety <= 0) {
            Mev[STEP].E->Safety = 1;
        }

        if (Mev[STEP].fgoto == -1) {
            Mev[STEP].trace = 0x7F;
            FNote = 7;
        } else if (Mev[STEP].fgoto != -2) {
            Mev[STEP].trace = Mev[STEP].fgoto;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break;


    case 30:  // Duration Failure
        Data->P[plr].Mission[MPad + Mev[STEP].pad].Duration = 1; //Original code would also return 1
        durx = -1; // end durations
        FNote = 7;
        Mev[STEP].StepInfo = 1950;
        Mev[STEP].trace = STEP + 1;

        break;

    case 31:  // kill EVA and LM people and branch VAL steps
        //Dock_Skip=1;
        Mev[STEP].trace = Mev[STEP].dgoto;
        Mev[STEP].StepInfo = 3100 + STEP;

        if (strncmp(Mev[STEP].E->ID, "C4", 2) == 0) {
            F_KillCrew(F_ALL, 0);
            Mev[STEP].StepInfo = 4100 + STEP;
        } else {
            if (JOINT == 0) {
                F_KillCrew(F_ONE, MA[0][EVA[0]].A);

                if (LM[0] != EVA[0]) {
                    F_KillCrew(F_ONE, MA[0][LM[0]].A);
                }
            } else {
                F_KillCrew(F_ONE, MA[1][EVA[1]].A);

                if (LM[1] != EVA[1]) {
                    F_KillCrew(F_ONE, MA[1][LM[1]].A);
                }
            }
        }

        death = 1;
        break;

    case 33:  // Kill Crew on All Capsules (happens only on dockings)
        FNote = 8;

        if (MANNED[Mev[STEP].pad] > 0) {
            F_KillCrew(F_ALL, 0);
        }

        if (MANNED[other(Mev[STEP].pad)] > 0)  {
            Mev[STEP].pad = other(Mev[STEP].pad); // switch pad for a sec
            F_KillCrew(F_ALL, 0);
            Mev[STEP].pad = other(Mev[STEP].pad); // restore current pad
        }

        Mev[STEP].StepInfo = 4600 + Mev[STEP].loc;
        Mev[STEP].trace = 0x7F;
        break;

    case 1:
    case 8:
    case 10:
    case 11:
    case 14:
    case 21:
    case 27:
    case 28:
    case 29:
    default:
        FNote = 0;
        Mev[STEP].StepInfo = 50;

        if (Mev[STEP].fgoto == -1) {
            Mev[STEP].trace = 0x7F;
        } else {
            Mev[STEP].trace = STEP + 1;
        }

        break; // nothing : continue steps
    }

    if ((Mev[STEP].Name[0] == 'A') && MH[Mev[STEP].pad][7] != NULL) {
        // boosters involved
        if (MH[Mev[STEP].pad][4]->Safety == MH[Mev[STEP].pad][4]->Base) {
            MH[Mev[STEP].pad][7]->Safety = MH[Mev[STEP].pad][7]->Base;
        }
    }

    VerifySF(plr);  // Keep all safety's within the proper ranges

    // check for all astro's that are dead.  End mission if this is the case.
    while (bioskey(1)) {
        bioskey(0);
    }

    key = 0;

    if (!AI[plr]) {
        temp = FailureMode(plr, FNote, text);
    }

    if (temp == 0 && FNote == 3) {
        Mev[STEP].trace = STEP + 1;
    } else if (FNote == 3) {
        Mev[STEP].StepInfo += 1000;
        SCRUBS = 1;
    }

    if (SCRUBS == 1) {
        if (Mev[STEP].loc == 8 && noDock == 1) {
            PROBLEM = 1;
        }

        if (PROBLEM == 0) {
            if (Mev[STEP].fgoto == -1) { // End of Mission Flag
                if (Mev[STEP].PComp > 0) {
                    Mev[STEP].PComp = 4;
                }

                Mev[STEP].trace = 0x7F; // End of Mission Signal
                FNote = 5;
            } else if (Mev[STEP].fgoto != -2) { // Alternate Step is other num
                if (Mev[STEP].PComp > 0) {
                    Mev[STEP].PComp = 4;
                }

                Mev[STEP].trace = Mev[STEP].fgoto;
            } else {
                Mev[STEP].trace = STEP + 1;
            }
        }
    }

    if (strncmp(Mev[STEP].E->ID, "M3", 2) == 0) {
        death = 0;    //what???
    }

    // New death branching code
    if (death == 1) {
        if (Mev[STEP].dgoto == 0) {
            Mev[STEP].trace = 0x7f;
        } else if (Mev[STEP].dgoto > 0) {
            Mev[STEP].trace = Mev[STEP].dgoto;
        }
    }

    if (type == 9 || type == 19) {
        Mev[STEP].trace = STEP;
        Mev[STEP].rnum = brandom(10000) + 1; // new failure roll
        Mev[STEP].dice = brandom(100) + 1; // new die roll
    }

    death = 0;
    return FNote;
}
Esempio n. 2
0
int main(int argc, char **argv)
#endif
{
    char fname[256];
    char defname[] = "game.dat";
    Boolean b_play;
    int dir;
    int inch;
    int num_step;
    int num;
    unsigned char steplog[MaxSteps];

#ifdef ENABLE_DL
    char buf[10];
    struct high_record high;

    while (1) {
        num = 0;
        clear();
        ansimore2("game/worker/welcome", false, 0, 0);
        while (num <= 0 || num > MAXDATA) {
	    buf[0]=0;
            getdata(5, 61, "", buf, 5, 1, NULL, true);
            if (buf[0] == 0)
                return 0;
            num = atoi(buf);
        }
        sprintf(fname, "game/worker/%s.%d", defname, num);
	clear();
#else
    {
        if (argc > 2) {
            sprintf(fname, "%s/%s.%s", argv[1], defname, argv[2]);
            num=atoi(argv[2]);
        } else if (2 == argc) {
            if (strlen(argv[1]) > 255)
                exit(1);
            sprintf(fname, "%s.%s", defname, argv[1]);
            num=atoi(argv[1]);
        } else {
            strcpy(fname, defname);
            num==-1;
        }
#endif
        num_step=0;
        load_highrecord(num, &high, -1);
        if (TRUE == InitData(fname)) {
            if (TRUE == InitPad()) {
                b_play = TRUE;
                DrawPad();
                update_endline1(&high,num_step);
                inch = 0;
                while (b_play) {
                    if (inch) {
                        showdiff();
                        cleardiff();
                        move(scr_lns-1, scr_cols - 1);
                        refresh();
                    }
                    if (wingame()) {
                    	   int newrecord;
			   char buf[100];
                    	   newrecord=0;
                    	   if (num_step<high.shortest||high.shortest==0) 
                    	   	newrecord=load_highrecord(num, &high, num_step);
                    	   clear();
                    	   move(12,15);
                    	   prints("祝贺你,你成功的完成了这一关");
                    	   move(13,15);
                    	   if (newrecord==1) {
                    	       sprintf(buf,"你也创造了本关使用步数的纪录(%d步)!好厉害~",num_step);
			   } else
                    	   if (newrecord!=0) {
                    	       sprintf(buf,"你也创造了本关使用步数的纪录(%d步)!",num_step);
			       prints(buf);
                    	       move(14,15);
			       sprintf(buf,"不过,让点创纪录机会给别人吧~你都有%d个记录了:P\n",newrecord);
                    	   } else {
			       sprintf(buf,"你用了%d步,纪录是%d步。",num_step,high.shortest);
			   }
			   prints(buf);
                        move(23, 0);
                        clrtoeol();
                        prints("\x1b[m                                \x1b[5;1;33m按任何键继续 ..\x1b[m");
                        igetkey();
                        break;
                    }
                    if (num_step>MaxSteps) {
			    char askbuf[100];
                    	    clear();
                    	    sprintf(askbuf,"你已经用了%d步还没有成功,重来么?(Y/N)",num_step);
                    	    getdata(12,0,askbuf,buf,2,1,NULL,true);
                    	    if (toupper(buf[0])=='N')
                    	    	break;
                         b_play = InitPad();
                         DrawPad();
                         num_step=0;
                    	}
                    inch = igetkey();
                    if ((' ' == inch)||(inch == '\n')||(inch=='\r'))
                        break;
                    dir = NullDir;
                    switch (inch) {
                    case 'i':
                    case 'I':
                    case KEY_UP:
                        dir = North;
                        break;
                    case 'j':
                    case 'J':
                    case KEY_LEFT:
                        dir = West;
                        break;
                    case 'l':
                    case 'L':
                    case KEY_RIGHT:
                        dir = East;
                        break;
                    case 'k':
                    case 'K':
                    case KEY_DOWN:
                        dir = South;
                        break;
                    case 12:   //      Ctrl-L
                    case 'R':   //      Ctrl-L
                        clear();
                        DrawPad();
                        break;
                    case '\t':
                        b_play = InitPad();
                        DrawPad();
                        num_step=0;
                        update_endline1(&high,num_step);
                        break;
	            case Ctrl('H'):
                    case '\177':
                    case KEY_DEL:
                    	  if (num_step!=0) {
                    	  	num_step--;
                    	       regretmove(steplog[num_step]);
                            update_endline1(&high,num_step);
                    	  }
                    	  break;
                    default:
                        break;
                    }
                    if (NullDir != dir) {
                    	    int ret;
                         if ((ret=workermove(dir))!=0) {
                         	if (ret==2)
                                 steplog[num_step]=dir+8;
                         	else
                                 steplog[num_step]=dir;
                             num_step++;
                             update_endline1(&high,num_step);
                	    }
                    }
                }
            }
            DestroyPad();
        }
        DestroyData();
    }
    return 0;
}