00258 {
00259 Database& db =
GetWeb().
GetDatabase();
00260 Query q(db);
00261 db::Account acct(db,
GetWeb().GetAccount());
00262 db::Player pl(db,
GetWeb().GetPlayer());
00263 db::Location loc(db, pl.location);
00264
char sql[1000];
00265
00266 sprintf(sql,
"select count(*) from npc where player=%ld and location=%ld", pl.num, pl.location);
00267
long qnpcs = q.get_count(sql);
00268
long qbeds = 0;
00269
00270 sprintf(sql,
"select * from playerbuilding where player=%ld and location=%ld", pl.num, pl.location);
00271 q.get_result(sql);
00272
while (q.fetch_row())
00273 {
00274 db::Playerbuilding x(&db, &q);
00275 db::Building b(db, x.building);
00276 qbeds += b.beds;
00277 }
00278 q.free_result();
00279
00280
00281
Header(db, q, acct, pl, loc, sql);
00282
00283
if (!
GetWeb().
GetSuperuservy() || !acct.superuser)
00284 {
00285 printf(
"<table cellpadding=0 cellspacing=0><tr>");
00286 printf(
"<td valign='top'>");
00287
00288 printf(
"<div class=box style='background: #e0ffe0'>");
00289 printf(
"<u>NPC's available for hire</u><br>");
00290
if (qnpcs < qbeds)
00291 {
00292 q.get_result(
"select * from npc where player=0 order by name");
00293
while (q.fetch_row())
00294 {
00295 db::Npc npc(&db, &q);
00296 sprintf(sql,
"select * from npcskill where npc=%ld", npc.num);
00297 db::Npcskill npcsk(&db, sql);
00298 db::Skill sk(db, npcsk.skill);
00299 printf(
"<b>%s</b>, age <b>%ld</b> days, <b>%s</b> [ <a class=button href='%s?%s=hire&hire=%ld'>Hire</a> ]<br>",
00300 npc.name.c_str(), npc.age_days, sk.name.c_str(),
00301
GetWeb().GetCgiName().c_str(), GetFormName().c_str(), npc.num);
00302 }
00303 q.free_result();
00304 }
00305
else
00306 {
00307 printf(
"<p>No space available - build more buildings.</p>");
00308 }
00309 printf(
"</div>");
00310 printf(
"</td>");
00311
00312 sprintf(sql,
"select * from npc where player=%ld", pl.num);
00313 q.get_result(sql);
00314
if (q.num_rows())
00315 {
00316 printf(
"<td valign='top'>");
00317 printf(
"<div class=box style='background: #ffffe0'>");
00318
00319 printf(
"<u>Your hired npc's</u><br>");
00320
while (q.fetch_row())
00321 {
00322 db::Npc npc(&db, &q);
00323 sprintf(sql,
"select * from npcskill where npc=%ld", npc.num);
00324 db::Npcskill npcsk(&db, sql);
00325 db::Skill sk(db, npcsk.skill);
00326 printf(
"<b>%s</b>, age <b>%ld</b> days, <b>%s</b> [ <a class=button href='%s?%s=fire&fire=%ld'>Fire</a> ]<br>",
00327 npc.name.c_str(), npc.age_days, sk.name.c_str(),
00328
GetWeb().GetCgiName().c_str(), GetFormName().c_str(), npc.num);
00329 }
00330 printf(
"</div>");
00331 printf(
"</td>");
00332 }
00333 q.free_result();
00334
00335
00336 printf(
"<td valign='top'>");
00337 printf(
"<div class=box style='background: #ffffe0'>");
00338
00339 printf(
"<u>Your resources</u><br>");
00340 sprintf(sql,
"select * from playerresource where player=%ld", pl.num);
00341 q.get_result(sql);
00342
while (q.fetch_row())
00343 {
00344 db::Playerresource x(&db, &q);
00345 db::Resource r(db, x.resource);
00346 printf(
"<b>%s</b>, amount <b>%ld</b><br>", r.name.c_str(), x.amount);
00347 }
00348 q.free_result();
00349
00350 printf(
"</div>");
00351 printf(
"</td>");
00352
00353 printf(
"<td valign='top'>");
00354 printf(
"<div class=box style='background: #ffffe0'>");
00355 printf(
"<u>Current location</u><br>");
00356 printf(
"<b>%s</b><br>", loc.name.c_str());
00357 sprintf(sql,
"select * from locationlink where location1=%ld", loc.num);
00358 q.get_result(sql);
00359
while (q.fetch_row())
00360 {
00361 db::Locationlink x(&db, &q);
00362 db::Location l(db, x.location2);
00363 printf(
"<a class=button href='%s?%s=travel&travel=%ld'>Travel to %s</a><br>",
00364
GetWeb().GetCgiName().c_str(), GetFormName().c_str(), x.location2, l.name.c_str());
00365 }
00366 q.free_result();
00367 printf(
"</div>");
00368
00369 printf(
"<div class=box style='background: #ffffe0'>");
00370
00371 printf(
"<u>Your buildings in <b>%s</b></u><br>", loc.name.c_str());
00372 sprintf(sql,
"select * from playerbuilding where player=%ld and location=%ld", pl.num, pl.location);
00373 q.get_result(sql);
00374
while (q.fetch_row())
00375 {
00376 db::Playerbuilding x(&db, &q);
00377 db::Building b(db, x.building);
00378 printf(
"<b>%s</b>, <b>%ld</b> beds<br>",
00379 b.name.c_str(), b.beds);
00380 }
00381 q.free_result();
00382 printf(
"<a class=button href='%s?BuildForm=try_build'>Build</a>",
GetWeb().GetCgiName().c_str());
00383
00384 printf(
"</div>");
00385 printf(
"</td>");
00386 printf(
"</tr></table>");
00387 }
00388
00389
00390
if (
GetWeb().
GetSuperuservy() && acct.superuser)
00391 {
00392
00393 printf(
"<table cellpadding=0 cellspacing=0><tr><td valign='top'>");
00394 printf(
"<div class=box style='background: #ffe0e0'>");
00395 printf(
"<form method='POST' action='%s'>",
GetWeb().GetCgiName().c_str());
00396 printf(
"<input type=hidden name='%s' value='skill_create'>", GetFormName().c_str());
00397 q.get_result(
"select * from skill order by name");
00398 printf(
"Edit Skill: <select name=skill><option>");
00399
while (q.fetch_row())
00400 {
00401 db::Skill sk(&db, &q);
00402 printf(
"<option value=%ld%s>%s", sk.num,
00403 (sk.num == GetWeb().GetSkill()) ?
" selected" :
"",
00404 sk.name.c_str());
00405 }
00406 q.free_result();
00407 printf(
"</select><input type=submit name=submit value=' Select '><br>");
00408
if (
GetWeb().
GetSkill())
00409 {
00410 db::Skill sk(db,
GetWeb().GetSkill());
00411 printf(
"<div class=box style='background: #ffc0c0'>");
00412 printf(
"Selected skill: <b>%s</b><br>", sk.name.c_str());
00413 printf(
"<div class=box style='background: #ffe0e0'>");
00414 printf(
"Resource: <select name=resource><option>");
00415 q.get_result(
"select * from resource order by name");
00416
while (q.fetch_row())
00417 {
00418 db::Resource r(&db, &q);
00419 printf(
"<option value=%ld>%s", r.num, r.name.c_str());
00420 }
00421 q.free_result();
00422 printf(
"</select><br>");
00423 printf(
"Type: <input type=radio name=prod value='Producer'>Producer\n");
00424 printf(
"<input type=radio name=prod value='Consumer'>Consumer<br>");
00425 printf(
"BaseAmount: <input type=text name=amount size=8> units/day");
00426 printf(
"<br>");
00427 printf(
"<input type=submit name=submit value=' Add selected resource '><br>");
00428 printf(
"</div>");
00429 sprintf(sql,
"select * from linkskillresource where skill=%ld", sk.num);
00430 q.get_result(sql);
00431
while (q.fetch_row())
00432 {
00433 db::Linkskillresource l(&db, &q);
00434 db::Resource r(db, l.resource);
00435 printf(
"Linked resource: <b>%s</b> %s, %ld units/day [ <a href='%s?%s=unlink&unlink=%ld'>unlink resource</a> ]<br>",
00436 r.name.c_str(), l.type.c_str(), l.base_amount,
00437
GetWeb().GetCgiName().c_str(), GetFormName().c_str(), r.num);
00438 }
00439 q.free_result();
00440 printf(
"</div>");
00441 }
00442 printf(
"Skill name to create<br>");
00443 printf(
"<input type=text name=skill_name><br>");
00444 printf(
"Resource name to create<br>");
00445 printf(
"<input type=text name=resource_name><br>");
00446 printf(
"<input type=submit name=submit value=' Edit / Create Skill '>");
00447
00448 printf(
"</form>");
00449 printf(
"</div>");
00450 printf(
"</td><td valign='top'>");
00451 printf(
"<div class=box style='background: #ffe0e0'>");
00452 printf(
"<form method='POST' action='%s'>",
GetWeb().GetCgiName().c_str());
00453 printf(
"<input type=hidden name='%s' value='building'>", GetFormName().c_str());
00454 q.get_result(
"select * from building order by name");
00455 printf(
"Edit building: <select name=building><option>");
00456
while (q.fetch_row())
00457 {
00458 db::Building b(&db, &q);
00459 printf(
"<option value=%ld%s>%s", b.num,
00460 (b.num == GetWeb().GetBuilding()) ?
" selected" :
"",
00461 b.name.c_str());
00462 }
00463 q.free_result();
00464 printf(
"</select><input type=submit name=submit value=' Select '><br>");
00465
00466
if (
GetWeb().
GetBuilding())
00467 {
00468 db::Building sk(db,
GetWeb().GetBuilding());
00469 printf(
"<div class=box style='background: #ffc0c0'>");
00470 printf(
"Selected building: <b>%s</b><br>", sk.name.c_str());
00471 printf(
"Beds: <b>%ld</b><br>", sk.beds);
00472 printf(
"<div class=box style='background: #ffe0e0'>");
00473 printf(
"Resource: <select name=resource><option>");
00474 q.get_result(
"select * from resource order by name");
00475
while (q.fetch_row())
00476 {
00477 db::Resource r(&db, &q);
00478 printf(
"<option value=%ld>%s", r.num, r.name.c_str());
00479 }
00480 q.free_result();
00481 printf(
"</select><br>");
00482 printf(
"Amount: <input type=text name=amount size=8> units");
00483 printf(
"<br>");
00484 printf(
"<input type=submit name=submit value=' Add selected resource '><br>");
00485 printf(
"</div>");
00486 sprintf(sql,
"select * from buildingresource where building=%ld", sk.num);
00487 q.get_result(sql);
00488
while (q.fetch_row())
00489 {
00490 db::Buildingresource l(&db, &q);
00491 db::Resource r(db, l.resource);
00492 printf(
"Linked resource: <b>%s</b>, <b>%ld</b> units [ <a href='%s?%s=unlinkbr&unlinkbr=%ld'>unlink resource</a> ]<br>",
00493 r.name.c_str(), l.amount,
00494
GetWeb().GetCgiName().c_str(), GetFormName().c_str(), r.num);
00495 }
00496 q.free_result();
00497 printf(
"</div>");
00498 }
00499 printf(
"Building name to create<br>");
00500 printf(
"<input type=text name=building_name><br>");
00501 printf(
"Number of beds<br>");
00502 printf(
"<input type=text name=beds size=10><br>");
00503 printf(
"<input type=submit name=submit value=' Submit '>");
00504
00505 printf(
"</form>");
00506 printf(
"</div>");
00507
00508 sprintf(sql,
"select count(*) from locationlink where location1=%ld", pl.location);
00509
long qlinks = q.get_count(sql);
00510
if (qlinks < 3)
00511 {
00512 printf(
"</td><td valign='top'>");
00513 printf(
"<div class=box style='background: #ffe0e0'>");
00514 printf(
"<form method='POST' action='%s'>",
GetWeb().GetCgiName().c_str());
00515 printf(
"<input type=hidden name='%s' value='loc_create'>", GetFormName().c_str());
00516
00517 q.get_result(
"select * from location order by name");
00518 printf(
"Edit location: <select name=location><option>");
00519
while (q.fetch_row())
00520 {
00521 db::Location sk(&db, &q);
00522 printf(
"<option value=%ld%s>%s", sk.num,
00523 (sk.num == GetWeb().GetLocation()) ?
" selected" :
"",
00524 sk.name.c_str());
00525 }
00526 q.free_result();
00527 printf(
"</select><input type=submit name=submit value=' Select '><br>");
00528
00529
if (
GetWeb().
GetLocation())
00530 {
00531 db::Location sk(db,
GetWeb().GetLocation());
00532 printf(
"<div class=box style='background: #ffc0c0'>");
00533 printf(
"Selected location: <b>%s</b><br>", sk.name.c_str());
00534 printf(
"Max buildings: <b>%ld</b><br>", sk.max_buildings);
00535 sprintf(sql,
"select * from locationresource where location=%ld", sk.num);
00536 q.get_result(sql);
00537
while (q.fetch_row())
00538 {
00539 db::Locationresource l(&db, &q);
00540 db::Resource r(db, l.resource);
00541 printf(
"Linked resource: <b>%s</b>, <b>%ld</b> units<br>",
00542 r.name.c_str(), l.amount);
00543 }
00544 q.free_result();
00545 printf(
"</div>");
00546 }
00547
00548 printf(
"Create location<br>(Current location: <b>%s</b>)<br>", loc.name.c_str());
00549 printf(
"<input type=text name=location_name><br>");
00550 printf(
"Max buildings<br>");
00551 printf(
"<input type=text name=max size=10><br>");
00552 printf(
"<input type=submit name=submit value=' Create '>");
00553
00554 printf(
"</form>");
00555 printf(
"</div>");
00556 }
00557 printf(
"</td></tr></table>");
00558 }
00559 }