diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2012-04-07 02:32:20 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2012-04-07 02:32:20 +0800 |
commit | c81a83a47063c14211f3af445eee7fa4f7e995df (patch) | |
tree | 6ff9597dc76a86fc777e941cb8d5c36892209af3 | |
parent | bcceff0859fe49037d5b296111b44aa3f4cf93c8 (diff) | |
download | pttbbs-c81a83a47063c14211f3af445eee7fa4f7e995df.tar pttbbs-c81a83a47063c14211f3af445eee7fa4f7e995df.tar.gz pttbbs-c81a83a47063c14211f3af445eee7fa4f7e995df.tar.bz2 pttbbs-c81a83a47063c14211f3af445eee7fa4f7e995df.tar.lz pttbbs-c81a83a47063c14211f3af445eee7fa4f7e995df.tar.xz pttbbs-c81a83a47063c14211f3af445eee7fa4f7e995df.tar.zst pttbbs-c81a83a47063c14211f3af445eee7fa4f7e995df.zip |
Revise chicken
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5605 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/include/pttstruct.h | 3 | ||||
-rw-r--r-- | pttbbs/mbbsd/chicken.c | 259 |
2 files changed, 137 insertions, 125 deletions
diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 2af6d7e1..4230d910 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -42,7 +42,8 @@ typedef struct chicken_t { /* 128 bytes */ int32_t mm; /* �k�O */ int32_t mm_max; /* ���k�O */ time4_t cbirth; /* ��ڭp��Ϊ��ͤ� */ - int32_t pad[2]; /* �d�ۥH��� */ + int32_t commonsense; /* �`���I�� */ + int32_t pad[1]; /* �d�ۥH��� */ } PACKSTRUCT chicken_t; #define PASSLEN 14 /* Length of encrypted passwd field */ diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index aa0219e7..26074b84 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -3,6 +3,7 @@ #define NUM_KINDS 15 /* ���h�ֺذʪ� */ #define CHICKENLOG "etc/chicken" +#define CHICKEN_PIC "etc/chickens" static const char * const cage[17] = { "�ϥ�", "�g��", "���~", "�֦~", "�C�K", "�C�~", @@ -28,18 +29,6 @@ static const int food_price[NUM_KINDS] = { 12, 12, 5, 6, 5, 20, 15, 23, 23, 10, 19}; -static const char * const attack_type[NUM_KINDS] = { - "��", "�@��", "�l", "�r", - "����", "��", "��", "��", - "�r", "�U�N", "�t��", "�ҥ�", - "�C��", "�N����u", "���k�@�T"}; - -static const char * const damage_degree[] = { - "�A�l����", "���o����", "�p�O��", "���L��", - "���I�k��", "�ϤO��", "�ˤH��", "������", - "�ϥ��O��", "�c������", "�M�I��", "�ƨg��", - "�r�P��", "�g���ɫB����", "��Ѱʦa��", - "�P�R��", NULL}; enum { OO, FOOD, WEIGHT, CLEAN, RUN, ATTACK, BOOK, HAPPY, SATIS, @@ -83,6 +72,18 @@ static const short time_change[NUM_KINDS][14] = static void time_diff(chicken_t * thechicken); static int isdeadth(const chicken_t * thechicken, chicken_t *mychicken); +static int revive_chicken(chicken_t *thechicken, int admin); + +static void +show_chicken_picture(const char *fpath) +{ + show_file(fpath, 5, 14, SHOWFILE_ALLOW_ALL); +} + +#ifdef HAVE_CHICKEN_CS +// External "common sense" module. +#include "chicken_cs.c" +#endif chicken_t * load_live_chicken(const char *uid) { @@ -140,6 +141,9 @@ chicken_query(const char *userid) if (!isdeadth(&xchicken, NULL)) { show_chicken_data(&xchicken); +#ifdef HAVE_CHICKEN_CS + prints("�`���I��: %d", xchicken.commonsense); +#endif prints("\n\n�H�W�O %s ���d�����..", userid); } else { move(1, 0); @@ -217,6 +221,7 @@ new_chicken(void) mychicken.hp_max = time_change[(int)mychicken.type][WEIGHT]; mychicken.mm = 0; mychicken.mm_max = 0; + mychicken.commonsense = 0; reload_money(); if (cuser.money < price) @@ -240,7 +245,8 @@ new_chicken(void) // log data log_filef(CHICKENLOG, LOG_CREAT, - ANSI_COLOR(31) "%s " ANSI_RESET "�i�F�@���s" ANSI_COLOR(33) " %s " ANSI_RESET "�� " + ANSI_COLOR(31) "%s " ANSI_RESET + "�i�F�@���s" ANSI_COLOR(33) " %s " ANSI_RESET "�� " ANSI_COLOR(32) "%s" ANSI_RESET " �� %s\n", cuser.userid, mychicken.name, chicken_type[(int)mychicken.type], Cdate(&now)); return 1; @@ -252,39 +258,45 @@ show_chicken_stat(const chicken_t * thechicken, int age) struct tm ptime; localtime4_r(&thechicken->birthday, &ptime); - prints(" Name :" ANSI_COLOR(33) "%s" ANSI_RESET " (" ANSI_COLOR(32) "%s" ANSI_RESET ")%*s�ͤ� " - ":" ANSI_COLOR(31) "%02d" ANSI_RESET "�~" ANSI_COLOR(31) "%2d" ANSI_RESET "��" ANSI_COLOR(31) "%2d" ANSI_RESET "�� " - "(" ANSI_COLOR(32) "%s %d��" ANSI_RESET ")\n" - " ��:" ANSI_COLOR(33) "%5d/%-5d" ANSI_RESET " �k:" ANSI_COLOR(33) "%5d/%-5d" ANSI_RESET " �����O:" - ANSI_COLOR(33) "%-7d" ANSI_RESET " �ӱ� :" ANSI_COLOR(33) "%-7d" ANSI_RESET " ���� :" ANSI_COLOR(33) "%-7d" - ANSI_RESET " \n" - " �ּ� :" ANSI_COLOR(33) "%-7d " ANSI_RESET " ���N :" ANSI_COLOR(33) "%-7d " ANSI_RESET " �h�� :" - ANSI_COLOR(33) "%-7d" ANSI_RESET " ��� :" ANSI_COLOR(33) "%-7d " ANSI_RESET "�魫 :" - ANSI_COLOR(33) "%-5.2f" ANSI_RESET " \n" - " �f�� :" ANSI_COLOR(33) "%-7d " ANSI_RESET " ���b :" ANSI_COLOR(33) "%-7d " ANSI_RESET " ���� :" - ANSI_COLOR(33) "%-7d" ANSI_RESET " �j�ɤY:" ANSI_COLOR(33) "%-7d" ANSI_RESET " �ī~ :" ANSI_COLOR(33) "%-7d" - ANSI_RESET " \n", + prints(" Name :" ANSI_COLOR(33) "%s" ANSI_RESET + " (" ANSI_COLOR(32) "%s" ANSI_RESET ")%*s" + "�ͤ� :" ANSI_COLOR(31) "%02d" ANSI_RESET "�~" + ANSI_COLOR(31) "%2d" ANSI_RESET "��" + ANSI_COLOR(31) "%2d" ANSI_RESET "�� " + "(" ANSI_COLOR(32) "%s %d��" ANSI_RESET ")\n", thechicken->name, chicken_type[(int)thechicken->type], - strlen(thechicken->name) >= 15 ? 0 : (int)(15 - strlen(thechicken->name)), "", - ptime.tm_year % 100, ptime.tm_mon + 1, ptime.tm_mday, - cage[age > 16 ? 16 : age], age, thechicken->hp, thechicken->hp_max, + strlen(thechicken->name) >= 15 ? 0 : + (int)(15 - strlen(thechicken->name)), + "", ptime.tm_year % 100, ptime.tm_mon + 1, ptime.tm_mday, + cage[age > 16 ? 16 : age], age); + + prints(" ��:" ANSI_COLOR(33) "%5d/%-5d" ANSI_RESET + " �k:" ANSI_COLOR(33) "%5d/%-5d" ANSI_RESET + " �����O:" ANSI_COLOR(33) "%-7d" ANSI_RESET + " �ӱ� :" ANSI_COLOR(33) "%-7d" ANSI_RESET + " ���� :" ANSI_COLOR(33) "%-7d" ANSI_RESET " \n", + thechicken->hp, thechicken->hp_max, thechicken->mm, thechicken->mm_max, - thechicken->attack, thechicken->run, thechicken->book, + thechicken->attack, thechicken->run, thechicken->book); + + prints(" �ּ� :" ANSI_COLOR(33) "%-7d " ANSI_RESET + " ���N :" ANSI_COLOR(33) "%-7d " ANSI_RESET + " �h�� :" ANSI_COLOR(33) "%-7d" ANSI_RESET + " ��� :" ANSI_COLOR(33) "%-7d " ANSI_RESET + "�魫 :" ANSI_COLOR(33) "%-5.2f" ANSI_RESET " \n", thechicken->happy, thechicken->satis, thechicken->tiredstrong, thechicken->temperament, - ((float)(thechicken->hp_max + (thechicken->weight / 50))) / 100, + ((float)(thechicken->hp_max + (thechicken->weight / 50))) / 100); + + prints(" �f�� :" ANSI_COLOR(33) "%-7d " ANSI_RESET + " ���b :" ANSI_COLOR(33) "%-7d " ANSI_RESET + " ���� :" ANSI_COLOR(33) "%-7d" ANSI_RESET + " �j�ɤY:" ANSI_COLOR(33) "%-7d" ANSI_RESET + " �ī~ :" ANSI_COLOR(33) "%-7d" ANSI_RESET " \n", thechicken->sick, thechicken->clean, thechicken->food, thechicken->oo, thechicken->medicine); } -#define CHICKEN_PIC "etc/chickens" - -static void -show_chicken_picture(const char *fpath) -{ - show_file(fpath, 5, 14, SHOWFILE_ALLOW_ALL); -} - void show_chicken_data(chicken_t * thechicken) { @@ -389,8 +401,10 @@ ch_guess(chicken_t *mychicken) mychicken->attack += time_change[(int)mychicken->type][ATTACK] / 4; move(20, 0); clrtobot(); - outs("�A�n�X[" ANSI_COLOR(32) "1" ANSI_RESET "]" ANSI_COLOR(33) "�ŤM" ANSI_RESET "(" ANSI_COLOR(32) "2" ANSI_RESET ")" - ANSI_COLOR(33) "���Y" ANSI_RESET "(" ANSI_COLOR(32) "3" ANSI_RESET ")" ANSI_COLOR(33) "��" ANSI_RESET ":\n"); + outs("�A�n�X[" ANSI_COLOR(32) "1" ANSI_RESET "]" ANSI_COLOR(33) "�ŤM" + ANSI_RESET "(" ANSI_COLOR(32) "2" ANSI_RESET ")" + ANSI_COLOR(33) "���Y" ANSI_RESET "(" ANSI_COLOR(32) "3" ANSI_RESET ")" + ANSI_COLOR(33) "��" ANSI_RESET ":\n"); me = vkey(); me -= '1'; if (me > 2 || me < 0) @@ -444,13 +458,17 @@ ch_hit(chicken_t *mychicken) pressanykey(); } -//static void -ch_buyitem(int money, const char *picture, int *item) +ch_buyitem(int money, const char *picture, int *item, chicken_t *mychicken) { int num = 0; char buf[5]; +#ifdef HAVE_CHICKEN_CS + if (ch_buyitem_cs(money, item, mychicken)) + return; +#endif + getdata_str(b_lines - 1, 0, "�n�R�h�֥��O:", buf, sizeof(buf), NUMECHO, "1"); num = atoi(buf); @@ -508,7 +526,8 @@ ch_kill(chicken_t *mychicken) pay(100, "��i�d���O"); more(CHICKEN_PIC "/deadth", YEA); log_filef(CHICKENLOG, LOG_CREAT, - ANSI_COLOR(31) "%s " ANSI_RESET "�� " ANSI_COLOR(33) "%s" ANSI_RESET ANSI_COLOR(32) " %s " + ANSI_COLOR(31) "%s " ANSI_RESET "�� " + ANSI_COLOR(33) "%s" ANSI_RESET ANSI_COLOR(32) " %s " ANSI_RESET "�_�F �� %s\n", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], Cdate(&now)); mychicken->name[0] = 0; @@ -666,7 +685,9 @@ revive_chicken(chicken_t *thechicken, int admin) } thechicken->lastvisit = now; // really need so? - +#ifdef HAVE_CHICKEN_CS + revive_chicken_cs(thechicken); +#endif return 0; } @@ -691,7 +712,8 @@ deadtype(const chicken_t * thechicken, chicken_t *mychicken) if (thechicken == mychicken) { log_filef(CHICKENLOG, LOG_CREAT, - ANSI_COLOR(31) "%s" ANSI_RESET " �үk�R��" ANSI_COLOR(33) " %s" ANSI_COLOR(32) " %s " + ANSI_COLOR(31) "%s" ANSI_RESET " �үk�R��" + ANSI_COLOR(33) " %s" ANSI_COLOR(32) " %s " ANSI_RESET "���F �� %s\n", cuser.userid, thechicken->name, chicken_type[(int)thechicken->type], Cdate(&now)); mychicken->name[0] = 0; @@ -746,7 +768,8 @@ ch_changename(chicken_t *mychicken) if (strlen(newname) >= 3 && strcmp(newname, mychicken->name)) { strlcpy(mychicken->name, newname, sizeof(mychicken->name)); log_filef(CHICKENLOG, LOG_CREAT, - ANSI_COLOR(31) "%s" ANSI_RESET " ��k�R��" ANSI_COLOR(33) " %s" ANSI_COLOR(32) " %s " + ANSI_COLOR(31) "%s" ANSI_RESET " ��k�R��" ANSI_COLOR(33) + " %s" ANSI_COLOR(32) " %s " ANSI_RESET "��W��" ANSI_COLOR(33) " %s" ANSI_RESET " �� %s\n", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], newname, Cdate(&now)); @@ -760,22 +783,34 @@ select_menu(int age GCC_UNUSED, chicken_t *mychicken) reload_money(); move(19, 0); - prints(ANSI_COLOR(44;37) " �� :" ANSI_COLOR(33) " %-10d " - " " ANSI_RESET "\n" - ANSI_COLOR(33) "(" ANSI_COLOR(37) "1" ANSI_COLOR(33) ")�M�z (" ANSI_COLOR(37) "2" ANSI_COLOR(33) ")�Y�� " - "(" ANSI_COLOR(37) "3" ANSI_COLOR(33) ")�q�� (" ANSI_COLOR(37) "4" ANSI_COLOR(33) ")��� " - "(" ANSI_COLOR(37) "5" ANSI_COLOR(33) ")�˥L (" ANSI_COLOR(37) "6" ANSI_COLOR(33) ")���L " - "(" ANSI_COLOR(37) "7" ANSI_COLOR(33) ")�R%s$%d (" ANSI_COLOR(37) "8" ANSI_COLOR(33) ")�Y�ɤY\n" - "(" ANSI_COLOR(37) "9" ANSI_COLOR(33) ")�Y�f�� (" ANSI_COLOR(37) "o" ANSI_COLOR(33) ")�R�j�ɤY$100 " - "(" ANSI_COLOR(37) "m" ANSI_COLOR(33) ")�R��$10 (" ANSI_COLOR(37) "k" ANSI_COLOR(33) ")��i " + + vbarf(ANSI_COLOR(44;37) " �� :" ANSI_COLOR(33) " %-10d" +#ifdef HAVE_CHICKEN_CS + ANSI_COLOR(37) " �`���I�� :" ANSI_COLOR(33) " %-10d" +#endif + , cuser.money +#ifdef HAVE_CHICKEN_CS + , mychicken->commonsense +#endif + ); + + prints("\n" ANSI_COLOR(33) "(" ANSI_COLOR(37) "1" ANSI_COLOR(33) ")�M�z " + "(" ANSI_COLOR(37) "2" ANSI_COLOR(33) ")�Y�� " + "(" ANSI_COLOR(37) "3" ANSI_COLOR(33) ")�q�� " + "(" ANSI_COLOR(37) "4" ANSI_COLOR(33) ")��� " + "(" ANSI_COLOR(37) "5" ANSI_COLOR(33) ")�˥L " + "(" ANSI_COLOR(37) "6" ANSI_COLOR(33) ")���L " + "(" ANSI_COLOR(37) "7" ANSI_COLOR(33) ")�R%s$%d " + "(" ANSI_COLOR(37) "8" ANSI_COLOR(33) ")�Y�ɤY\n" + "(" ANSI_COLOR(37) "9" ANSI_COLOR(33) ")�Y�f�� " + "(" ANSI_COLOR(37) "o" ANSI_COLOR(33) ")�R�j�ɤY$100 " + "(" ANSI_COLOR(37) "m" ANSI_COLOR(33) ")�R��$10 " + "(" ANSI_COLOR(37) "k" ANSI_COLOR(33) ")��i " "(" ANSI_COLOR(37) "n" ANSI_COLOR(33) ")��W " +#ifdef HAVE_CHICKEN_CS + "(" ANSI_COLOR(37) "s" ANSI_COLOR(33) ")�`�Ѱݵ� " +#endif "(" ANSI_COLOR(37) "q" ANSI_COLOR(33) ")���}:" ANSI_RESET, - cuser.money, - /* - * chicken_food[(int)mychicken->type], - * chicken_type[(int)mychicken->type], - * chicken_type[(int)mychicken->type], - */ chicken_food[(int)mychicken->type], food_price[(int)mychicken->type]); do { @@ -805,7 +840,7 @@ select_menu(int age GCC_UNUSED, chicken_t *mychicken) break; case '7': ch_buyitem(food_price[(int)mychicken->type], CHICKEN_PIC "/food", - &mychicken->food); + &mychicken->food, mychicken); break; case '8': ch_eatoo(mychicken); @@ -815,11 +850,12 @@ select_menu(int age GCC_UNUSED, chicken_t *mychicken) break; case 'O': case 'o': - ch_buyitem(100, CHICKEN_PIC "/buyoo", &mychicken->oo); + ch_buyitem(100, CHICKEN_PIC "/buyoo", &mychicken->oo, mychicken); break; case 'M': case 'm': - ch_buyitem(10, CHICKEN_PIC "/buymedicine", &mychicken->medicine); + ch_buyitem(10, CHICKEN_PIC "/buymedicine", &mychicken->medicine, + mychicken); break; case 'N': case 'n': @@ -832,6 +868,12 @@ select_menu(int age GCC_UNUSED, chicken_t *mychicken) case 'Q': case 'q': return 0; +#ifdef HAVE_CHICKEN_CS + case 'S': + case 's': + ch_teach(mychicken); + break; +#endif } } while (ch < ' ' || ch > 'z'); return 1; @@ -844,77 +886,46 @@ recover_chicken(chicken_t * thechicken) int price = egg_price[(int)thechicken->type]; int money = price; - /* - // make more cost according to chicken status. - price += thechicken->hp_max; - price += thechicken->tiredstrong; - price += thechicken->sick; - // price += thechicken->weight; - - if (price - money > 0) - { - price -= thechicken->satis; // ���N�� - if (price < money) - price = money; - } - */ - // money is a little less than price. +#ifdef HAVE_CHICKEN_CS + if (recover_chicken_cs(thechicken)) + return 1; +#endif + money = price + (random() % price); price *= 2; if (now - thechicken->lastvisit > (60 * 60 * 24 * 7)) return 0; - move(21, 0); clrtobot(); - outmsg(ANSI_COLOR(33;44) "���F�ɦu��" ANSI_COLOR(37;45) - " �O�`�� �ڬO�����A�� " ANSI_RESET); - bell(); - vkey(); - outmsg(ANSI_COLOR(33;44) "���F�ɦu��" ANSI_COLOR(37;45) - " �A�L�k���ڤ��y �]���ڬO�t�F, �̪�ʿ��Q�ȥ~�� " ANSI_RESET); - bell(); - vkey(); - snprintf(buf, sizeof(buf), ANSI_COLOR(33;44) "���F�ɦu��" ANSI_COLOR(37;45) - " �A���@�ӭ訫���[��%s�n�۴��^�Ӷ�? �u�n %d ���� " ANSI_RESET, - chicken_type[(int)thechicken->type], price); - outmsg(buf); - - // prevent user accident hit + + // ���F�ɦu�÷d�������y��b�O�ܸ��ݪ��D�N + vs_hdr2(" �i���� ", " �_���d��"); + prints("\n�A���@�ӭ覺�`���[�� %s �n�۳�^�Ӷ�? �u�n %d ����...\n", + chicken_type[(int)thechicken->type], price); do { - bell(); - getdata(21, 0, " �n����_���d���ܡH (n:�|�H��/y:��������): ", - buf, 3, LCECHO); - move(22, 0); clrtoeol(); outs(" �п�J y �� n �C\n"); + getdata(10, 0, " �n����_���d���ܡH [y/n]: ", + buf, 2, LCECHO); } while (buf[0] != 'y' && buf[0] != 'n'); - move(22, 0); clrtoeol(); - - if (buf[0] == 'y') { - reload_money(); - if (cuser.money < price) { - outmsg(ANSI_COLOR(33;44) "���F�ɦu��" ANSI_COLOR(37;45) - " ���� ���S�a�� �S�����p�� �֥h�w���a " ANSI_RESET); - bell(); - vkey(); - return 0; - } - revive_chicken(thechicken, 0); - pay(money, "�F�ɦu��"); - snprintf(buf, sizeof(buf), - ANSI_COLOR(33;44) "���F�ɦu��" ANSI_COLOR(37;45) - " OK�F �O�o���L�I�F�� ���M�i�ॢ�ġC" - "���Ѥ߱��n�A���A$%d�N�n " ANSI_RESET, money); - outmsg(buf); - bell(); - vkey(); - return 1; + + if (buf[0] == 'n') { + thechicken->lastvisit = 0; + return 0; } - outmsg(ANSI_COLOR(33;44) "���F�ɦu��" ANSI_COLOR(37;45) - " ���M���ڧ|�H! �o�~�Y�R�u���ȿ�... " ANSI_RESET); - thechicken->lastvisit = 0; - bell(); - vkey(); - return 0; + + reload_money(); + if (cuser.money < price) { + vmsg("��������A���w����A��"); + return 0; + } + + pay(money, "�F�ɦu��"); + revive_chicken(thechicken, 0); + move(12, 0); + prints("�d���w�_���C �аO�o�[�H�����קK�A�צ��`�C\n" + "�P�±z���d�����R�ߡA�_���O����A�Ȧ� $%d�C\n", money); + pressanykey(); + return 1; } void |